Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_app.py @ 1963:a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
/!\ several features are temporarily disabled, like notifications in frontends
next step in refactoring, with the following changes:
- jp: updated jp message to follow changes in backend/bridge
- jp: added --lang, --subject, --subject_lang, and --type options to jp message + fixed unicode handling for jid
- quick_frontend (QuickApp, QuickChat):
- follow backend changes
- refactored chat, message are now handled in OrderedDict and uid are kept so they can be updated
- Message and Occupant classes handle metadata, so frontend just have to display them
- Primitivus (Chat):
- follow backend/QuickFrontend changes
- info & standard messages are handled in the same MessageWidget class
- improved/simplified handling of messages, removed update() method
- user joined/left messages are merged when next to each other
- a separator is shown when message is received while widget is out of focus, so user can quickly see the new messages
- affiliation/role are shown (in a basic way for now) in occupants panel
- removed "/me" messages handling, as it will be done by a backend plugin
- message language is displayed when available (only one language per message for now)
- fixed :history and :search commands
- core (constants): new constants for messages type, XML namespace, entity type
- core: *Message methods renamed to follow new code sytle (e.g. sendMessageToBridge => messageSendToBridge)
- core (messages handling): fixed handling of language
- core (messages handling): mes_data['from'] and ['to'] are now jid.JID
- core (core.xmpp): reorganised message methods, added getNick() method to client.roster
- plugin text commands: fixed plugin and adapted to new messages behaviour. client is now used in arguments instead of profile
- plugins: added information for cancellation reason in CancelError calls
- plugin XEP-0045: various improvments, but this plugin still need work:
- trigger is used to avoid message already handled by the plugin to be handled a second time
- changed the way to handle history, the last message from DB is checked and we request only messages since this one, in seconds (thanks Poezio folks :))
- subject reception is waited before sending the roomJoined signal, this way we are sure that everything including history is ready
- cmd_* method now follow the new convention with client instead of profile
- roomUserJoined and roomUserLeft messages are removed, the events are now handled with info message with a "ROOM_USER_JOINED" info subtype
- probably other forgotten stuffs :p
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 20 Jun 2016 18:41:53 +0200 |
parents | 633b5c21aefd |
children | 200cd707a46d |
comparison
equal
deleted
inserted
replaced
1962:a45235d8dc93 | 1963:a2bc5089c2eb |
---|---|
120 | 120 |
121 def _plug_profile_gotRoomsJoined(self, rooms_args): | 121 def _plug_profile_gotRoomsJoined(self, rooms_args): |
122 #Now we open the MUC window where we already are: | 122 #Now we open the MUC window where we already are: |
123 for room_args in rooms_args: | 123 for room_args in rooms_args: |
124 self.host.roomJoinedHandler(*room_args, profile=self.profile) | 124 self.host.roomJoinedHandler(*room_args, profile=self.profile) |
125 | |
126 self.bridge.getRoomsSubjects(self.profile, callback=self._plug_profile_gotRoomsSubjects) | |
127 | |
128 def _plug_profile_gotRoomsSubjects(self, subjects_args): | |
129 for subject_args in subjects_args: | |
130 self.host.roomNewSubjectHandler(*subject_args, profile=self.profile) | |
131 | |
132 #Presence must be requested after rooms are filled | 125 #Presence must be requested after rooms are filled |
133 self.host.bridge.getPresenceStatuses(self.profile, callback=self._plug_profile_gotPresences) | 126 self.host.bridge.getPresenceStatuses(self.profile, callback=self._plug_profile_gotPresences) |
134 | 127 |
135 def _plug_profile_gotPresences(self, presences): | 128 def _plug_profile_gotPresences(self, presences): |
136 def gotEntityData(data, contact): | 129 def gotEntityData(data, contact): |
261 self.registerSignal("progressFinished") | 254 self.registerSignal("progressFinished") |
262 self.registerSignal("progressError") | 255 self.registerSignal("progressError") |
263 self.registerSignal("actionResultExt", self.actionResultHandler) | 256 self.registerSignal("actionResultExt", self.actionResultHandler) |
264 self.registerSignal("roomJoined", iface="plugin") | 257 self.registerSignal("roomJoined", iface="plugin") |
265 self.registerSignal("roomLeft", iface="plugin") | 258 self.registerSignal("roomLeft", iface="plugin") |
266 self.registerSignal("roomUserJoined", iface="plugin") | |
267 self.registerSignal("roomUserLeft", iface="plugin") | |
268 self.registerSignal("roomUserChangedNick", iface="plugin") | 259 self.registerSignal("roomUserChangedNick", iface="plugin") |
269 self.registerSignal("roomNewSubject", iface="plugin") | 260 self.registerSignal("roomNewSubject", iface="plugin") |
270 self.registerSignal("chatStateReceived", iface="plugin") | 261 self.registerSignal("chatStateReceived", iface="plugin") |
271 self.registerSignal("psEvent", iface="plugin") | 262 self.registerSignal("psEvent", iface="plugin") |
272 | 263 |
488 if not self.trigger.point("messageNewTrigger", uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile=profile): | 479 if not self.trigger.point("messageNewTrigger", uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile=profile): |
489 return | 480 return |
490 | 481 |
491 from_me = from_jid.bare == self.profiles[profile].whoami.bare | 482 from_me = from_jid.bare == self.profiles[profile].whoami.bare |
492 target = to_jid if from_me else from_jid | 483 target = to_jid if from_me else from_jid |
493 | |
494 chat_type = C.CHAT_GROUP if type_ == C.MESS_TYPE_GROUPCHAT else C.CHAT_ONE2ONE | |
495 contact_list = self.contact_lists[profile] | 484 contact_list = self.contact_lists[profile] |
496 | 485 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=C.CHAT_ONE2ONE, on_new_widget=None, profile=profile) |
497 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=chat_type, on_new_widget=None, profile=profile) | |
498 | 486 |
499 self.current_action_ids = set() # FIXME: to be removed | 487 self.current_action_ids = set() # FIXME: to be removed |
500 self.current_action_ids_cb = {} # FIXME: to be removed | 488 self.current_action_ids_cb = {} # FIXME: to be removed |
501 | 489 |
502 if not from_jid in contact_list and from_jid.bare != self.profiles[profile].whoami.bare: | 490 if not from_jid in contact_list and from_jid.bare != self.profiles[profile].whoami.bare: |
558 self.setPresenceStatus(show, status, profile=profile) | 546 self.setPresenceStatus(show, status, profile=profile) |
559 return | 547 return |
560 | 548 |
561 self.callListeners('presence', entity, show, priority, statuses, profile=profile) | 549 self.callListeners('presence', entity, show, priority, statuses, profile=profile) |
562 | 550 |
563 def roomJoinedHandler(self, room_jid_s, room_nicks, user_nick, profile): | 551 def roomJoinedHandler(self, room_jid_s, occupants, user_nick, subject, profile): |
564 """Called when a MUC room is joined""" | 552 """Called when a MUC room is joined""" |
565 log.debug(u"Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s" % {'room_jid': room_jid_s, 'profile': profile, 'users': room_nicks}) | 553 log.debug(u"Room [{room_jid}] joined by {profile}, users presents:{users}".format(room_jid=room_jid_s, profile=profile, users=occupants.keys())) |
566 room_jid = jid.JID(room_jid_s) | 554 room_jid = jid.JID(room_jid_s) |
567 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) | 555 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, occupants=occupants, subject=subject, profile=profile) |
568 chat_widget.setUserNick(unicode(user_nick)) | 556 chat_widget.setUserNick(unicode(user_nick)) |
569 self.contact_lists[profile].setSpecial(room_jid, C.CONTACT_SPECIAL_GROUP) | 557 self.contact_lists[profile].setSpecial(room_jid, C.CONTACT_SPECIAL_GROUP) |
570 chat_widget.update() | 558 # chat_widget.update() |
571 | 559 |
572 def roomLeftHandler(self, room_jid_s, profile): | 560 def roomLeftHandler(self, room_jid_s, profile): |
573 """Called when a MUC room is left""" | 561 """Called when a MUC room is left""" |
574 log.debug(u"Room [%(room_jid)s] left by %(profile)s" % {'room_jid': room_jid_s, 'profile': profile}) | 562 log.debug(u"Room [%(room_jid)s] left by %(profile)s" % {'room_jid': room_jid_s, 'profile': profile}) |
575 room_jid = jid.JID(room_jid_s) | 563 room_jid = jid.JID(room_jid_s) |
576 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, room_jid, profile) | 564 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, room_jid, profile) |
577 if chat_widget: | 565 if chat_widget: |
578 self.widgets.deleteWidget(chat_widget) | 566 self.widgets.deleteWidget(chat_widget) |
579 self.contact_lists[profile].removeContact(room_jid) | 567 self.contact_lists[profile].removeContact(room_jid) |
580 | 568 |
581 def roomUserJoinedHandler(self, room_jid_s, user_nick, user_data, profile): | |
582 """Called when an user joined a MUC room""" | |
583 room_jid = jid.JID(room_jid_s) | |
584 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) | |
585 chat_widget.addUser(user_nick) | |
586 log.debug(u"user [%(user_nick)s] joined room [%(room_jid)s]" % {'user_nick': user_nick, 'room_jid': room_jid}) | |
587 | |
588 def roomUserLeftHandler(self, room_jid_s, user_nick, user_data, profile): | |
589 """Called when an user joined a MUC room""" | |
590 room_jid = jid.JID(room_jid_s) | |
591 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) | |
592 chat_widget.removeUser(user_nick) | |
593 log.debug(u"user [%(user_nick)s] left room [%(room_jid)s]" % {'user_nick': user_nick, 'room_jid': room_jid}) | |
594 | |
595 def roomUserChangedNickHandler(self, room_jid_s, old_nick, new_nick, profile): | 569 def roomUserChangedNickHandler(self, room_jid_s, old_nick, new_nick, profile): |
596 """Called when an user joined a MUC room""" | 570 """Called when an user joined a MUC room""" |
597 room_jid = jid.JID(room_jid_s) | 571 room_jid = jid.JID(room_jid_s) |
598 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) | 572 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) |
599 chat_widget.changeUserNick(old_nick, new_nick) | 573 chat_widget.changeUserNick(old_nick, new_nick) |
611 | 585 |
612 @param from_jid_s (unicode): JID of a contact or C.ENTITY_ALL | 586 @param from_jid_s (unicode): JID of a contact or C.ENTITY_ALL |
613 @param state (unicode): new state | 587 @param state (unicode): new state |
614 @param profile (unicode): current profile | 588 @param profile (unicode): current profile |
615 """ | 589 """ |
616 log.debug(_(u"Received new chat state {} from {} [{}]").format(state, from_jid_s, profile)) | 590 # log.debug(_(u"Received new chat state {} from {} [{}]").format(state, from_jid_s, profile)) |
617 from_jid = jid.JID(from_jid_s) if from_jid_s != C.ENTITY_ALL else C.ENTITY_ALL | 591 # from_jid = jid.JID(from_jid_s) if from_jid_s != C.ENTITY_ALL else C.ENTITY_ALL |
618 contact_list = self.contact_lists[profile] | 592 # contact_list = self.contact_lists[profile] |
619 for widget in self.widgets.getWidgets(quick_chat.QuickChat): | 593 # for widget in self.widgets.getWidgets(quick_chat.QuickChat): |
620 if profile != widget.profile: | 594 # if profile != widget.profile: |
621 continue | 595 # continue |
622 to_display = C.USER_CHAT_STATES[state] if (state and widget.type == C.CHAT_GROUP) else state | 596 # to_display = C.USER_CHAT_STATES[state] if (state and widget.type == C.CHAT_GROUP) else state |
623 if widget.type == C.CHAT_GROUP and from_jid_s == C.ENTITY_ALL: | 597 # if widget.type == C.CHAT_GROUP and from_jid_s == C.ENTITY_ALL: |
624 for occupant in [jid.newResource(widget.target, nick) for nick in widget.occupants]: | 598 # for occupant in [jid.newResource(widget.target, nick) for nick in widget.occupants]: |
625 contact_list.setCache(occupant, 'chat_state', to_display) | 599 # contact_list.setCache(occupant, 'chat_state', to_display) |
626 widget.update(occupant) | 600 # widget.update(occupant) |
627 elif from_jid.bare == widget.target.bare: # roster contact or MUC occupant | 601 # elif from_jid.bare == widget.target.bare: # roster contact or MUC occupant |
628 contact_list.setCache(from_jid, 'chat_state', to_display) | 602 # contact_list.setCache(from_jid, 'chat_state', to_display) |
629 widget.update(from_jid) | 603 # widget.update(from_jid) |
630 | 604 |
631 def psEventHandler(self, category, service_s, node, event_type, data, profile): | 605 def psEventHandler(self, category, service_s, node, event_type, data, profile): |
632 """Called when a PubSub event is received. | 606 """Called when a PubSub event is received. |
633 | 607 |
634 @param category(unicode): event category (e.g. "PEP", "MICROBLOG") | 608 @param category(unicode): event category (e.g. "PEP", "MICROBLOG") |