Beispiel #1
0
 def send(contact, resource, presence):
     jid = JID(contact)
     jid.resource = resource
     if jid == self.stream.boundjid:
         return
     msg_xml = build_presence_dbxml(jid, presence)
     msg_xml.attrib['to'] = self.stream.boundjid.bare
     self.stream.send_element(msg_xml)
Beispiel #2
0
 def testJIDchange(self):
     """Test changing JID of the form 'user@server/resource/with/slashes'"""
     j = JID('user1@someserver1/some1/resource1')
     j.user = '******'
     j.domain = 'someserver'
     j.resource = 'some/resource'
     self.check_jid(j, 'user', 'someserver', 'some/resource',
                    'user@someserver', 'user@someserver/some/resource',
                    'user@someserver/some/resource')
Beispiel #3
0
 def testJIDchange(self):
     """Test changing JID of the form 'user@server/resource/with/slashes'"""
     j = JID('user1@someserver1/some1/resource1')
     j.user = '******'
     j.domain = 'someserver'
     j.resource = 'some/resource'
     self.check_jid(j,
                    'user',
                    'someserver',
                    'some/resource',
                    'user@someserver',
                    'user@someserver/some/resource',
                    'user@someserver/some/resource')
Beispiel #4
0
 async def _handle_user_items(self, iq):
     target = iq['to']
     disco = iq['disco_items']
     reply = iq.reply(clear=False)
     if not await self._allow_access(target):
         reply.send()
         return
     if disco['node']:
         reply.send()
         return
     result = await self.stream.session_hook.get_all_resources(target.user)
     if result:
         items = reply['disco_items']
         for resource, priority in result:
             jid = JID(target)
             jid.resource = resource
             items.add_item(jid)
     reply.send()
Beispiel #5
0
    def command_say(self,
                    line: str,
                    attention: bool = False,
                    correct: bool = False) -> None:
        if not self.on:
            return
        our_jid = JID(self.jid.bare)
        our_jid.resource = self.own_nick
        msg = self.core.xmpp.make_message(
            mto=self.jid.full,
            mfrom=our_jid,
        )
        msg['type'] = 'chat'
        msg['body'] = line
        x = ET.Element('{%s}x' % NS_MUC_USER)
        msg.append(x)
        # trigger the event BEFORE looking for colors.
        # This lets a plugin insert \x19xxx} colors, that will
        # be converted in xhtml.
        self.core.events.trigger('private_say', msg, self)
        if not msg['body']:
            return
        if correct or msg['replace']['id']:
            msg['replace']['id'] = self.last_sent_message['id']
        else:
            del msg['replace']

        if msg['body'].find('\x19') != -1:
            msg.enable('html')
            msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
            msg['body'] = xhtml.clean_text(msg['body'])
        if config.get_by_tabname('send_chat_states', self.general_jid):
            needed = 'inactive' if self.inactive else 'active'
            msg['chat_state'] = needed
        if attention:
            msg['attention'] = True
        self.core.events.trigger('private_say_after', msg, self)
        if not msg['body']:
            return
        self.set_last_sent_message(msg, correct=correct)
        self.core.handler.on_groupchat_private_message(msg, sent=True)
        msg._add_receipt = True
        msg.send()
        self.cancel_paused_delay()
Beispiel #6
0
 async def _handle_subscribed(self, msg, user, contact, values):
     if self.stream.is_local(contact.domain):
         await self._inbound_subscribed(msg.xml, contact, user)
     elif not await self._remote_server(msg):
         return
     if values is not None:
         await self.stream.roster.send_push(user, contact, values)
         presences = (await self.stream.session_hook.
                      get_all_presences(user.username))
         if presences is None:
             # no session database, try IPC broadcast
             await self.stream.ipc_send('presence.subscribed',
                                        user,
                                        msg.xml)
         else:
             for resource, priority, presence in presences:
                 jid = JID(contact)
                 jid.resource = resource
                 msg_xml = build_presence_dbxml(jid, presence)
                 await self.stream.ipc_send('presence.available',
                                            contact,
                                            msg_xml)
Beispiel #7
0
 async def _handle_unsubscribed(self, xml, user, contact, values,
                                preapproved=False, push=True):
     sub = values.get('subscription', 'none')
     subscribed = sub in self.from_types
     if subscribed:
         values['subscription'] = self.unsubscribed_map.get(sub, sub)
     if push and (subscribed or preapproved):
         await self.stream.roster.send_push(user, contact, values)
     if not subscribed:
         return False
     resources = await (self.stream.session_hook.
                        get_all_resources(user.username))
     if resources is None:
         # no session database, try IPC broadcast
         await self.stream.ipc_send('presence.unsubscribed',
                                    user,
                                    xml)
     else:
         for resource, priority in resources:
             jid = JID(user)
             jid.resource = resource
             await self._send_unavailable(jid, contact)
     return True
Beispiel #8
0
 def ack_message(self, msg_id: str, msg_jid: JID):
     if JID(msg_jid).bare == self.core.xmpp.boundjid.bare:
         msg_jid = JID(self.jid.bare)
         msg_jid.resource = self.own_nick
     super().ack_message(msg_id, msg_jid)