37
37
telepathy.server.ChannelTypeText,
38
38
telepathy.server.ChannelInterfaceGroup,
39
39
telepathy.server.ChannelInterfaceChatState,
40
pymsn.event.ConversationEventInterface):
40
papyon.event.ConversationEventInterface):
42
def __init__(self, connection, conversation, chan_manager):
42
def __init__(self, conn, manager, conversation, props):
44
44
self._conversation = conversation
45
self._conn_ref = weakref.ref(connection)
46
self._chan_manager_ref = weakref.ref(chan_manager)
45
self._conn_ref = weakref.ref(conn)
48
telepathy.server.ChannelTypeText.__init__(self, connection, None)
47
telepathy.server.ChannelTypeText.__init__(self, conn, manager, props)
49
48
telepathy.server.ChannelInterfaceGroup.__init__(self)
50
49
telepathy.server.ChannelInterfaceChatState.__init__(self)
51
pymsn.event.ConversationEventInterface.__init__(self, self._conversation)
50
papyon.event.ConversationEventInterface.__init__(self, self._conversation)
53
52
self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD, 0)
54
53
self.__add_initial_participants()
62
61
def Send(self, message_type, text):
63
62
if message_type == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
64
self._conversation.send_text_message(pymsn.ConversationMessage(text))
63
self._conversation.send_text_message(papyon.ConversationMessage(text))
65
64
elif message_type == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_ACTION and \
67
66
self._conversation.send_nudge()
80
78
def GetSelfHandle(self):
81
79
return self._conn.GetSelfHandle()
83
# pymsn.event.ConversationEventInterface
81
# papyon.event.ConversationEventInterface
84
82
def on_conversation_user_joined(self, contact):
85
83
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
86
84
contact.account, contact.network_id)
88
86
self.MembersChanged('', [handle], [], [], [],
89
87
handle, telepathy.CHANNEL_GROUP_CHANGE_REASON_INVITED)
91
# pymsn.event.ConversationEventInterface
89
# papyon.event.ConversationEventInterface
92
90
def on_conversation_user_left(self, contact):
93
91
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
94
92
contact.account, contact.network_id)
99
97
self.MembersChanged('', [], [handle], [], [],
100
98
handle, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
102
# pymsn.event.ConversationEventInterface
100
# papyon.event.ConversationEventInterface
103
101
def on_conversation_user_typing(self, contact):
104
102
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
105
103
contact.account, contact.network_id)
106
104
logger.info("User %r is typing" % handle)
107
105
self.ChatStateChanged(handle, telepathy.CHANNEL_CHAT_STATE_COMPOSING)
109
# pymsn.event.ConversationEventInterface
107
# papyon.event.ConversationEventInterface
110
108
def on_conversation_message_received(self, sender, message):
111
109
id = self._recv_id
112
110
timestamp = int(time.time())
118
116
self.Received(id, timestamp, handle, type, 0, message)
119
117
self._recv_id += 1
121
# pymsn.event.ConversationEventInterface
119
# papyon.event.ConversationEventInterface
122
120
def on_conversation_nudge_received(self, sender):
123
121
id = self._recv_id
124
122
timestamp = int(time.time())
125
123
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
126
124
sender.account, sender.network_id)
127
125
type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_ACTION
128
text = unicode(_("sends you a nudge"), "utf-8")
126
text = unicode("sends you a nudge", "utf-8")
129
127
logger.info("User %r sent a nudge" % handle)
130
128
self.Received(id, timestamp, handle, type, 0, text)
131
129
self._recv_id += 1