Exemplo n.º 1
0
    def __init__(self, msn, to_invite = (), **k):
        Events.EventMixin.__init__(self)
        self.Bridge = None
        self.client = msn
        self._to_invite = set(to_invite)
        self._closed = False

        self._waschat = len(self._to_invite) > 1
        Conversation.__init__(self, msn)

        self.check_invite_list()

        self.protocol.register_conv(self)

        log.info("Added %r to msn's conversation list", self)

        self.buddies = {}
        self.typing_status = ObservableDict()

        self._pending_invite_callbacks = {}

        self.room_list.append(self.self_buddy)
        if self.ischat:
            cb = self.client.circle_buddies[self._chatbuddy]
            cb.sem.bind("resource_release", self._circle_unused)
            cb.sem.acquire()
            self.client.ns.JoinCircleConversation(self._chatbuddy)
            for bname in cb.buddy_names:
                if bname.lower().startswith(str(cb.guid).lower()):
                    continue
                self.buddy_join(bname)
Exemplo n.º 2
0
    def recv_msg_text(self, msg):
        name = msg.name
        textmsg = MSNTextMessage.from_net(msg.payload)

        buddy = self.buddies[name] = self.protocol.get_buddy(name)
        self.typing_status[buddy] = None

        if hasattr(textmsg, 'html'):
            message = textmsg.html().replace('\n', '<br />')
            content_type = 'text/html'
        else:
            message = textmsg
            content_type = 'text/plain'

        service_channel = offline = msg.payload.get("Service-Channel", None)
        sms = service_channel == 'IM/Mobile'
        offline = service_channel == "IM/Offline"
        timestamp_str = msg.payload.get('Original-Arrival-Time', None)
        if timestamp_str is None:
            timestamp = None
        else:
            timestamp = datetime.datetime.fromtimestamp(SOAPServices.strptime_highres(timestamp_str))

        did_receive = self.received_message(buddy, message, sms = sms, content_type = content_type,
                                            offline = offline, timestamp = timestamp)

        if name != self.self_buddy.name and did_receive:
            Conversation.incoming_message(self)
Exemplo n.º 3
0
    def exit(self):
        self.room_state.leave()

        try:
            del self.protocol.conversations[self.jid.as_unicode()]
        except KeyError:
            traceback.print_exc()

        Conversation.exit(self)
Exemplo n.º 4
0
    def __init__(self, protocol, jid, callback):
        pyxmpp.jabber.muc.MucRoomHandler.__init__(self)
        Conversation.__init__(self, protocol)

        self.callback = callback
        self.jid      = jid
        self.protocol.conversations[jid.as_unicode()] = self

        self.buddies    = {}
Exemplo n.º 5
0
    def exit(self):
        self.room_state.leave()

        try:
            del self.protocol.conversations[self.jid.as_unicode()]
        except KeyError:
            traceback.print_exc()

        Conversation.exit(self)
Exemplo n.º 6
0
    def __init__(self, protocol, jid, callback):
        pyxmpp.jabber.muc.MucRoomHandler.__init__(self)
        Conversation.__init__(self, protocol)

        self.callback = callback
        self.jid = jid
        self.protocol.conversations[jid.as_unicode()] = self

        self.buddies = {}
Exemplo n.º 7
0
    def user_left(self,user,stanza):
        'Called when a participant leaves the room.'

        bud = self.buddies[user.nick]
        try:
            self.room_list.remove(bud)
        except ValueError:
            pass

        self._log_presence(bud, 'left')
        Conversation.buddy_leave(self, bud)
Exemplo n.º 8
0
    def exit(self, force_close = False):
        log.info("%r exiting", self)
        self._closed = True

        if self.ischat and self._chat_target_type == MSNAB.IMAddressInfoType.TemporaryGroup:
            circle = self.protocol.circle_buddies[self._chatbuddy]
            circle.sem.release()
            self._chatbuddy = None
            self._chat_target_name = None
        Conversation.exit(self)
        self.Disconnect()
Exemplo n.º 9
0
    def user_left(self, user, stanza):
        'Called when a participant leaves the room.'

        bud = self.buddies[user.nick]
        try:
            self.room_list.remove(bud)
        except ValueError:
            pass

        self._log_presence(bud, 'left')
        Conversation.buddy_leave(self, bud)
Exemplo n.º 10
0
    def user_joined(self, user, stanza):
        'Called when a new participant joins the room.'

        bud = self._buddy(user)
        self.room_list.append(bud)

        if user is self.room_state.me and self.callback is not None:
            self.callback, cb = None, self.callback
            cb.success(self)

        self._log_presence(bud, 'joined')
        Conversation.buddy_join(self, bud)
Exemplo n.º 11
0
    def user_joined(self, user, stanza):
        'Called when a new participant joins the room.'

        bud = self._buddy(user)
        self.room_list.append(bud)

        if user is self.room_state.me and self.callback is not None:
            self.callback, cb = None, self.callback
            cb.success(self)

        self._log_presence(bud, 'joined')
        Conversation.buddy_join(self, bud)
Exemplo n.º 12
0
    def on_message_recv(self, name, msg, sms = False):
        buddy = self.buddies[name] = self.protocol.get_buddy(name)
        self.typing_status[buddy] = None

        if hasattr(msg, 'html'):
            message = msg.html().replace('\n', '<br />')
            content_type = 'text/html'
        else:
            message = msg
            content_type = 'text/plain'

        did_receive = self.received_message(buddy, message, sms = sms, content_type = content_type)

        if name != self.self_buddy.name and did_receive:
            Conversation.incoming_message(self)