Skip to content

Commit 67b3261

Browse files
committed
Fix GetExtendedTweetElements to support streaming
1 parent fce01f3 commit 67b3261

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 1.6.1.{build}
1+
version: 1.6.2.{build}
22

33
os: Visual Studio 2015
44

src/CoreTweetSupplement/CoreTweetSupplement.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private static string ToString(IList<DoubleUtf16Char> source, int start, int cou
136136
/// </summary>
137137
/// <param name="text">The text such as <see cref="Status.Text"/>, <see cref="DirectMessage.Text"/> and <see cref="User.Description"/>.</param>
138138
/// <param name="entities">The <see cref="Entities"/> instance.</param>
139-
/// <returns>An <see cref="IEnumerable{ITextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
139+
/// <returns>An <see cref="IEnumerable{TextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
140140
public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities entities)
141141
{
142142
var chars = GetCodePoints(text);
@@ -150,20 +150,22 @@ public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities ent
150150
/// <param name="entities">The <see cref="Entities"/> instance.</param>
151151
/// <param name="startIndex">The starting character position in code point.</param>
152152
/// <param name="endIndex">The ending character position in code point.</param>
153-
/// <returns>An <see cref="IEnumerable{ITextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
153+
/// <returns>An <see cref="IEnumerable{TextPart}"/> whose elements are parts of <paramref name="text"/>.</returns>
154154
public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities entities, int startIndex, int endIndex)
155155
{
156-
return EnumerateTextParts(GetCodePoints(text), entities, startIndex, endIndex);
157-
}
156+
var chars = GetCodePoints(text);
158157

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

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

164+
return EnumerateTextParts(chars, entities, startIndex, endIndex);
165+
}
166+
167+
private static IEnumerable<TextPart> EnumerateTextParts(IList<DoubleUtf16Char> chars, Entities entities, int startIndex, int endIndex)
168+
{
167169
if (entities == null)
168170
{
169171
var text = ToString(chars, startIndex, endIndex - startIndex);
@@ -317,16 +319,19 @@ public static ExtendedTweetInfo GetExtendedTweetElements(this Status status)
317319

318320
var start = displayTextRange[0];
319321
var end = displayTextRange[1];
322+
323+
var entities = status.ExtendedTweet?.Entities ?? status.Entities;
324+
320325
return new ExtendedTweetInfo
321326
{
322327
TweetText = EnumerateTextParts(
323328
status.FullText ?? status.ExtendedTweet?.FullText ?? status.Text,
324-
status.Entities,
329+
entities,
325330
start, end).ToArray(),
326-
HiddenPrefix = status.Entities?.UserMentions == null ? new UserMentionEntity[0]
327-
: status.Entities.UserMentions.Where(x => x.Indices[0] < start).ToArray(),
328-
HiddenSuffix = (status.Entities?.Urls ?? Enumerable.Empty<UrlEntity>())
329-
.Concat(status.Entities?.Media ?? Enumerable.Empty<UrlEntity>())
331+
HiddenPrefix = entities?.UserMentions == null ? new UserMentionEntity[0]
332+
: entities.UserMentions.Where(x => x.Indices[0] < start).ToArray(),
333+
HiddenSuffix = (entities?.Urls ?? Enumerable.Empty<UrlEntity>())
334+
.Concat(entities?.Media ?? Enumerable.Empty<UrlEntity>())
330335
.Where(x => x.Indices[0] >= end).ToArray()
331336
};
332337
}

src/CoreTweetSupplement/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"title": "CoreTweetSupplement",
3-
"version": "1.6.1-*",
3+
"version": "1.6.2-*",
44
"authors": [ "CoreTweet Development Team" ],
55
"description": "An utility for client developers with CoreTweet",
66
"copyright": "Copyright (C) 2014-2016 CoreTweet Development Team",
77

88
"dependencies": {
9-
"CoreTweet": "0.7.1.345"
9+
"CoreTweet": "0.7.2.352"
1010
},
1111

1212
"frameworks": {

0 commit comments

Comments
 (0)