git » sdk » commit d207e49

Keep track of when main sync is done

author Stephen Paul Weber
2024-07-09 16:23:14 UTC
committer Stephen Paul Weber
2024-07-09 16:23:14 UTC
parent de3ca0437ae46d3e71b7ff9ae68147675b7e1e37

Keep track of when main sync is done

And expose per-chat sync state in the API

snikket/Chat.hx +11 -3
snikket/Client.hx +8 -1

diff --git a/snikket/Chat.hx b/snikket/Chat.hx
index c3f403a..4dcecfe 100644
--- a/snikket/Chat.hx
+++ b/snikket/Chat.hx
@@ -290,7 +290,11 @@ abstract class Chat {
 
 	@:allow(snikket)
 	private function livePresence() {
-		return false;
+		return true;
+	}
+
+	public function syncing() {
+		return !client.inSync;
 	}
 
 	/**
@@ -498,7 +502,7 @@ class DirectChat extends Chat {
 
 	@:allow(snikket)
 	private function prepareIncomingMessage(message:ChatMessage, stanza:Stanza) {
-		message.syncPoint = true; // TODO: if client is done initial MAM. right now it always is
+		message.syncPoint = !syncing();
 		return message;
 	}
 
@@ -786,6 +790,10 @@ class Channel extends Chat {
 		return false;
 	}
 
+	override public function syncing() {
+		return !inSync && livePresence();
+	}
+
 	private function nickInUse() {
 		for (nick => p in presence) {
 			for (status in p?.mucUser?.allTags("status") ?? []) {
@@ -852,7 +860,7 @@ class Channel extends Chat {
 
 	@:allow(snikket)
 	private function prepareIncomingMessage(message:ChatMessage, stanza:Stanza) {
-		message.syncPoint = inSync;
+		message.syncPoint = !syncing();
 		message.sender = JID.parse(stanza.attr.get("from")); // MUC always needs full JIDs
 		if (message.senderId() == getFullJid().asString()) {
 			message.recipients = message.replyTo;
diff --git a/snikket/Client.hx b/snikket/Client.hx
index c66ab06..356d65e 100644
--- a/snikket/Client.hx
+++ b/snikket/Client.hx
@@ -70,6 +70,8 @@ class Client extends EventEmitter {
 	private var _displayName: String;
 	private var fastMechanism: Null<String> = null;
 	private final pendingCaps: Map<String, Array<(Null<Caps>)->Chat>> = [];
+	@:allow(snikket)
+	private var inSync(default, null) = false;
 
 	/**
 		Create a new Client to connect to a particular account
@@ -549,7 +551,11 @@ class Client extends EventEmitter {
 			if (stream.clientId == null && !jid.isBare()) persistence.storeLogin(jid.asBare().asString(), jid.resource, displayName(), null);
 		}
 
-		if (data.resumed) return EventHandled;
+		if (data.resumed) {
+			inSync = true;
+			this.trigger("status/online", {});
+			return EventHandled;
+		}
 
 		// Enable carbons
 		sendStanza(
@@ -564,6 +570,7 @@ class Client extends EventEmitter {
 		rosterGet();
 		bookmarksGet(() -> {
 			sync(() -> {
+				inSync = true;
 				persistence.getChatsUnreadDetails(accountId(), chats, (details) -> {
 					for (detail in details) {
 						var chat = getChat(detail.chatId) ?? getDirectChat(detail.chatId, false);