comparison frontends/src/quick_frontend/quick_chat.py @ 2066:09c18fcd8225

plugin XEP-0045, quick frontend (app,chat): various chat improvments: - (XEP-0045): join defered is now fired when room is full joined and history is available - (XEP-0045): mucJOIN signature has changed, it now returns the same arguments as mucRoomJoined and a boolean which is True if the room was alread joined - quick frontend (app, chat): adapted code to new changes
author Goffi <goffi@goffi.org>
date Fri, 09 Sep 2016 23:54:33 +0200
parents 8fa0d95c2142
children 7834743705f0
comparison
equal deleted inserted replaced
2065:f3167c873e7b 2066:09c18fcd8225
216 for w in self.widgets: 216 for w in self.widgets:
217 w.updated(["state"]) 217 w.updated(["state"])
218 218
219 219
220 class QuickChat(quick_widgets.QuickWidget): 220 class QuickChat(quick_widgets.QuickWidget):
221
222 visible_states = ['chat_state'] # FIXME: to be removed, used only in quick_games 221 visible_states = ['chat_state'] # FIXME: to be removed, used only in quick_games
223 222
224 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, occupants=None, subject=None, profiles=None): 223 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None):
225 """ 224 """
226 @param type_: can be C.CHAT_ONE2ONE for single conversation or C.CHAT_GROUP for chat à la IRC 225 @param type_: can be C.CHAT_ONE2ONE for single conversation or C.CHAT_GROUP for chat à la IRC
227 """ 226 """
228 self.lang = '' # default language to use for messages 227 self.lang = '' # default language to use for messages
229 quick_widgets.QuickWidget.__init__(self, host, target, profiles=profiles) 228 quick_widgets.QuickWidget.__init__(self, host, target, profiles=profiles)
234 self.current_target = target 233 self.current_target = target
235 self.type = type_ 234 self.type = type_
236 if type_ == C.CHAT_GROUP: 235 if type_ == C.CHAT_GROUP:
237 if target.resource: 236 if target.resource:
238 raise exceptions.InternalError(u"a group chat entity can't have a resource") 237 raise exceptions.InternalError(u"a group chat entity can't have a resource")
239 self.nick = None 238 if nick is None:
239 raise exceptions.InternalError(u"nick must not be None for group chat")
240
241 self.nick = nick
240 self.occupants = {} 242 self.occupants = {}
241 self.setOccupants(occupants) 243 self.setOccupants(occupants)
242 else: 244 else:
243 if occupants is not None: 245 if occupants is not None or nick is not None:
244 raise exceptions.InternalError(u"only group chat can have occupants") 246 raise exceptions.InternalError(u"only group chat can have occupants or nick")
245 self.messages = OrderedDict() # key: uid, value: Message instance 247 self.messages = OrderedDict() # key: uid, value: Message instance
246 self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame 248 self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame
247 self.subject = subject 249 self.subject = subject
248 lt = time.localtime() 250 lt = time.localtime()
249 self.day_change = (lt.tm_year, lt.tm_mon, lt.tm_mday, 0, 0, 0, lt.tm_wday, lt.tm_yday, lt.tm_isdst) # struct_time of day changing time 251 self.day_change = (lt.tm_year, lt.tm_mon, lt.tm_mday, 0, 0, 0, lt.tm_wday, lt.tm_yday, lt.tm_isdst) # struct_time of day changing time
288 """copy important attribute for a new widget""" 290 """copy important attribute for a new widget"""
289 kwargs['type_'] = self.type 291 kwargs['type_'] = self.type
290 if self.type == C.CHAT_GROUP: 292 if self.type == C.CHAT_GROUP:
291 kwargs['occupants'] = {o.nick: o.data for o in self.occupants.itervalues()} 293 kwargs['occupants'] = {o.nick: o.data for o in self.occupants.itervalues()}
292 kwargs['subject'] = self.subject 294 kwargs['subject'] = self.subject
295 try:
296 kwargs['nick'] = self.nick
297 except AttributeError:
298 pass
293 299
294 def onPrivateCreated(self, widget): 300 def onPrivateCreated(self, widget):
295 """Method called when a new widget for private conversation (MUC) is created""" 301 """Method called when a new widget for private conversation (MUC) is created"""
296 raise NotImplementedError 302 raise NotImplementedError
297 303