Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/helpers/threads.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Builds the thread objects served by the threads query from the tracked messages:
# every channel message with replies is a thread.

THREAD_PARTICIPANT_APP_PK = 102_398

def query_threads(reply_limit:)
parents = $message_list.select do |msg|
msg['parent_id'].nil? && $message_list.any? { |reply| reply['parent_id'] == msg['id'] }
Expand Down Expand Up @@ -29,6 +31,23 @@ def build_thread(parent:, reply_limit:)
'participant_count' => participants.count,
'reply_count' => replies.count,
'latest_replies' => replies.last(reply_limit),
'thread_participants' => participants.map { |user| { 'user_id' => user['id'], 'user' => user } }
'thread_participants' => participants.map { |user| build_thread_participant(parent: parent, user: user, replies: replies) }
}
end

# Mirrors the fields the real backend sends for a thread participant. Clients generated from the
# OpenAPI spec require app_pk, channel_cid, created_at, last_read_at and custom.
def build_thread_participant(parent:, user:, replies:)
user_replies = replies.select { |reply| reply['user']['id'] == user['id'] }
{
'app_pk' => THREAD_PARTICIPANT_APP_PK,
'channel_cid' => parent['cid'],
'thread_id' => parent['id'],
'user_id' => user['id'],
'user' => user,
'created_at' => user_replies.first['created_at'],
'last_read_at' => user_replies.last['created_at'],
'last_thread_message_at' => user_replies.last['created_at'],
'custom' => {}
}
end
Loading