Skip to content

Commit

Permalink
Return the stored versions of messages
Browse files Browse the repository at this point in the history
Especially this allows hydrading the inReplyTo stubs.
  • Loading branch information
singpolyma committed Oct 2, 2024
1 parent fb6619a commit f3f1348
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions snikket/Chat.hx
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,25 @@ abstract class Chat {
abstract public function getMessagesAround(aroundId:Null<String>, aroundTime:Null<String>, handler:(Array<ChatMessage>)->Void):Void;

private function fetchFromSync(sync: MessageSync, callback: (Array<ChatMessage>)->Void) {
final chatMessages = [];
final promises = [];
sync.onMessages((messageList) -> {
final chatMessages = [];
for (m in messageList.messages) {
switch (m) {
case ChatMessageStanza(message):
final chatMessage = prepareIncomingMessage(message, new Stanza("message", { from: message.senderId() }));
persistence.storeMessage(client.accountId(), chatMessage, (m)->{});
if (message.chatId() == chatId) chatMessages.push(message);
promises.push(new thenshim.Promise((resolve, reject) -> {
persistence.storeMessage(client.accountId(), chatMessage, resolve);
}));
case ReactionUpdateStanza(update):
persistence.storeReaction(client.accountId(), update, (m)->{});
default:
// ignore
}
}
callback(chatMessages);
thenshim.PromiseTools.all(promises).then((chatMessages) -> {
callback(chatMessages.filter((m) -> m != null && m.chatId() == chatId));
});
});
sync.fetchNext();
}
Expand Down

0 comments on commit f3f1348

Please sign in to comment.