public TwitterApi Api { get; }
public TwitterConfiguration Configuration { get; private set; }
+ public TwitterTextConfiguration TextConfiguration { get; private set; }
delegate void GetIconImageDelegate(PostClass post);
private readonly object LockObj = new object();
{
this.Api = api;
this.Configuration = TwitterConfiguration.DefaultConfiguration();
+ this.TextConfiguration = TwitterTextConfiguration.DefaultConfiguration();
}
public TwitterApiAccessLevel AccessLevel
{
this.CheckAccountState();
- if (mediaIds == null &&
- Twitter.DMSendTextRegex.IsMatch(postStr))
+ if (Twitter.DMSendTextRegex.IsMatch(postStr))
{
await this.SendDirectMessage(postStr)
.ConfigureAwait(false);
}
var minimumId = this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.Timeline, tab, read);
-
- if (minimumId != null && minimumId.Value < tab.OldestId)
+ if (minimumId != null)
tab.OldestId = minimumId.Value;
}
}
var minimumId = this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.Reply, tab, read);
-
- if (minimumId != null && minimumId.Value < tab.OldestId)
+ if (minimumId != null)
tab.OldestId = minimumId.Value;
}
var minimumId = CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.UserTimeline, tab, read);
- if (minimumId != null && minimumId.Value < tab.OldestId)
+ if (minimumId != null)
tab.OldestId = minimumId.Value;
}
post.Source = string.Intern(sourceText);
post.SourceUri = sourceUri;
- post.IsReply = post.ReplyToList.Contains(_uname);
+ post.IsReply = post.RetweetedId == null && post.ReplyToList.Contains(_uname);
post.IsExcludeReply = false;
if (post.IsMe)
var minimumId = CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.List, tab, read);
- if (minimumId != null && minimumId.Value < tab.OldestId)
+ if (minimumId != null)
tab.OldestId = minimumId.Value;
}
var minimumId = this.CreatePostsFromSearchJson(searchResult, tab, read, more);
- if (minimumId != null && minimumId.Value < tab.OldestId)
+ if (minimumId != null)
tab.OldestId = minimumId.Value;
}
var minimumId = this.CreateFavoritePostsFromJson(statuses, read);
- if (minimumId != null && minimumId.Value < tab.OldestId)
+ if (minimumId != null)
tab.OldestId = minimumId.Value;
}
{
var matchDm = Twitter.DMSendTextRegex.Match(postText);
if (matchDm.Success)
- return this.GetTextLengthRemainInternal(matchDm.Groups["body"].Value, isDm: true);
+ return this.GetTextLengthRemainDM(matchDm.Groups["body"].Value);
- return this.GetTextLengthRemainInternal(postText, isDm: false);
+ return this.GetTextLengthRemainWeighted(postText);
}
- private int GetTextLengthRemainInternal(string postText, bool isDm)
+ private int GetTextLengthRemainDM(string postText)
{
var textLength = 0;
textLength += shortUrlLength - url.Length;
}
- if (isDm)
- return this.Configuration.DmTextCharacterLimit - textLength;
- else
- return 140 - textLength;
+ return this.Configuration.DmTextCharacterLimit - textLength;
+ }
+
+ private int GetTextLengthRemainWeighted(string postText)
+ {
+ var config = this.TextConfiguration;
+ var totalWeight = 0;
+
+ var urls = TweetExtractor.ExtractUrlEntities(postText).ToArray();
+
+ var pos = 0;
+ while (pos < postText.Length)
+ {
+ var urlEntity = urls.FirstOrDefault(x => x.Indices[0] == pos);
+ if (urlEntity != null)
+ {
+ totalWeight += config.TransformedURLLength * config.Scale;
+
+ var urlLength = urlEntity.Indices[1] - urlEntity.Indices[0];
+ pos += urlLength;
+
+ continue;
+ }
+
+ var codepoint = char.ConvertToUtf32(postText, pos);
+ var weight = config.DefaultWeight;
+
+ foreach (var weightRange in config.Ranges)
+ {
+ if (codepoint >= weightRange.Start && codepoint <= weightRange.End)
+ {
+ weight = weightRange.Weight;
+ break;
+ }
+ }
+
+ totalWeight += weight;
+
+ var isSurrogatePair = codepoint > 0xffff;
+ if (isSurrogatePair)
+ pos += 2; // サロゲートペアの場合は2文字分進める
+ else
+ pos++;
+ }
+
+ var remainWeight = config.MaxWeightedTweetLength * config.Scale - totalWeight;
+
+ return remainWeight / config.Scale;
}
MyCommon.TraceOut(ex);
return;
}
+ catch (XmlException)
+ {
+ MyCommon.TraceOut("XmlException (StatusArrived): " + line);
+ }
catch(NullReferenceException)
{
MyCommon.TraceOut("NullRef StatusArrived: " + line);