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