def __init__(self, conn, manager, conversation, props, object_path=None): GlitterTextChannel.__init__(self, conn, manager, conversation, props, object_path) _, _, handle = manager._get_type_requested_handle(props) if handle.contact is None: raise telepathy.NotAvailable('Contact not available') self._pending_offline_messages = {} contact = handle.contact if conversation is None: if contact.presence != papyon.Presence.OFFLINE: client = conn.msn_client conversation = papyon.Conversation(client, [contact]) self._conversation = conversation if self._conversation: self._offline_contact = None self._offline_handle = None papyon.event.ConversationEventInterface.__init__(self, self._conversation) else: self._offline_handle = handle self._offline_contact = contact self._initial_handle = handle self._oim_box_ref = weakref.ref(conn.msn_client.oim_box)
def __init__(self, conn, manager, room, props, object_path=None): GlitterTextChannel.__init__(self, conn, manager, room, props, object_path) telepathy.server.ChannelInterfaceGroup.__init__(self) self.GroupFlagsChanged( telepathy.CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES | telepathy.CHANNEL_GROUP_FLAG_HANDLE_OWNERS_NOT_AVAILABLE, 0) # This is done in an idle so that classes which subclass this one # can do stuff in their __init__ but will still benefit from this method # being called. self.__add_initial_participants()
def __init__(self, conn, manager, room, props, object_path=None): GlitterTextChannel.__init__(self, conn, manager, room, props, object_path) telepathy.server.ChannelInterfaceGroup.__init__(self) self.GroupFlagsChanged( telepathy.CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES | telepathy.CHANNEL_GROUP_FLAG_HANDLE_OWNERS_NOT_AVAILABLE, 0 ) # This is done in an idle so that classes which subclass this one # can do stuff in their __init__ but will still benefit from this method # being called. self.__add_initial_participants()
def get_participants(self): # If we have no conversation, our contact is probably offline, # so we don't actually want this to return our offline contact # as adding him or her to a MUC won't work either. if self._conversation is None: return GlitterTextChannel.get_participants(self) else: return set([self._initial_handle.contact])
def AcknowledgePendingMessages(self, ids): GlitterTextChannel.AcknowledgePendingMessages(self, ids) messages = [] for id in ids: if id in self._pending_offline_messages.keys(): messages.append(self._pending_offline_messages[id]) del self._pending_offline_messages[id] self._oim_box_ref().delete_messages(messages)
def steal_conversation(self): # Set offline contact details for this 1-1 chat. self._offline_handle = self._initial_handle self._offline_contact = self._initial_handle.contact # If this 1-1 chat has been idle for sometime, the switchboard will # close, so the participant list will be an empty set. If we then # create a channel with the conference interface and then try and # extend from this conversation, there won't be any participants. # Let's reinvite them now. if self._conversation: if len(self._conversation.participants) == 0: self._conversation.invite_user(self._initial_handle.contact) return GlitterTextChannel.steal_conversation(self)
def _get_text_channel(self, props, conversation=None): _, surpress_handler, handle = self._get_type_requested_handle(props) path = "TextChannel%d" % (next(self.__text_channel_id),) logger.debug('New text channel %s', path) handle = props.get(telepathy.CHANNEL_INTERFACE + '.TargetHandle') room = self._conn.roomFromHandle(handle) # if room.oneToOne: # channel = GlitterImChannel(self._conn, self, room, props, # object_path=path) # else: channel = GlitterTextChannel(self._conn, self, room, props, object_path=path) return channel
def _send_text_message(self, message_type, text): if self._conversation is None and self._offline_contact.presence != papyon.Presence.OFFLINE: contact = self._offline_contact logger.info('Contact %s still connected, inviting him to the text channel before sending message' % str(contact)) client = self._conn_ref().msn_client self._conversation = papyon.Conversation(client, [contact]) papyon.event.ConversationEventInterface.__init__(self, self._conversation) self._offline_contact = None self._offline_handle = None if self._conversation is not None: # Actually send the message. return GlitterTextChannel._send_text_message(self, message_type, text) else: if message_type == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: logger.info("Sending offline message : %s" % str(text)) self._oim_box_ref().send_message(self._offline_contact, text.encode("utf-8")) #FIXME : Check if the message was sent correctly? else: raise telepathy.NotImplemented("Unhandled message type for offline contact") return True
def ListPendingMessages(self, clear): if clear: messages = self._pending_offline_messages.values() self._oim_box_ref().delete_messages(messages) return GlitterTextChannel.ListPendingMessages(self, clear)