changeset 238:a04b4830eef2 legit-client

Filter out non-own tweets included for replies
author nanaya <me@nanaya.net>
date Sat, 15 Jul 2023 01:53:05 +0900
parents 961d362e42c7
children c800506ae799
files app/lib/legit_client.rb
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/app/lib/legit_client.rb	Sat Jul 15 01:47:34 2023 +0900
+++ b/app/lib/legit_client.rb	Sat Jul 15 01:53:05 2023 +0900
@@ -5,7 +5,7 @@
     begin
       json = JSON.parse(resp)
       {
-        timeline: normalize_timeline(json['data']['user']['result']['timeline_v2']['timeline']['instructions']),
+        timeline: normalize_timeline(json['data']['user']['result']['timeline_v2']['timeline']['instructions'], user_id),
         raw: resp,
       }
     rescue => e
@@ -102,7 +102,7 @@
     ret
   end
 
-  def self.normalize_timeline(json)
+  def self.normalize_timeline(json, user_id)
     json.find { |instruction| instruction['type'] == 'TimelineAddEntries' }['entries']
       .filter { |entry| entry['entryId'] =~ /\A(profile-conversation|tweet)-/ }
       .reduce([]) do |acc, entry|
@@ -115,6 +115,7 @@
         end
         acc
       end.map { |rawTweet| normalize_tweet(rawTweet['itemContent']['tweet_results']['result']) }
+      .filter { |tweet| !tweet.nil? && tweet.dig(:user, :id) == user_id }
   end
 
   def self.normalize_tweet(json)