Mercurial > libervia-backend
diff frontends/src/quick_frontend/quick_app.py @ 510:886754295efe
quick frontend, primitivus, wix: MUC private messages management
/!\ not fully finished, backend part is not done yet /!\
- as resources are discarded to manage chat windows lists, a pretty dirty hack is done to work around this:
full jid is escaped using a prefix (it becomes invalid and resource is preserved).
- new quick_utils module, with helper methods. escapePrivate and unescapePrivate implementations
- MUC private messages are not managed in Wix yet
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 11 Oct 2012 00:48:35 +0200 |
parents | f98bef71a918 |
children | 8ee9113d307b |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py Fri Sep 28 00:48:52 2012 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Thu Oct 11 00:48:35 2012 +0200 @@ -22,8 +22,11 @@ from logging import debug, info, warning, error from sat.tools.jid import JID from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService +from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate from optparse import OptionParser +import sat_frontends.quick_frontend.constants + import gettext gettext.install('sat_frontend', "../i18n", unicode=True) @@ -46,7 +49,7 @@ self.bridge.register("disconnected", self.disconnected) self.bridge.register("connectionError", self.connectionError) self.bridge.register("newContact", self.newContact) - self.bridge.register("newMessage", self.newMessage) + self.bridge.register("newMessage", self._newMessage) self.bridge.register("newAlert", self.newAlert) self.bridge.register("presenceUpdate", self.presenceUpdate) self.bridge.register("subscribe", self.subscribe) @@ -230,17 +233,48 @@ return entity=JID(JabberId) _groups = list(groups) - self.contact_list._replace(entity, _groups, attributes) - - def newMessage(self, from_jid, msg, type, to_jid, profile): + self.contact_list.replace(entity, _groups, attributes) + + def _newMessage(self, from_jid_s, msg, _type, to_jid_s, profile): + """newMessage premanagement: a dirty hack to manage private messages + if a private MUC message is detected, from_jid or to_jid is prefixed and resource is escaped""" if not self.check_profile(profile): return - sender=JID(from_jid) - addr=JID(to_jid) - win = addr if sender.short == self.profiles[profile]['whoami'].short else sender + from_jid = JID(from_jid_s) + to_jid = JID(to_jid_s) + + from_me = from_jid.short == self.profiles[profile]['whoami'].short + win = to_jid if from_me else from_jid + + if _type != "groupchat" and self.contact_list.getSpecial(win) == "MUC": + #we have a private message in a MUC room + #XXX: normaly we use bare jid as key, here we need the full jid + # so we cheat by replacing the "/" before the resource by + # a "@", so the jid is invalid, + new_jid = escapePrivate(win) + if from_me: + to_jid = new_jid + else: + from_jid = new_jid + if new_jid not in self.contact_list: + self.contact_list.add(new_jid) + + self.newMessage(from_jid, to_jid, msg, _type, profile) + + def newMessage(self, from_jid, to_jid, msg, _type, profile): + from_me = from_jid.short == self.profiles[profile]['whoami'].short + win = to_jid if from_me else from_jid + self.current_action_ids = set() self.current_action_ids_cb = {} - self.chat_wins[win.short].printMessage(sender, msg, profile) + + self.chat_wins[win.short].printMessage(from_jid, msg, profile) + + def sendMessage(self, to_jid, message, subject='', mess_type="auto", profile_key="@DEFAULT@"): + if to_jid.startswith(const_PRIVATE_PREFIX): + to_jid = unescapePrivate(to_jid) + mess_type = "chat" + self.bridge.sendMessage(to_jid, message, subject, mess_type, profile_key) def newAlert(self, msg, title, alert_type, profile): if not self.check_profile(profile): @@ -292,13 +326,13 @@ self.chat_wins[room_jid].setPresents(list(set([user_nick]+room_nicks))) self.contact_list.setSpecial(JID(room_jid), "MUC") - def roomLeft(self, room_jid, profile): + def roomLeft(self, room_jid_s, profile): """Called when a MUC room is left""" if not self.check_profile(profile): return - debug (_("Room [%(room_jid)s] left by %(profile)s") % {'room_jid':room_jid, 'profile': profile}) - del self.chat_wins[room_jid] - self.contact_list.remove(room_jid) + debug (_("Room [%(room_jid)s] left by %(profile)s") % {'room_jid':room_jid_s, 'profile': profile}) + del self.chat_wins[room_jid_s] + self.contact_list.remove(JID(room_jid_s)) def roomUserJoined(self, room_jid, user_nick, user_data, profile): """Called when an user joined a MUC room""" @@ -504,12 +538,12 @@ if key == "nick": if jid in self.contact_list: self.contact_list.setCache(jid, 'nick', value) - self.contact_list._replace(jid) + self.contact_list.replace(jid) elif key == "avatar": if jid in self.contact_list: filename = self.bridge.getAvatarFile(value) self.contact_list.setCache(jid, 'avatar', filename) - self.contact_list._replace(jid) + self.contact_list.replace(jid) def askConfirmation(self, type, id, data): raise NotImplementedError