changeset 252:151bc6d97d39

Include pinned tweet
author nanaya <me@nanaya.net>
date Tue, 17 Oct 2023 00:04:11 +0900
parents 43cbceac80ab
children d726e8b92dd1
files app/lib/legit_client.rb
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/app/lib/legit_client.rb	Mon Jul 17 20:54:04 2023 +0900
+++ b/app/lib/legit_client.rb	Tue Oct 17 00:04:11 2023 +0900
@@ -98,8 +98,15 @@
   end
 
   def self.normalize_timeline(json, user_id)
-    json.find { |instruction| instruction['type'] == 'TimelineAddEntries' }['entries']
-      .filter { |entry| entry['entryId'] =~ /\A(profile-conversation|tweet)-/ }
+    json
+      .reduce([]) do |acc, instruction|
+        case instruction['type']
+        when 'TimelineAddEntries' then acc += instruction['entries']
+        when 'TimelinePinEntry' then acc << instruction['entry']
+        end
+
+        acc
+      end.filter { |entry| entry['entryId'] =~ /\A(profile-conversation|tweet)-/ }
       .reduce([]) do |acc, entry|
         if entry['content']['entryType'] == 'TimelineTimelineItem'
           acc.push(entry['content'])