comparison src/plugins/plugin_xep_0045.py @ 2144:1d3f73e065e1

core, jp: component handling + client handling refactoring: - SàT can now handle components - plugin have now a "modes" key in PLUGIN_INFO where they declare if they can be used with clients and or components. They default to be client only. - components are really similar to clients, but with some changes in behaviour: * component has "entry point", which is a special plugin with a componentStart method, which is called just after component is connected * trigger end with a different suffixes (e.g. profileConnected vs profileConnectedComponent), so a plugin which manage both clients and components can have different workflow * for clients, only triggers of plugins handling client mode are launched * for components, only triggers of plugins needed in dependencies are launched. They all must handle component mode. * component have a sendHistory attribute (False by default) which can be set to True to allow saving sent messages into history * for convenience, "client" is still used in method even if it can now be a component * a new "component" boolean attribute tells if we have a component or a client * components have to add themselve Message protocol * roster and presence protocols are not added for components * component default port is 5347 (which is Prosody's default port) - asyncCreateProfile has been renamed for profileCreate, both to follow new naming convention and to prepare the transition to fully asynchronous bridge - createProfile has a new "component" attribute. When used to create a component, it must be set to a component entry point - jp: added --component argument to profile/create - disconnect bridge method is now asynchronous, this way frontends can know when disconnection is finished - new PI_* constants for PLUGIN_INFO values (not used everywhere yet) - client/component connection workflow has been moved to their classes instead of being a host methods - host.messageSend is now client.sendMessage, and former client.sendMessage is now client.sendMessageData. - identities are now handled in client.identities list, so it can be updated dynamically by plugins (in the future, frontends should be able to update them too through bridge) - profileConnecting* profileConnected* profileDisconnected* and getHandler now all use client instead of profile
author Goffi <goffi@goffi.org>
date Sun, 12 Feb 2017 17:55:43 +0100
parents 09c18fcd8225
children 33c8c4973743
comparison
equal deleted inserted replaced
2143:c3cac21157d4 2144:1d3f73e065e1
102 self.text_cmds.addWhoIsCb(self._whois, 100) 102 self.text_cmds.addWhoIsCb(self._whois, 100)
103 103
104 host.trigger.add("presence_available", self.presenceTrigger) 104 host.trigger.add("presence_available", self.presenceTrigger)
105 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=1000000) 105 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=1000000)
106 106
107 def profileConnected(self, profile): 107 def profileConnected(self, client):
108 def assign_service(service): 108 def assign_service(service):
109 client = self.host.getClient(profile)
110 client.muc_service = service 109 client.muc_service = service
111 return self.getMUCService(profile=profile).addCallback(assign_service) 110 return self.getMUCService(profile=client.profile).addCallback(assign_service)
112 111
113 def MessageReceivedTrigger(self, client, message_elt, post_treat): 112 def MessageReceivedTrigger(self, client, message_elt, post_treat):
114 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT: 113 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT:
115 if message_elt.subject or message_elt.delay: 114 if message_elt.subject or message_elt.delay:
116 return False 115 return False
475 474
476 def subject(self, client, room_jid, subject): 475 def subject(self, client, room_jid, subject):
477 self.checkRoomJoined(client, room_jid) 476 self.checkRoomJoined(client, room_jid)
478 return client._muc_client.subject(room_jid, subject) 477 return client._muc_client.subject(room_jid, subject)
479 478
480 def getHandler(self, profile): 479 def getHandler(self, client):
481 # create a MUC client and associate it with profile' session 480 # create a MUC client and associate it with profile' session
482 client = self.host.getClient(profile)
483 muc_client = client._muc_client = SatMUCClient(self) 481 muc_client = client._muc_client = SatMUCClient(self)
484 return muc_client 482 return muc_client
485 483
486 def kick(self, client, nick, room_jid, options=None): 484 def kick(self, client, nick, room_jid, options=None):
487 """ 485 """
884 "type": C.MESS_TYPE_INFO, 882 "type": C.MESS_TYPE_INFO,
885 "extra": extra, 883 "extra": extra,
886 "timestamp": time.time(), 884 "timestamp": time.time(),
887 } 885 }
888 self.host.messageAddToHistory(mess_data, self.parent) 886 self.host.messageAddToHistory(mess_data, self.parent)
889 self.host.messageSendToBridge(mess_data, self.parent) 887 self.host.sendMessageToBridge(mess_data, self.parent)
890 888
891 889
892 def userLeftRoom(self, room, user): 890 def userLeftRoom(self, room, user):
893 if not self.host.trigger.point("MUC user left", room, user, self.parent.profile): 891 if not self.host.trigger.point("MUC user left", room, user, self.parent.profile):
894 return 892 return
923 "type": C.MESS_TYPE_INFO, 921 "type": C.MESS_TYPE_INFO,
924 "extra": extra, 922 "extra": extra,
925 "timestamp": time.time(), 923 "timestamp": time.time(),
926 } 924 }
927 self.host.messageAddToHistory(mess_data, self.parent) 925 self.host.messageAddToHistory(mess_data, self.parent)
928 self.host.messageSendToBridge(mess_data, self.parent) 926 self.host.sendMessageToBridge(mess_data, self.parent)
929 927
930 def userChangedNick(self, room, user, new_nick): 928 def userChangedNick(self, room, user, new_nick):
931 self.host.bridge.mucRoomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile) 929 self.host.bridge.mucRoomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile)
932 930
933 def userUpdatedStatus(self, room, user, show, status): 931 def userUpdatedStatus(self, room, user, show, status):