1
- // <copyright file="TweetFormatter .cs" company="Endjin Limited">
1
+ // <copyright file="ShortFormContentFormatter .cs" company="Endjin Limited">
2
2
// Copyright (c) Endjin Limited. All rights reserved.
3
3
// </copyright>
4
4
12
12
13
13
namespace Stacker . Cli . Formatters ;
14
14
15
- public class TweetFormatter : IContentFormatter
15
+ public class ShortFormContentFormatter : IContentFormatter
16
16
{
17
- private const int MaxContentLength = 280 ;
18
- private readonly string campaignSource = "twitter" ;
17
+ private readonly int maxContentLength ;
18
+ private readonly string campaignSource ;
19
+
20
+ public ShortFormContentFormatter ( int maxContentLength , string campaignSource )
21
+ {
22
+ this . campaignSource = campaignSource ;
23
+ this . maxContentLength = maxContentLength ;
24
+ }
19
25
20
26
public IEnumerable < string > Format ( string campaignMedium , string campaignName , IEnumerable < ContentItem > feedItems , StackerSettings settings )
21
27
{
22
- List < string > tweets = new ( ) ;
28
+ List < string > tweets = [ ] ;
23
29
StringBuilder content = new ( ) ;
24
30
StringBuilder campaignTracking = new ( ) ;
25
31
@@ -54,6 +60,13 @@ public IEnumerable<string> Format(string campaignMedium, string campaignName, IE
54
60
}
55
61
}
56
62
63
+ // If we don't find a match from our users, just use the display name
64
+ if ( match is null )
65
+ {
66
+ content . Append ( " by " ) ;
67
+ content . Append ( item . Author . DisplayName ) ;
68
+ }
69
+
57
70
if ( item ? . Tags != null && item . Tags . Any ( ) )
58
71
{
59
72
int tweetLength = content . Length + campaignTracking . Length + 1 ; // 1 = extra space before link
@@ -62,7 +75,7 @@ public IEnumerable<string> Format(string campaignMedium, string campaignName, IE
62
75
foreach ( string tag in item . Tags )
63
76
{
64
77
tweetLength += tag . Length + 2 ; // 2 Offset = Space + #
65
- if ( tweetLength <= MaxContentLength )
78
+ if ( tweetLength <= this . maxContentLength )
66
79
{
67
80
tagsToInclude ++ ;
68
81
}
0 commit comments