From e53beb1f9d75306285f719b551e7a2d8496077dd Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Sat, 14 May 2022 11:19:35 -0400 Subject: [PATCH] fix --- src/BirdsiteLive.Domain/StatusService.cs | 3 +- .../TwitterTweetsService.cs | 35 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/BirdsiteLive.Domain/StatusService.cs b/src/BirdsiteLive.Domain/StatusService.cs index 51c1a15..a372a9b 100644 --- a/src/BirdsiteLive.Domain/StatusService.cs +++ b/src/BirdsiteLive.Domain/StatusService.cs @@ -67,9 +67,10 @@ namespace BirdsiteLive.Domain var content = extractedTags.content; if (tweet.IsRetweet) { - content = "RT: " + content; + // content = "RT: " + content; cc = new[] {"https://www.w3.org/ns/activitystreams#Public"}; } + cc = new[] {"https://www.w3.org/ns/activitystreams#Public"}; string inReplyTo = null; // if (tweet.InReplyToStatusId != default) diff --git a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs index e0eb3d3..0d254fd 100644 --- a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs +++ b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs @@ -167,26 +167,35 @@ namespace BirdsiteLive.Twitter var extractedMedia = Array.Empty(); JsonElement attachments; - if (tweet.TryGetProperty("attachments", out attachments)) + try { - foreach (JsonElement m in attachments.GetProperty("media_keys").EnumerateArray()) + if (tweet.TryGetProperty("attachments", out attachments)) { - var mediaInfo = media.EnumerateArray().Where(x => x.GetProperty("media_key").GetString() == m.GetString()).First(); - var mediaType = mediaInfo.GetProperty("type").GetString(); - if (mediaType != "photo") + foreach (JsonElement m in attachments.GetProperty("media_keys").EnumerateArray()) { - continue; - } - var url = mediaInfo.GetProperty("url").GetString(); - extractedMedia.Append( - new ExtractedMedia + var mediaInfo = media.EnumerateArray().Where(x => x.GetProperty("media_key").GetString() == m.GetString()).First(); + var mediaType = mediaInfo.GetProperty("type").GetString(); + if (mediaType != "photo") { - Url = url, - MediaType = GetMediaType(mediaType, url), + continue; } - ); + var url = mediaInfo.GetProperty("url").GetString(); + extractedMedia.Append( + new ExtractedMedia + { + Url = url, + MediaType = GetMediaType(mediaType, url), + } + ); + } } + + } + catch (Exception e) + { + _logger.LogError("Tried getting media from tweet, but got error:", e); + }