Skip to content

Commit

Permalink
fix(channel-web): fetch last message for each convo (#11288)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmasse committed Jan 25, 2022
1 parent fbbf064 commit 822a8cd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/channel-web/src/backend/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,16 @@ export default async (bp: typeof sdk, db: Database) => {
const conversations = await req.messaging.listConversations(userId, MAX_MESSAGE_HISTORY)
const config = await bp.config.getModuleConfigForBot('channel-web', botId)

const convsWithLastMessage: (Conversation & { lastMessage?: Message })[] = []
for (const conversation of conversations) {
convsWithLastMessage.push({
...conversation,
lastMessage: (await req.messaging.listMessages(conversation.id, 1))[0]
})
}

return res.send({
conversations: [...conversations],
conversations: convsWithLastMessage,
startNewConvoOnTimeout: config.startNewConvoOnTimeout,
recentConversationLifetime: config.recentConversationLifetime
})
Expand Down

0 comments on commit 822a8cd

Please sign in to comment.