Ejemplo n.º 1
0
Archivo: muc.py Proyecto: Gandi/wokkel
    def history(self, roomJID, messages):
        """
        Send history to create a MUC based on a one on one chat.

        See: http://xmpp.org/extensions/xep-0045.html#continue

        @param roomJID: The room jabber/xmpp entity id.
        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}

        @param messages: The history to send to the room as an ordered list of
                         message, represented by a dictionary with the keys
                         C{'stanza'}, holding the original stanza a
                         L{domish.Element}, and C{'timestamp'} with the
                         timestamp.
        @type messages: C{list} of L{domish.Element}
        """

        for message in messages:
            stanza = message["stanza"]
            stanza["type"] = "groupchat"

            delay = Delay(stamp=message["timestamp"])

            sender = stanza.getAttribute("from")
            if sender is not None:
                delay.sender = jid.JID(sender)

            stanza.addChild(delay.toElement())

            stanza["to"] = roomJID.userhost()
            if stanza.hasAttribute("from"):
                del stanza["from"]

            self.xmlstream.send(stanza)
Ejemplo n.º 2
0
    def history(self, roomJID, messages):
        """
        Send history to create a MUC based on a one on one chat.

        See: http://xmpp.org/extensions/xep-0045.html#continue

        @param roomJID: The room jabber/xmpp entity id.
        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}

        @param messages: The history to send to the room as an ordered list of
                         message, represented by a dictionary with the keys
                         L{'stanza'}, holding the original stanza a
                         L{domish.Element}, and L{'timestamp'} with the
                         timestamp.
        @type messages: L{list} of L{domish.Element}
        """

        for message in messages:
            stanza = message['stanza']
            stanza['type'] = 'groupchat'

            delay = Delay(stamp=message['timestamp'])

            sender = stanza.getAttribute('from')
            if sender is not None:
                delay.sender = jid.JID(sender)

            stanza.addChild(delay.toElement())

            stanza['to'] = roomJID.userhost()
            if stanza.hasAttribute('from'):
                del stanza['from']

            self.xmlstream.send(stanza)
Ejemplo n.º 3
0
    def test_toElementLegacy(self):
        """
        The legacy format uses C{CCYYMMDDThh:mm:ss} in the old namespace.
        """
        delay = Delay(stamp=datetime(2002, 9, 10, 23, 8, 25,
                                  tzinfo=dateutil.tz.tzutc()),
                      sender=JID(u'*****@*****.**'))
        element = delay.toElement(legacy=True)

        self.assertEqual(u'jabber:x:delay', element.uri)
        self.assertEqual(u'x', element.name)
        self.assertEqual(u'20020910T23:08:25', element.getAttribute('stamp'))
        self.assertEqual(u'*****@*****.**', element.getAttribute('from'))
Ejemplo n.º 4
0
    def test_toElement(self):
        """
        The DOM structure has the serialized timestamp and sender address.
        """
        delay = Delay(stamp=datetime(2002, 9, 10, 23, 8, 25,
                                  tzinfo=dateutil.tz.tzutc()),
                      sender=JID(u'*****@*****.**'))
        element = delay.toElement()

        self.assertEqual(u'urn:xmpp:delay', element.uri)
        self.assertEqual(u'delay', element.name)
        self.assertEqual(u'2002-09-10T23:08:25Z', element.getAttribute('stamp'))
        self.assertEqual(u'*****@*****.**', element.getAttribute('from'))
Ejemplo n.º 5
0
    def test_toElementLegacy(self):
        """
        The legacy format uses C{CCYYMMDDThh:mm:ss} in the old namespace.
        """
        delay = Delay(stamp=datetime(2002, 9, 10, 23, 8, 25,
                                  tzinfo=dateutil.tz.tzutc()),
                      sender=JID(u'*****@*****.**'))
        element = delay.toElement(legacy=True)

        self.assertEqual(u'jabber:x:delay', element.uri)
        self.assertEqual(u'x', element.name)
        self.assertEqual(u'20020910T23:08:25', element.getAttribute('stamp'))
        self.assertEqual(u'*****@*****.**', element.getAttribute('from'))
Ejemplo n.º 6
0
    def test_toElement(self):
        """
        The DOM structure has the serialized timestamp and sender address.
        """
        delay = Delay(stamp=datetime(2002, 9, 10, 23, 8, 25,
                                  tzinfo=dateutil.tz.tzutc()),
                      sender=JID(u'*****@*****.**'))
        element = delay.toElement()

        self.assertEqual(u'urn:xmpp:delay', element.uri)
        self.assertEqual(u'delay', element.name)
        self.assertEqual(u'2002-09-10T23:08:25Z', element.getAttribute('stamp'))
        self.assertEqual(u'*****@*****.**', element.getAttribute('from'))