comparison app/lib/legit_client.rb @ 252:151bc6d97d39

Include pinned tweet
author nanaya <me@nanaya.net>
date Tue, 17 Oct 2023 00:04:11 +0900
parents 9e5f9ffa4077
children d726e8b92dd1
comparison
equal deleted inserted replaced
251:43cbceac80ab 252:151bc6d97d39
96 96
97 ret 97 ret
98 end 98 end
99 99
100 def self.normalize_timeline(json, user_id) 100 def self.normalize_timeline(json, user_id)
101 json.find { |instruction| instruction['type'] == 'TimelineAddEntries' }['entries'] 101 json
102 .filter { |entry| entry['entryId'] =~ /\A(profile-conversation|tweet)-/ } 102 .reduce([]) do |acc, instruction|
103 case instruction['type']
104 when 'TimelineAddEntries' then acc += instruction['entries']
105 when 'TimelinePinEntry' then acc << instruction['entry']
106 end
107
108 acc
109 end.filter { |entry| entry['entryId'] =~ /\A(profile-conversation|tweet)-/ }
103 .reduce([]) do |acc, entry| 110 .reduce([]) do |acc, entry|
104 if entry['content']['entryType'] == 'TimelineTimelineItem' 111 if entry['content']['entryType'] == 'TimelineTimelineItem'
105 acc.push(entry['content']) 112 acc.push(entry['content'])
106 else 113 else
107 entry['content']['items'].each do |item| 114 entry['content']['items'].each do |item|