Ejemplo n.º 1
0
 def _getRoomID(response):
     root = createModel(response)
     room_id = None
     for xmlroom in root.room:
         if str(xmlroom.name[0].text[0]).lower() == name.lower():
             room_id = str(xmlroom.id[0].text[0])
             log.msg("found room %s for account %s with id %s" % (xmlroom.name[0].text[0], self.account, room_id))                    
             break
     if room_id is None:
         return None
     room = CampfireRoom(self.account, self.token, name, room_id, self.muc, self.campfire_name)
     return room.join().addCallback(lambda s: s.update()).addCallback(_saveHandle)
Ejemplo n.º 2
0
 def _updateMsgs(self, response):
     root = createModel(response)
     msgs = []
     for xmlmsg in root.message:
         msgtype = xmlmsg.type[0].text[0]
         if msgtype in ["TextMessage", "PasteMessage"]:
             user = self.participants.getName(xmlmsg.children['user-id'][0].text[0])
             body = xmlmsg.body[0].text[0]
             id = xmlmsg.id[0].text[0]
             tstamp = xmlmsg.children["created-at"][0].text[0]
             msgs.append(Message(id, user, body, msgtype, tstamp))
         self.msgs.last_msg_id = xmlmsg.children['id'][0].text[0]
     self.msgs.reset(msgs)
     return self
Ejemplo n.º 3
0
 def _updateMsgs(self, response):
     root = createModel(response)
     msgs = []
     for xmlmsg in root.message:
         msgtype = xmlmsg.type[0].text[0]
         if msgtype in ["TextMessage", "PasteMessage"]:
             user = self.participants.getName(
                 xmlmsg.children['user-id'][0].text[0])
             body = xmlmsg.body[0].text[0]
             id = xmlmsg.id[0].text[0]
             tstamp = xmlmsg.children["created-at"][0].text[0]
             msgs.append(Message(id, user, body, msgtype, tstamp))
         self.msgs.last_msg_id = xmlmsg.children['id'][0].text[0]
     self.msgs.reset(msgs)
     return self
Ejemplo n.º 4
0
    def _updateRoom(self, response):
        root = createModel(response)

        # update list of participants
        participants = {}
        for xmluser in root.users[0].user:
            uid = xmluser.id[0].text[0]
            name = xmluser.name[0].text[0]
            participants[uid] = name
        self.participants.update(participants)
        
        self.topic = root.topic[0].text[0]
        if self.msgs.last_msg_id is not None:
            url = "room/%s/recent.xml?since_message_id=%s" % (self.room_id, self.msgs.last_msg_id)
        else:
            url = "room/%s/recent.xml" % self.room_id
        return self.getPage(url).addCallback(self._updateMsgs)
Ejemplo n.º 5
0
    def _updateRoom(self, response):
        root = createModel(response)

        # update list of participants
        participants = {}
        for xmluser in root.users[0].user:
            uid = xmluser.id[0].text[0]
            name = xmluser.name[0].text[0]
            participants[uid] = name
        self.participants.update(participants)

        self.topic = root.topic[0].text[0]
        if self.msgs.last_msg_id is not None:
            url = "room/%s/recent.xml?since_message_id=%s" % (
                self.room_id, self.msgs.last_msg_id)
        else:
            url = "room/%s/recent.xml" % self.room_id
        return self.getPage(url).addCallback(self._updateMsgs)
Ejemplo n.º 6
0
 def _getToken(response):
     root = createModel(response)
     self.token = root.children["api-auth-token"][0].text[0]
     self.campfire_name = root.name[0].text[0]
     log.msg("Successfully authenticated %s with token %s" % (username, self.token))            
     return self