Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_chat.py @ 1377:017270e6eea4
quick_frontends, primitivus: know who are the MUC occupants from the presence informations:
- QuickChat.occupants is now a property using cached information
- some MUC handlers are no more needed, the presence handler is enough
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 20 Mar 2015 16:25:38 +0100 |
parents | ba87b940f07a |
children | 3dae6964c071 |
comparison
equal
deleted
inserted
replaced
1376:28fd9e838f8f | 1377:017270e6eea4 |
---|---|
44 raise ValueError("A group chat entity can't have a resource") | 44 raise ValueError("A group chat entity can't have a resource") |
45 self.current_target = target | 45 self.current_target = target |
46 self.type = type_ | 46 self.type = type_ |
47 self.id = "" # FIXME: to be removed | 47 self.id = "" # FIXME: to be removed |
48 self.nick = None | 48 self.nick = None |
49 self.occupants = set() | |
50 self.games = {} | 49 self.games = {} |
51 | 50 |
52 def __str__(self): | 51 def __str__(self): |
53 return u"Chat Widget [target: {}, type: {}, profile: {}]".format(self.target, self.type, self.profile) | 52 return u"Chat Widget [target: {}, type: {}, profile: {}]".format(self.target, self.type, self.profile) |
54 | 53 |
61 """Get unique hash for private conversations | 60 """Get unique hash for private conversations |
62 | 61 |
63 This method should be used with force_hash to get unique widget for private MUC conversations | 62 This method should be used with force_hash to get unique widget for private MUC conversations |
64 """ | 63 """ |
65 return (unicode(profile), target) | 64 return (unicode(profile), target) |
66 | |
67 | 65 |
68 def addTarget(self, target): | 66 def addTarget(self, target): |
69 super(QuickChat, self).addTarget(target) | 67 super(QuickChat, self).addTarget(target) |
70 if target.resource: | 68 if target.resource: |
71 self.current_target = target # FIXME: tmp, must use resource priority throught contactList instead | 69 self.current_target = target # FIXME: tmp, must use resource priority throught contactList instead |
73 @property | 71 @property |
74 def target(self): | 72 def target(self): |
75 if self.type == C.CHAT_GROUP: | 73 if self.type == C.CHAT_GROUP: |
76 return self.current_target.bare | 74 return self.current_target.bare |
77 return self.current_target | 75 return self.current_target |
76 | |
77 @property | |
78 def occupants(self): | |
79 """Return the occupants of a group chat (nicknames). | |
80 | |
81 @return: set(unicode) | |
82 """ | |
83 if self.type != C.CHAT_GROUP: | |
84 return set() | |
85 contact_list = self.host.contact_lists[self.profile] | |
86 return contact_list.getCache(self.target, C.CONTACT_RESOURCES).keys() | |
78 | 87 |
79 def manageMessage(self, entity, mess_type): | 88 def manageMessage(self, entity, mess_type): |
80 """Tell if this chat widget manage an entity and message type couple | 89 """Tell if this chat widget manage an entity and message type couple |
81 | 90 |
82 @param entity (jid.JID): (full) jid of the sending entity | 91 @param entity (jid.JID): (full) jid of the sending entity |
89 else: | 98 else: |
90 if mess_type != C.MESS_TYPE_GROUPCHAT and entity in self.targets: | 99 if mess_type != C.MESS_TYPE_GROUPCHAT and entity in self.targets: |
91 return True | 100 return True |
92 return False | 101 return False |
93 | 102 |
94 def setPresents(self, nicks): | 103 def addUser(self, nick): |
95 """Set the occupants of a group chat. | |
96 | |
97 @param nicks (list[unicode]): sorted list of nicknames | |
98 """ | |
99 log.debug(_("Adding users %s to room") % nicks) | |
100 if self.type != C.CHAT_GROUP: | |
101 log.error(_("[INTERNAL] trying to set presents nicks for a non group chat window")) | |
102 raise Exception("INTERNAL ERROR") # TODO: raise proper Exception here | |
103 self.occupants.update(nicks) | |
104 | |
105 def replaceUser(self, nick, show_info=True): | |
106 """Add user if it is not in the group list""" | 104 """Add user if it is not in the group list""" |
107 log.debug (_("Replacing user %s") % nick) | 105 self.printInfo("=> %s has joined the room" % nick) |
108 if self.type != C.CHAT_GROUP: | 106 |
109 log.error (_("[INTERNAL] trying to replace user for a non group chat window")) | 107 def removeUser(self, nick): |
110 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here | |
111 len_before = len(self.occupants) | |
112 self.occupants.add(nick) | |
113 if len_before != len(self.occupants) and show_info: | |
114 self.printInfo("=> %s has joined the room" % nick) | |
115 | |
116 def removeUser(self, nick, show_info=True): | |
117 """Remove a user from the group list""" | 108 """Remove a user from the group list""" |
118 log.debug(_("Removing user %s") % nick) | 109 self.printInfo("<= %s has left the room" % nick) |
119 if self.type != C.CHAT_GROUP: | |
120 log.error (_("[INTERNAL] trying to remove user for a non group chat window")) | |
121 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here | |
122 self.occupants.remove(nick) | |
123 if show_info: | |
124 self.printInfo("<= %s has left the room" % nick) | |
125 | 110 |
126 def setUserNick(self, nick): | 111 def setUserNick(self, nick): |
127 """Set the nick of the user, usefull for e.g. change the color of the user""" | 112 """Set the nick of the user, usefull for e.g. change the color of the user""" |
128 self.nick = nick | 113 self.nick = nick |
129 | 114 |
130 def getUserNick(self): | 115 def getUserNick(self): |
131 return unicode(self.nick) | 116 return unicode(self.nick) |
132 | 117 |
133 def changeUserNick(self, old_nick, new_nick): | 118 def changeUserNick(self, old_nick, new_nick): |
134 """Change nick of a user in group list""" | 119 """Change nick of a user in group list""" |
135 log.debug(_("Changing nick of user %(old_nick)s to %(new_nick)s") % {"old_nick": old_nick, "new_nick": new_nick}) | |
136 if self.type != C.CHAT_GROUP: | |
137 log.error (_("[INTERNAL] trying to change user nick for a non group chat window")) | |
138 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here | |
139 self.removeUser(old_nick, show_info=False) | |
140 self.replaceUser(new_nick, show_info=False) | |
141 self.printInfo("%s is now known as %s" % (old_nick, new_nick)) | 120 self.printInfo("%s is now known as %s" % (old_nick, new_nick)) |
142 | 121 |
143 def setSubject(self, subject): | 122 def setSubject(self, subject): |
144 """Set title for a group chat""" | 123 """Set title for a group chat""" |
145 log.debug(_("Setting subject to %s") % subject) | 124 log.debug(_("Setting subject to %s") % subject) |