Merge remote-tracking branch 'upstream/yowsup-2' into yowsup-2
This commit is contained in:
commit
32f6e03b94
6
group.py
6
group.py
|
@ -78,6 +78,12 @@ class Group():
|
|||
self._updateParticipant(number, flags, protocol_pb2.STATUS_NONE)
|
||||
del self.participants[number]
|
||||
|
||||
def leaveRoom(self):
|
||||
for number in self.participants:
|
||||
nick = self.participants[number]
|
||||
flags = protocol_pb2.PARTICIPANT_FLAG_ROOM_NOT_FOUND
|
||||
self._updateParticipant(number, flags, protocol_pb2.STATUS_NONE)
|
||||
|
||||
def changeNick(self, number, new_nick):
|
||||
if self.participants[number] == new_nick:
|
||||
return
|
||||
|
|
40
session.py
40
session.py
|
@ -248,16 +248,13 @@ class Session(YowsupApp):
|
|||
type, participant, offline, items]))
|
||||
)
|
||||
try:
|
||||
buddy = self.buddies[_from.split('@')[0]]
|
||||
#self.backend.handleBuddyChanged(self.user, buddy.number.number,
|
||||
# buddy.nick, buddy.groups, protocol_pb2.STATUS_ONLINE)
|
||||
self.backend.handleMessageAck(self.user, buddy.number, self.msgIDs[_id].xmppId)
|
||||
self.msgIDs[_id].cnt = self.msgIDs[_id].cnt +1
|
||||
if self.msgIDs[_id].cnt == 2:
|
||||
del self.msgIDs[_id]
|
||||
|
||||
number = _from.split('@')[0]
|
||||
self.backend.handleMessageAck(self.user, number, self.msgIDs[_id].xmppId)
|
||||
self.msgIDs[_id].cnt = self.msgIDs[_id].cnt + 1
|
||||
if self.msgIDs[_id].cnt == 2:
|
||||
del self.msgIDs[_id]
|
||||
except KeyError:
|
||||
pass
|
||||
self.logger.error("Message %s not found. Unable to send ack", _id)
|
||||
|
||||
# Called by superclass
|
||||
def onAck(self, _id, _class, _from, timestamp):
|
||||
|
@ -282,7 +279,7 @@ class Session(YowsupApp):
|
|||
if participant is not None: # Group message
|
||||
partname = participant.split('@')[0]
|
||||
if notify is None:
|
||||
notify = "";
|
||||
notify = ""
|
||||
self.sendGroupMessageToXMPP(buddy, partname, messageContent,
|
||||
timestamp, notify)
|
||||
else:
|
||||
|
@ -482,9 +479,9 @@ class Session(YowsupApp):
|
|||
self.logger.info("Stopped typing: %s to %s", self.legacyName, buddy)
|
||||
self.sendTyping(buddy, False)
|
||||
|
||||
def sendMessageToWA(self, sender, message, ID):
|
||||
self.logger.info("Message sent from %s to %s: %s",
|
||||
self.legacyName, sender, message)
|
||||
def sendMessageToWA(self, sender, message, ID, xhtml=""):
|
||||
self.logger.info("Message sent from %s to %s: %s (xhtml=%s)",
|
||||
self.legacyName, sender, message, xhtml)
|
||||
|
||||
message = message.encode("utf-8")
|
||||
# FIXME: Fragile, should pass this in to onDlerror
|
||||
|
@ -522,7 +519,7 @@ class Session(YowsupApp):
|
|||
self.logger.debug("Group Message from %s to %s Groups: %s",
|
||||
group.nick , group , self.groups)
|
||||
self.backend.handleMessage(
|
||||
self.user, room, message.decode('utf-8'), group.nick
|
||||
self.user, room, message.decode('utf-8'), group.nick, xhtml=xhtml
|
||||
)
|
||||
except KeyError:
|
||||
self.logger.error('Group not found: %s', room)
|
||||
|
@ -591,20 +588,7 @@ class Session(YowsupApp):
|
|||
self.leaveGroup(room)
|
||||
# Delete Room on spectrum side
|
||||
group = self.groups[room]
|
||||
for jid in group.participants:
|
||||
buddy = jid.split("@")[0]
|
||||
try:
|
||||
nick = self.buddies[buddy].nick
|
||||
except KeyError:
|
||||
nick = buddy
|
||||
if nick == "":
|
||||
nick = buddy
|
||||
if buddy == self.legacyName:
|
||||
nick = group.nick
|
||||
flags = protocol_pb2.PARTICIPANT_FLAG_ROOM_NOT_FOUND
|
||||
self.backend.handleParticipantChanged(
|
||||
self.user, nick, self._shortenGroupId(room), flags,
|
||||
protocol_pb2.STATUS_NONE, buddy)
|
||||
group.leaveRoom()
|
||||
del self.groups[room]
|
||||
|
||||
def _requestLastSeen(self, buddy):
|
||||
|
|
|
@ -36,7 +36,7 @@ class WhatsAppBackend(SpectrumBackend):
|
|||
self.sessions = { }
|
||||
self.spectrum_jid = spectrum_jid
|
||||
# Used to prevent duplicate messages
|
||||
self.lastMessage = {}
|
||||
self.lastMsgId = {}
|
||||
|
||||
self.logger.debug("Backend started")
|
||||
|
||||
|
@ -46,9 +46,6 @@ class WhatsAppBackend(SpectrumBackend):
|
|||
if user not in self.sessions:
|
||||
self.sessions[user] = Session(self, user, legacyName, extra)
|
||||
|
||||
if user not in self.lastMessage:
|
||||
self.lastMessage[user] = {}
|
||||
|
||||
self.sessions[user].login(password)
|
||||
|
||||
def handleLogoutRequest(self, user, legacyName):
|
||||
|
@ -57,20 +54,17 @@ class WhatsAppBackend(SpectrumBackend):
|
|||
self.sessions[user].logout()
|
||||
del self.sessions[user]
|
||||
|
||||
def handleMessageSendRequest(self, user, buddy, message, xhtml = "", ID = 0):
|
||||
self.logger.debug("handleMessageSendRequest(user=%s, buddy=%s, message=%s, xhtml = %s)", user, buddy, message, xhtml)
|
||||
def handleMessageSendRequest(self, user, buddy, message, xhtml="", ID=""):
|
||||
self.logger.debug("handleMessageSendRequest(user=%s, buddy=%s, message=%s, xhtml=%s, ID=%s)", user, buddy, message, xhtml, ID)
|
||||
# For some reason spectrum occasionally sends to identical messages to
|
||||
# a buddy, one to the bare jid and one to /bot. This causes duplicate
|
||||
# messages. Since it is unlikely a user wants to send the same message
|
||||
# twice, we should just ignore the second message
|
||||
#
|
||||
# TODO Proper fix, this work around drops all duplicate messages even
|
||||
# intentional ones.
|
||||
# IDEA there is an ID field in ConvMessage. If it is extracted it will work
|
||||
usersMessage = self.lastMessage[user]
|
||||
if buddy not in usersMessage or usersMessage[buddy] != message:
|
||||
self.sessions[user].sendMessageToWA(buddy, message, ID)
|
||||
usersMessage[buddy] = message
|
||||
# a buddy, one to the bare jid and one to the /bot resource. This
|
||||
# causes duplicate messages. Thus we should not send consecutive
|
||||
# messages with the same id
|
||||
if ID == '':
|
||||
self.sessions[user].sendMessageToWA(buddy, message, ID, xhtml)
|
||||
elif user not in self.lastMsgId or self.lastMsgId[user] != ID:
|
||||
self.sessions[user].sendMessageToWA(buddy, message, ID, xhtml)
|
||||
self.lastMsgId[user] = ID
|
||||
|
||||
def handleJoinRoomRequest(self, user, room, nickname, pasword):
|
||||
self.logger.debug("handleJoinRoomRequest(user=%s, room=%s, nickname=%s)", user, room, nickname)
|
||||
|
|
Loading…
Reference in a new issue