# HG changeset patch # User Goffi # Date 1350813809 -7200 # Node ID 75216d94a89d45cb6d0802588febab582a708f48 # Parent 59b32c04e1054103aeab2a8de278bd54aad797e1 primitivus: fixed messages order in chat window diff -r 59b32c04e105 -r 75216d94a89d frontends/src/primitivus/chat.py --- a/frontends/src/primitivus/chat.py Sat Oct 20 19:22:51 2012 +0200 +++ b/frontends/src/primitivus/chat.py Sun Oct 21 12:03:29 2012 +0200 @@ -247,8 +247,9 @@ timestamp - time.mktime(_chat_text.timestamp) < 5): #we discard double messages, to avoid backlog / history conflict return - my_jid = self.host.profiles[profile]['whoami'] self.content.append(ChatText(self, timestamp or None, nick, mymess, msg)) + if timestamp: + self.content.sort(key=lambda chat_text: chat_text.timestamp) if self.text_list.get_focus()[1] == len(self.content)-2: #we don't change focus if user is not at the bottom #as that mean that he is probably watching discussion history diff -r 59b32c04e105 -r 75216d94a89d src/core/xmpp.py --- a/src/core/xmpp.py Sat Oct 20 19:22:51 2012 +0200 +++ b/src/core/xmpp.py Sun Oct 21 12:03:29 2012 +0200 @@ -37,6 +37,7 @@ self.host_app = host_app self.client_initialized = defer.Deferred() self.conn_deferred = defer.Deferred() + self.ignored = set() def getConnectionDeferred(self): """Return a deferred which fire when the client is connected""" @@ -97,6 +98,20 @@ self.host_app.bridge.disconnected(self.profile) #we send the signal to the clients self.host_app.purgeClient(self.profile) #and we remove references to this client + def ignore(self, entity_jid): + """Put entity in ignore list + @param entity_jid: jid of the entity to ignore""" + self.ignored.add(entity_jid) + + def unignore(self, entity_jid): + """Remove an entity from ignore list + @param entity_jid: jid of the entity to ignore""" + self.ignored.discard(entity_jid) + + def isIgnored(self, entity_jid): + """Tell if an entity is in ignore + @param entity_jid: jid of the entity to ignore""" + return entity_jid in self.ignored class SatMessageProtocol(xmppim.MessageProtocol): @@ -105,7 +120,12 @@ self.host = host def onMessage(self, message): - debug (_(u"got message from: %s"), message["from"]) + debug (_(u"got message from: %s") % message["from"]) + + if self.parent.isIgnored(jid.JID(message["from"])): + info(_(u"%s is ignored, discarding the message") % message["from"]) + return + if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile): return for e in message.elements(): diff -r 59b32c04e105 -r 75216d94a89d src/plugins/plugin_misc_text_commands.py --- a/src/plugins/plugin_misc_text_commands.py Sat Oct 20 19:22:51 2012 +0200 +++ b/src/plugins/plugin_misc_text_commands.py Sun Oct 21 12:03:29 2012 +0200 @@ -77,6 +77,15 @@ return jid.JID(arg+service_jid) return jid.JID(u"%s@%s" % (arg, service_jid)) + def _feedBack(self, message, mess_data, profile): + """Give a message back to the user""" + if mess_data["type"] == 'groupchat': + _from = mess_data["to"].userhostJID() + else: + _from = self.host.getJidNStream(profile)[0] + + self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile) + def cmd_nick(self, mess_data, profile): """change nickname""" debug("Catched nick command") @@ -150,6 +159,29 @@ return False + def cmd_ignore(self, mess_data, profile): + """Add an entity to ignore list""" + nick = mess_data["unparsed"].strip() + + if mess_data['type'] == "groupchat": + #if we are in a group chat, a nick must be given as argument + if not nick: + return False + room = mess_data["to"] + if not self.host.plugins["XEP-0045"].isNickInRoom(room, nick): + self._feedBack(u"[%s] is not in this room, can't ignore it" % (nick,), mess_data, profile) + return False + full_jid = jid.JID(u"%s/%s" % (room.userhost(), nick)) + else: + if nick: + self._feedBack("/ignore doesn't support arguments if you are not in a room", mess_data, profile) + return False + full_jid = mess_data["to"] + + self.host.getClient(profile).ignore(full_jid) + self._feedBack(_(u"[%s] added to ignore list") % full_jid, mess_data, profile) + return False + def cmd_help(self, mess_data, profile): """show help on available commands""" commands=filter(lambda method: method.startswith('cmd_'), dir(self)) @@ -165,14 +197,7 @@ spaces = (longuest - len(command)) * ' ' help_cmds.append(" /%s: %s %s" % (command[4:], spaces, help_str)) - if mess_data["type"] == 'groupchat': - _from = mess_data["to"].userhostJID() - else: - _from = self.host.getJidNStream(profile)[0] - help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),) - - self.host.bridge.newMessage(unicode(mess_data["to"]), help_mess, mess_data['type'], unicode(_from), {}, profile=profile) - + self._feedBack(help_mess, mess_data, profile) diff -r 59b32c04e105 -r 75216d94a89d src/plugins/plugin_xep_0045.py --- a/src/plugins/plugin_xep_0045.py Sat Oct 20 19:22:51 2012 +0200 +++ b/src/plugins/plugin_xep_0045.py Sun Oct 21 12:03:29 2012 +0200 @@ -126,6 +126,15 @@ if not self.__check_profile(profile) or not self.clients[profile].joined_rooms.has_key(room_jid_s): return '' return self.clients[profile].joined_rooms[room_jid_s].nick + + def isNickInRoom(self, room_jid, nick, profile): + """Tell if a nick is currently present in a room""" + profile = self.host.memory.getProfileName(profile_key) + if not self.__check_profile(profile): + raise exceptions.UnknownProfileError("Unknown or disconnected profile") + if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): + raise UnknownRoom("This room has not been joined") + return self.clients[profile].joined_rooms[room_jid.userhost()].inRoster(nick) def getRoomsSubjects(self, profile_key='@DEFAULT@'): """Return received subjects of rooms""" @@ -209,7 +218,6 @@ def getHandler(self, profile): self.clients[profile] = SatMUCClient(self) return self.clients[profile] - class SatMUCClient (muc.MUCClient): @@ -219,7 +227,7 @@ self.plugin_parent = plugin_parent self.host = plugin_parent.host muc.MUCClient.__init__(self) - self.joined_rooms = {} + self.joined_rooms = {} #FIXME: seem to do the same thing as MUCClient's _rooms attribute, must be removed self.rec_subjects = {} self.__changing_nicks = set() # used to keep trace of who is changing nick, # and to discard userJoinedRoom signal in this case @@ -283,7 +291,7 @@ def userUpdatedStatus(self, room, user, show, status): print("FIXME: MUC status not managed yet") - #FIXME: gof + #FIXME: def receivedSubject(self, room, user, subject): debug (_("New subject for room (%(room_id)s): %(subject)s") % {'room_id':room.roomJID.full(),'subject':subject})