From 4613e8e993d2731781072c371c3c59078f507d7f Mon Sep 17 00:00:00 2001 From: James Bunton Date: Sun, 29 Jul 2007 16:25:30 +1000 Subject: [PATCH] Conference rooms now show up as such in service discovery. --- src/disco.py | 35 +++++++++++++++++++---------------- src/main.py | 1 + 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/disco.py b/src/disco.py index 4fd2221..6abebf4 100644 --- a/src/disco.py +++ b/src/disco.py @@ -64,6 +64,18 @@ class ServerDiscovery: self.addFeature(DISCO, None, config.jid) self.addFeature(DISCO, None, "USER") + self.addFeature(DISCO, None, "ROOM") + + def _makeSearchJID(self, jid): + if jid.find('@') > 0: + if jid.find('%') > 0: + return "USER" + else: + return "ROOM" + elif config.compjid and to == config.compjid: + return config.jid + else: + return jid def sendIq(self, el, timeout=15): """ Used for sending IQ packets. @@ -86,21 +98,21 @@ class ServerDiscovery: return d def addIdentity(self, category, ctype, name, jid): - """ Adds an identity to this JID's discovery profile. If jid == "USER" then MSN users will get this identity. """ + """ Adds an identity to this JID's discovery profile. If jid == "USER" then MSN users will get this identity, jid == "ROOM" is for groupchat rooms. """ LogEvent(INFO) if not self.identities.has_key(jid): self.identities[jid] = [] self.identities[jid].append((category, ctype, name)) def addFeature(self, var, handler, jid): - """ Adds a feature to this JID's discovery profile. If jid == "USER" then MSN users will get this feature. """ + """ Adds a feature to this JID's discovery profile. If jid == "USER" then MSN users will get this feature, jid == "ROOM" is for groupchat rooms. """ LogEvent(INFO) if not self.features.has_key(jid): self.features[jid] = [] self.features[jid].append((var, handler)) def addNode(self, node, handler, name, jid, rootnode): - """ Adds a node to this JID's discovery profile. If jid == "USER" then MSN users will get this node. """ + """ Adds a node to this JID's discovery profile. If jid == "USER" then MSN users will get this node, jid == "ROOM" is for groupchat rooms. """ LogEvent(INFO) if not self.nodes.has_key(jid): self.nodes[jid] = {} @@ -149,13 +161,7 @@ class ServerDiscovery: self.sendDiscoItemsResponse(to=fro, ID=ID, ulang=ulang, jid=to) return - if to.find('@') > 0: - searchjid = "USER" - elif config.compjid and to == config.compjid: - searchjid = config.jid - else: - searchjid = to - for (feature, handler) in self.features.get(searchjid, []): + for (feature, handler) in self.features.get(self._makeSearchJID(to), []): if feature == xmlns and handler: LogEvent(INFO, "Handler found") handler(el) @@ -177,9 +183,8 @@ class ServerDiscovery: query = iq.addElement("query") query.attributes["xmlns"] = DISCO_INFO - searchjid = jid - if jid.find('@') > 0: searchjid = "USER" - if config.compjid and jid == config.compjid: searchjid = config.jid + searchjid = self._makeSearchJID(jid) + # Add any identities for (category, ctype, name) in self.identities.get(searchjid, []): identity = query.addElement("identity") @@ -206,9 +211,7 @@ class ServerDiscovery: query = iq.addElement("query") query.attributes["xmlns"] = DISCO_ITEMS - searchjid = jid - if jid.find('@') > 0: searchjid = "USER" - if config.compjid and jid == config.compjid: searchjid = config.jid + searchjid = self._makeSearchJID(jid) for node in self.nodes.get(searchjid, []): handler, name, rootnode = self.nodes[jid][node] if rootnode: diff --git a/src/main.py b/src/main.py index 6b1587a..a85a4ee 100644 --- a/src/main.py +++ b/src/main.py @@ -127,6 +127,7 @@ class PyTransport(component.Service): self.discovery.addFeature(disco.XCONFERENCE, None, config.jid) # So that clients know you can create groupchat rooms on the server self.discovery.addFeature("jabber:iq:conference", None, config.jid) # We don't actually support this, but Psi has a bug where it looks for this instead of the above self.discovery.addIdentity("client", "pc", "MSN Messenger", "USER") + self.discovery.addIdentity("conference", "text", "MSN Groupchat", "ROOM") self.xdb = xdb.XDB(config.jid, legacy.mangle) self.avatarCache = avatar.AvatarCache() -- 2.39.2