git » sdk » commit 1488433

Dummy persistence

author Stephen Paul Weber
2024-04-16 13:54:30 UTC
committer Stephen Paul Weber
2024-04-16 13:54:30 UTC
parent cdacddacb30a28e5c3731581a7ef3f7f4d7805d6

Dummy persistence

cpp.hxml +1 -0
snikket/Client.hx +5 -1
snikket/persistence/Dummy.hx +114 -0

diff --git a/cpp.hxml b/cpp.hxml
index a90ccfd..1b039f6 100644
--- a/cpp.hxml
+++ b/cpp.hxml
@@ -8,6 +8,7 @@
 HaxeCBridge
 snikket.Client
 snikket.Push
+snikket.persistence.Dummy
 snikket.persistence.Sqlite
 
 --cpp cpp
diff --git a/snikket/Client.hx b/snikket/Client.hx
index 6451066..7c80e80 100644
--- a/snikket/Client.hx
+++ b/snikket/Client.hx
@@ -979,7 +979,11 @@ class Client extends EventEmitter {
 	}
 
 	private function sync(?callback: ()->Void) {
-		persistence.lastId(accountId(), null, (lastId) -> doSync(callback, lastId));
+		if (Std.is(persistence, snikket.persistence.Dummy)) {
+			callback(); // No reason to sync if we're not storing anyway
+		} else {
+			persistence.lastId(accountId(), null, (lastId) -> doSync(callback, lastId));
+		}
 	}
 
 	private function onMAMJMI(sid: String, stanza: Stanza) {
diff --git a/snikket/persistence/Dummy.hx b/snikket/persistence/Dummy.hx
new file mode 100644
index 0000000..2c3e1d7
--- /dev/null
+++ b/snikket/persistence/Dummy.hx
@@ -0,0 +1,114 @@
+package snikket.persistence;
+
+#if cpp
+import HaxeCBridge;
+#end
+import datetime.DateTime;
+import haxe.Json;
+import haxe.crypto.Base64;
+import haxe.crypto.Sha1;
+import haxe.crypto.Sha256;
+import haxe.io.Bytes;
+import haxe.io.BytesData;
+import sys.FileSystem;
+import sys.db.Connection;
+import sys.io.File;
+import snikket.Caps;
+import snikket.Chat;
+import snikket.Message;
+
+// TODO: consider doing background threads for operations
+
+@:expose
+#if cpp
+@:build(HaxeCBridge.expose())
+@:build(HaxeSwiftBridge.expose())
+#end
+class Dummy implements Persistence {
+	/**
+		Create a basic persistence layer that persists nothing
+
+		@returns new persistence layer
+	**/
+	public function new() { }
+
+	@HaxeCBridge.noemit
+	public function lastId(accountId: String, chatId: Null<String>, callback:(Null<String>)->Void):Void {
+		callback(null);
+	}
+
+	@HaxeCBridge.noemit
+	public function storeChat(accountId: String, chat: Chat) { }
+
+	@HaxeCBridge.noemit
+	public function getChats(accountId: String, callback: (Array<SerializedChat>)->Void) {
+		callback([]);
+	}
+
+	@HaxeCBridge.noemit
+	public function storeMessage(accountId: String, message: ChatMessage, callback: (ChatMessage)->Void) {
+		callback(message);
+	}
+
+	@HaxeCBridge.noemit
+	public function getMessages(accountId: String, chatId: String, beforeId: Null<String>, beforeTime: Null<String>, callback: (Array<ChatMessage>)->Void) {
+		callback([]);
+	}
+
+	@HaxeCBridge.noemit
+	public function getChatsUnreadDetails(accountId: String, chats: Array<Chat>, callback: (Array<{ chatId: String, message: ChatMessage, unreadCount: Int }>)->Void) {
+		callback([]);
+	}
+
+	@HaxeCBridge.noemit
+	public function storeReaction(accountId: String, update: ReactionUpdate, callback: (Null<ChatMessage>)->Void) {
+		callback(null);
+	}
+
+	@HaxeCBridge.noemit
+	public function updateMessageStatus(accountId: String, localId: String, status:MessageStatus, callback: (ChatMessage)->Void) {
+		callback(null);
+	}
+
+	@HaxeCBridge.noemit
+	public function getMediaUri(hashAlgorithm:String, hash:BytesData, callback: (Null<String>)->Void) {
+		callback(null);
+	}
+
+	@HaxeCBridge.noemit
+	public function storeMedia(mime:String, bd:BytesData, callback: ()->Void) {
+		callback();
+	}
+
+	@HaxeCBridge.noemit
+	public function storeCaps(caps:Caps) { }
+
+	@HaxeCBridge.noemit
+	public function getCaps(ver:String, callback: (Caps)->Void) {
+		callback(null);
+	}
+
+	@HaxeCBridge.noemit
+	public function storeLogin(login:String, clientId:String, displayName:String, token:Null<String>) { }
+
+	@HaxeCBridge.noemit
+	public function getLogin(login:String, callback:(Null<String>, Null<String>, Int, Null<String>)->Void) {
+		callback(null, null, 0, null);
+	}
+
+	@HaxeCBridge.noemit
+	public function storeStreamManagement(accountId:String, smId:String, outboundCount:Int, inboundCount:Int, outboundQueue:Array<String>) { }
+
+	@HaxeCBridge.noemit
+	public function getStreamManagement(accountId:String, callback: (Null<String>, Int, Int, Array<String>)->Void) {
+		callback(null, -1, -1, []);
+	}
+
+	@HaxeCBridge.noemit
+	public function storeService(accountId:String, serviceId:String, name:Null<String>, node:Null<String>, caps:Caps) { }
+
+	@HaxeCBridge.noemit
+	public function findServicesWithFeature(accountId:String, feature:String, callback:(Array<{serviceId:String, name:Null<String>, node:Null<String>, caps: Caps}>)->Void) {
+		callback([]);
+	}
+}