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' % unicode(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 ButterflyTextChannel._send_text_message( self, message_type, text) else: if message_type == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: logger.info("Sending offline message : %s" % unicode(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 Send(self, message_type, text): logger.debug('Send') if message_type != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: logger.error('Unhandled message type: {}'.format(message_type)) raise telepathy.NotImplemented("Unhandled message type") message_id = self._send_text_message(self._handle.name, text) return dbus.String(message_id)
def _get_media_channel(self, props, call=None): _, surpress_handler, handle = self._get_type_requested_handle(props) if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT: raise telepathy.NotImplemented('Only contacts are allowed') contact = handle.contact if contact.presence == papyon.Presence.OFFLINE: raise telepathy.NotAvailable('Contact not available') logger.debug('New media channel') if call is None: client = self._conn.msn_client call = client.call_manager.create_call(contact) path = "MediaChannel/%d" % self.__media_channel_id self.__media_channel_id += 1 return ButterflyMediaChannel(self._conn, self, call, handle, props, object_path=path)
def _get_text_channel(self, props, conversation=None): _, surpress_handler, handle = self._get_type_requested_handle(props) path = "TextChannel%d" % self.__text_channel_id self.__text_channel_id += 1 if handle.get_type() == telepathy.HANDLE_TYPE_CONTACT: logger.debug( 'New text channel for contact handle, name: %s, id: %s, type: %s' % (handle.name, handle.id, handle.type)) channel = SunshineTextChannel(self._conn, self, conversation, props, object_path=path) return channel elif handle.get_type() == telepathy.HANDLE_TYPE_ROOM: logger.debug( 'New text channel for room handle, name: %s, id: %s, type: %s' % (handle.name, handle.id, handle.type)) channel = SunshineRoomTextChannel(self._conn, self, conversation, props, object_path=path) return channel else: raise telepathy.NotImplemented('Unknown handle for text channel.')
def SendMessage(self, message, flags): headers = message.pop(0) message_type = int(headers.get('message-type', telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL)) if message_type != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: raise telepathy.NotImplemented("Unhandled message type") text = None #TODO html for part in message: if part.get("content-type", None) == "text/plain": text = part['content'] break if text is None: raise telepathy.NotImplemented("Unhandled message type") message_id = self._send_text_message(self._handle.name, text) return dbus.String(message_id)
def SendMessage(self, message, flags, _success, _error): headers = message.pop(0) message_type = int( headers.get('message-type', telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL)) if message_type != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: raise telepathy.NotImplemented("Unhandled message type") text = None for part in message: if part.get("content-type", None) == "text/plain": text = part['content'] break if text is None: raise telepathy.NotImplemented("Unhandled message type") self._room.sendMessage(text) _success('')
def ProvideFile(self, address_type, access_control, param): logger.debug("Provide file") if address_type not in self.socket_types.keys(): raise telepathy.NotImplemented("Socket type %u is unsupported" % address_type) self.socket = self.add_listener() self.channel = self.add_io_channel(self.socket) return self.socket.getsockname()
def SendMessage(self, message, flags, _success, _error): headers = message.pop(0) message_type = int( headers.get('message-type', telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL)) if message_type != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: raise telepathy.NotImplemented("Unhandled message type") text = None for part in message: if part.get("content-type", None) == "text/plain": text = part['content'] break if text is None: raise telepathy.NotImplemented("Unhandled message type") if self._send_text_message(message_type, text): timestamp = int(time.time()) # The function MUST return before emitting the signals _success('') self._signal_text_sent(timestamp, message_type, text)
def _send_text_message(self, message_type, text): "Send a simple text message, return true if sent correctly" if self._conversation is not None: if message_type == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: logger.info("Sending message : %s" % unicode(text)) self._conversation.send_text_message( papyon.ConversationMessage(text)) else: raise telepathy.NotImplemented("Unhandled message type") return True else: logger.warning('Tried sending a message with no conversation') return False
def AcceptFile(self, address_type, access_control, param, offset): logger.debug("Accept file") if address_type not in self.socket_types.keys(): raise telepathy.NotImplemented("Socket type %u is unsupported" % address_type) self.socket = self.add_listener() self.channel = self.add_io_channel(self.socket) self.set_state(telepathy.FILE_TRANSFER_STATE_PENDING, telepathy.FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED) self.InitialOffsetDefined(0) self.set_state(telepathy.FILE_TRANSFER_STATE_OPEN, telepathy.FILE_TRANSFER_STATE_CHANGE_REASON_NONE) return self.socket.getsockname()
def Send(self, message_type, text): if message_type == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: logger.info( "Sending message to %s, id %s, body: '%s'" % (str(self.handle.name), str(self.handle.id), unicode(text))) msg = text.decode('UTF-8').encode('windows-1250', 'replace') #gg_text = escape(text.decode('UTF-8')).encode('UTF-8').replace('<', '<').replace('>', '>') gg_text = text.decode('UTF-8', 'xmlcharrefreplace').replace( '<', '<').replace('>', '>') self._conn_ref().profile.sendTo(int(self.handle.name), str(gg_text), str(msg)) self._conn_ref().profile.sendTypingNotify(int(self.handle.name), 0) self.signalTextSent(int(time.time()), message_type, text) else: raise telepathy.NotImplemented("Unhandled message type")
def Send(self, message_type, text): if message_type == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: recipients = [] if self.contacts != None: for rhandle in self.contacts: recipients.append(rhandle.name) for nr in recipients: print nr recs_tmp = sorted(recipients) recs_tmp.remove(nr) logger.info("Sending message to %s, id %s, body: '%s'" % (str(nr), str(self.handle.id), unicode(text))) msg = text.encode('windows-1250') self.conn.gadu_client.sendToConf(int(nr), str(text), str(msg), recs_tmp) else: raise telepathy.NotImplemented("Unhandled message type") self.Sent(int(time.time()), message_type, text)
def _get_ft_channel(self, props, session=None): _, surpress_handler, handle = self._get_type_requested_handle(props) if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT: raise telepathy.NotImplemented('Only contacts are allowed') contact = handle.contact if contact.presence == papyon.Presence.OFFLINE: raise telepathy.NotAvailable('Contact not available') logger.debug('New file transfer channel') path = "FileTransferChannel%d" % self.__ft_channel_id self.__ft_channel_id += 1 return ButterflyFileTransferChannel(self._conn, self, session, handle, props, object_path=path)
def _get_text_channel(self, props, conversation=None): _, surpress_handler, handle = self._get_type_requested_handle(props) logger.debug('New text channel') path = "TextChannel%d" % self.__text_channel_id self.__text_channel_id += 1 # Normal 1-1 chat if handle.get_type() == telepathy.HANDLE_TYPE_CONTACT: channel = ButterflyImChannel(self._conn, self, conversation, props, object_path=path) # MUC which has been upgraded from a 1-1 chat elif handle.get_type() == telepathy.HANDLE_TYPE_NONE \ and telepathy.CHANNEL_INTERFACE_CONFERENCE + '.InitialChannels' in props: channel = ButterflyConferenceChannel(self._conn, self, conversation, props, object_path=path) # MUC invite elif handle.get_type() == telepathy.HANDLE_TYPE_NONE: channel = ButterflyMucChannel(self._conn, self, conversation, props, object_path=path) else: raise telepathy.NotImplemented('Only contacts are allowed') return channel