Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_chat.py @ 1764:33c815c17fe6
quick_frontend (chat): temporary fix for bug 12:
- avoid duplicate one2one message (before the history + as a part of it)
- do not display "=> <nick> has joined the room" for each occupant when we have just joined a MUC
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 22 Dec 2015 11:44:51 +0100 |
parents | 9b557e76a5a8 |
children | d17772b0fe22 |
comparison
equal
deleted
inserted
replaced
1763:9b557e76a5a8 | 1764:33c815c17fe6 |
---|---|
53 self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame | 53 self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame |
54 | 54 |
55 if type_ == C.CHAT_ONE2ONE: | 55 if type_ == C.CHAT_ONE2ONE: |
56 self.historyPrint(profile=self.profile) | 56 self.historyPrint(profile=self.profile) |
57 | 57 |
58 # FIXME: has been introduced to temporarily fix http://bugs.goffi.org/show_bug.cgi?id=12 | |
59 self.initialised = False | |
60 | |
58 def __str__(self): | 61 def __str__(self): |
59 return u"Chat Widget [target: {}, type: {}, profile: {}]".format(self.target, self.type, self.profile) | 62 return u"Chat Widget [target: {}, type: {}, profile: {}]".format(self.target, self.type, self.profile) |
60 | 63 |
61 @staticmethod | 64 @staticmethod |
62 def getWidgetHash(target, profile): | 65 def getWidgetHash(target, profile): |
107 return True | 110 return True |
108 return False | 111 return False |
109 | 112 |
110 def addUser(self, nick): | 113 def addUser(self, nick): |
111 """Add user if it is not in the group list""" | 114 """Add user if it is not in the group list""" |
115 if not self.initialised: | |
116 return # FIXME: tmp fix for bug 12, do not flood the room with the messages when we've just entered it | |
112 self.printInfo("=> %s has joined the room" % nick) | 117 self.printInfo("=> %s has joined the room" % nick) |
113 | 118 |
114 def removeUser(self, nick): | 119 def removeUser(self, nick): |
115 """Remove a user from the group list""" | 120 """Remove a user from the group list""" |
116 self.printInfo("<= %s has left the room" % nick) | 121 self.printInfo("<= %s has left the room" % nick) |
146 log.debug(log_msg) | 151 log.debug(log_msg) |
147 | 152 |
148 target = self.target.bare | 153 target = self.target.bare |
149 | 154 |
150 def onHistory(history): | 155 def onHistory(history): |
156 self.initialised = True # FIXME: tmp fix for bug 12 | |
151 day_format = "%A, %d %b %Y" # to display the day change | 157 day_format = "%A, %d %b %Y" # to display the day change |
152 previous_day = datetime.now().strftime(day_format) | 158 previous_day = datetime.now().strftime(day_format) |
153 for line in history: | 159 for line in history: |
154 timestamp, from_jid, to_jid, message, type_, extra = line # FIXME: extra is unused ! | 160 timestamp, from_jid, to_jid, message, type_, extra = line # FIXME: extra is unused ! |
155 if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or | 161 if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or |
164 self.afterHistoryPrint() | 170 self.afterHistoryPrint() |
165 | 171 |
166 def onHistoryError(err): | 172 def onHistoryError(err): |
167 log.error(_("Can't get history")) | 173 log.error(_("Can't get history")) |
168 | 174 |
175 self.initialised = False # FIXME: tmp fix for bug 12, here needed for :history and :search commands | |
169 self.host.bridge.getHistory(unicode(self.host.profiles[profile].whoami.bare), unicode(target), size, True, search, profile, callback=onHistory, errback=onHistoryError) | 176 self.host.bridge.getHistory(unicode(self.host.profiles[profile].whoami.bare), unicode(target), size, True, search, profile, callback=onHistory, errback=onHistoryError) |
170 | 177 |
171 def _get_nick(self, entity): | 178 def _get_nick(self, entity): |
172 """Return nick of this entity when possible""" | 179 """Return nick of this entity when possible""" |
173 contact_list = self.host.contact_lists[self.profile] | 180 contact_list = self.host.contact_lists[self.profile] |
196 return | 203 return |
197 try: | 204 try: |
198 timestamp = float(extra['timestamp']) | 205 timestamp = float(extra['timestamp']) |
199 except KeyError: | 206 except KeyError: |
200 timestamp = None | 207 timestamp = None |
208 | |
209 if not self.initialised and self.type == C.CHAT_ONE2ONE: | |
210 return # FIXME: tmp fix for bug 12, do not display the first one2one message which is already in the local history | |
211 | |
201 if type_ == C.MESS_TYPE_INFO: | 212 if type_ == C.MESS_TYPE_INFO: |
202 self.printInfo(msg, extra=extra) | 213 self.printInfo(msg, extra=extra) |
203 else: | 214 else: |
215 self.initialised = True # FIXME: tmp fix for bug 12, do not discard any message from now | |
216 | |
204 nick = self._get_nick(from_jid) | 217 nick = self._get_nick(from_jid) |
205 if msg.startswith('/me '): | 218 if msg.startswith('/me '): |
206 self.printInfo('* %s %s' % (nick, msg[4:]), type_='me', extra=extra) | 219 self.printInfo('* %s %s' % (nick, msg[4:]), type_='me', extra=extra) |
207 else: | 220 else: |
208 # my_message is True if message comes from local user | 221 # my_message is True if message comes from local user |