git » sdk » commit 1d57a83

Show display name from roster

author Stephen Paul Weber
2023-09-12 20:51:22 UTC
committer Stephen Paul Weber
2023-09-12 20:51:22 UTC
parent 794ec7e6b045da357bdf3859c49f0a523e6d91d3

Show display name from roster

xmpp/Chat.hx +13 -0
xmpp/Client.hx +2 -1

diff --git a/xmpp/Chat.hx b/xmpp/Chat.hx
index bb9e5c9..b3f7a82 100644
--- a/xmpp/Chat.hx
+++ b/xmpp/Chat.hx
@@ -28,6 +28,8 @@ abstract class Chat {
 
 	abstract public function getMessages(beforeId:Null<String>, handler:MessageListHandler):MessageSync;
 
+	abstract public function getDisplayName():String;
+
 	public function isDirectChat():Bool { return type.match(ChatTypeDirect); };
 	public function isGroupChat():Bool  { return type.match(ChatTypeGroup);  };
 	public function isPublicChat():Bool { return type.match(ChatTypePublic); };
@@ -47,8 +49,19 @@ abstract class Chat {
 }
 
 class DirectChat extends Chat {
+	private var displayName:String;
+
 	public function new(client:Client, stream:GenericStream, chatId:String) {
 		super(client, stream, chatId, ChatTypeDirect);
+		this.displayName = chatId;
+	}
+
+	public function setDisplayName(fn:String) {
+		this.displayName = fn;
+	}
+
+	public function getDisplayName() {
+		return this.displayName;
 	}
 
 	public function getMessages(beforeId:Null<String>, handler:MessageListHandler):MessageSync {
diff --git a/xmpp/Client.hx b/xmpp/Client.hx
index 7ea1947..5cb07f9 100644
--- a/xmpp/Client.hx
+++ b/xmpp/Client.hx
@@ -94,7 +94,8 @@ class Client extends xmpp.EventEmitter {
 		var rosterGet = new RosterGet();
 		rosterGet.onFinished(() -> {
 			for (item in rosterGet.getResult()) {
-				getDirectChat(item.jid, false);
+				var chat = getDirectChat(item.jid, false);
+				if (item.fn != null && item.fn != "") chat.setDisplayName(item.fn);
 			}
 			this.trigger("chats/update", chats);
 		});