Skip to content

Commit

Permalink
Fix GetExtendedTweetElements to support streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
azyobuzin committed Nov 6, 2016
1 parent fce01f3 commit 67b3261
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1.6.1.{build}
version: 1.6.2.{build}

os: Visual Studio 2015

Expand Down
27 changes: 16 additions & 11 deletions src/CoreTweetSupplement/CoreTweetSupplement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static string ToString(IList<DoubleUtf16Char> source, int start, int cou
/// </summary>
/// <param name="text">The text such as <see cref="Status.Text"/>, <see cref="DirectMessage.Text"/> and <see cref="User.Description"/>.</param>
/// <param name="entities">The <see cref="Entities"/> instance.</param>
/// <returns>An <see cref="IEnumerable{ITextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
/// <returns>An <see cref="IEnumerable{TextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities entities)
{
var chars = GetCodePoints(text);
Expand All @@ -150,20 +150,22 @@ public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities ent
/// <param name="entities">The <see cref="Entities"/> instance.</param>
/// <param name="startIndex">The starting character position in code point.</param>
/// <param name="endIndex">The ending character position in code point.</param>
/// <returns>An <see cref="IEnumerable{ITextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
/// <returns>An <see cref="IEnumerable{TextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities entities, int startIndex, int endIndex)
{
return EnumerateTextParts(GetCodePoints(text), entities, startIndex, endIndex);
}
var chars = GetCodePoints(text);

private static IEnumerable<TextPart> EnumerateTextParts(IList<DoubleUtf16Char> chars, Entities entities, int startIndex, int endIndex)
{
if (startIndex < 0 || startIndex >= chars.Count)
throw new ArgumentOutOfRangeException(nameof(startIndex));

if (endIndex < startIndex || endIndex > chars.Count)
throw new ArgumentOutOfRangeException(nameof(endIndex));

return EnumerateTextParts(chars, entities, startIndex, endIndex);
}

private static IEnumerable<TextPart> EnumerateTextParts(IList<DoubleUtf16Char> chars, Entities entities, int startIndex, int endIndex)
{
if (entities == null)
{
var text = ToString(chars, startIndex, endIndex - startIndex);
Expand Down Expand Up @@ -317,16 +319,19 @@ public static ExtendedTweetInfo GetExtendedTweetElements(this Status status)

var start = displayTextRange[0];
var end = displayTextRange[1];

var entities = status.ExtendedTweet?.Entities ?? status.Entities;

return new ExtendedTweetInfo
{
TweetText = EnumerateTextParts(
status.FullText ?? status.ExtendedTweet?.FullText ?? status.Text,
status.Entities,
entities,
start, end).ToArray(),
HiddenPrefix = status.Entities?.UserMentions == null ? new UserMentionEntity[0]
: status.Entities.UserMentions.Where(x => x.Indices[0] < start).ToArray(),
HiddenSuffix = (status.Entities?.Urls ?? Enumerable.Empty<UrlEntity>())
.Concat(status.Entities?.Media ?? Enumerable.Empty<UrlEntity>())
HiddenPrefix = entities?.UserMentions == null ? new UserMentionEntity[0]
: entities.UserMentions.Where(x => x.Indices[0] < start).ToArray(),
HiddenSuffix = (entities?.Urls ?? Enumerable.Empty<UrlEntity>())
.Concat(entities?.Media ?? Enumerable.Empty<UrlEntity>())
.Where(x => x.Indices[0] >= end).ToArray()
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/CoreTweetSupplement/project.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"title": "CoreTweetSupplement",
"version": "1.6.1-*",
"version": "1.6.2-*",
"authors": [ "CoreTweet Development Team" ],
"description": "An utility for client developers with CoreTweet",
"copyright": "Copyright (C) 2014-2016 CoreTweet Development Team",

"dependencies": {
"CoreTweet": "0.7.1.345"
"CoreTweet": "0.7.2.352"
},

"frameworks": {
Expand Down

0 comments on commit 67b3261

Please sign in to comment.