+46
-30
app/firehose_stream.rb
+46
-30
app/firehose_stream.rb
···
48
48
return if msg.type != :commit
49
49
50
50
msg.operations.each do |op|
51
-
return unless op.type == :bsky_post
51
+
case op.type
52
+
when :bsky_post
53
+
process_post(msg, op)
54
+
55
+
when :bsky_like, :bsky_repost
56
+
# if you want to use the number of likes and/or reposts for filtering or sorting:
57
+
# add a likes/reposts column to feeds, then do +1 / -1 here depending on op.action
58
+
59
+
when :bsky_follow
60
+
# if you want to make a personalized feed that needs info about given user's follows/followers:
61
+
# add a followers table, then add/remove records here depending on op.action
52
62
53
-
if op.action == :delete
54
-
if post = Post.find_by(repo: op.repo, rkey: op.rkey)
55
-
post.destroy
56
-
end
63
+
else
64
+
# other types like :bsky_block, :bsky_profile (includes profile edits)
57
65
end
66
+
end
67
+
end
58
68
59
-
return unless op.action == :create
69
+
def process_post(msg, op)
70
+
if op.action == :delete
71
+
if post = Post.find_by(repo: op.repo, rkey: op.rkey)
72
+
post.destroy
73
+
end
74
+
end
60
75
61
-
begin
62
-
text = op.raw_record['text']
63
-
post = Post.new(
64
-
repo: op.repo,
65
-
time: msg.time,
66
-
text: text,
67
-
rkey: op.rkey,
68
-
data: JSON.generate(op.raw_record)
69
-
)
76
+
return unless op.action == :create
70
77
71
-
matched = false
78
+
begin
79
+
text = op.raw_record['text']
80
+
post = Post.new(
81
+
repo: op.repo,
82
+
time: msg.time,
83
+
text: text,
84
+
rkey: op.rkey,
85
+
data: JSON.generate(op.raw_record)
86
+
)
72
87
73
-
@feeds.each do |feed|
74
-
if feed.post_matches?(post)
75
-
FeedPost.create!(feed_id: feed.feed_id, post: post, time: msg.time) unless !@save_posts
76
-
matched = true
77
-
end
78
-
end
88
+
matched = false
79
89
80
-
if @log_posts == :all || @log_posts && matched
81
-
puts
82
-
puts text
90
+
@feeds.each do |feed|
91
+
if feed.post_matches?(post)
92
+
FeedPost.create!(feed_id: feed.feed_id, post: post, time: msg.time) unless !@save_posts
93
+
matched = true
83
94
end
95
+
end
84
96
85
-
post.save! if @save_posts == :all
86
-
rescue StandardError => e
87
-
puts "Error: #{e}"
88
-
p msg unless @env == :production || e.message == "nesting of 100 is too deep"
97
+
if @log_posts == :all || @log_posts && matched
98
+
puts
99
+
puts text
89
100
end
90
101
91
-
print '.' if @show_progress && @log_posts != :all
102
+
post.save! if @save_posts == :all
103
+
rescue StandardError => e
104
+
puts "Error: #{e}"
105
+
p msg unless @env == :production || e.message == "nesting of 100 is too deep"
92
106
end
107
+
108
+
print '.' if @show_progress && @log_posts != :all
93
109
end
94
110
end