Minor bug fixes
This commit is contained in:
parent
107354af81
commit
8385888e97
|
@ -437,8 +437,8 @@ class SpectrumBackend:
|
|||
self.handleConvMessageAckPayload(wrapper.payload)
|
||||
elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_RAW_XML:
|
||||
self.handleRawXmlRequest(wrapper.payload)
|
||||
elif wrapper.type == Protocol_pb2.WrapperMessage.TYPE_BUDDIES:
|
||||
self.handleBuddiesPayload()
|
||||
elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDIES:
|
||||
self.handleBuddiesPayload(wrapper.payload)
|
||||
|
||||
def send(self, data):
|
||||
header = struct.pack('!I',len(data))
|
||||
|
|
19
buddy.py
19
buddy.py
|
@ -50,10 +50,10 @@ class Buddy():
|
|||
|
||||
class BuddyList(dict):
|
||||
|
||||
def __init__(self, owner, backend, user, sendSync):
|
||||
def __init__(self, owner, backend, user, session):
|
||||
self.owner = owner
|
||||
self.backend = backend
|
||||
self.sendSync = sendSync
|
||||
self.session = session
|
||||
self.user = user
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
self.synced = False
|
||||
|
@ -76,7 +76,7 @@ class BuddyList(dict):
|
|||
contacts = self.keys()
|
||||
|
||||
if self.synced == False:
|
||||
self.sendSync(contacts, delta = False, interactive = True)
|
||||
self.session.sendSync(contacts, delta = False, interactive = True)
|
||||
self.synced = True
|
||||
|
||||
# add = set(new) - set(old)
|
||||
|
@ -91,8 +91,9 @@ class BuddyList(dict):
|
|||
# self.backend.handleBuddyRemoved(self.user, number)
|
||||
# self.unsubscribePresence(number)
|
||||
#
|
||||
for buddy in contacts:
|
||||
# self.subscribePresence(number)
|
||||
for number in contacts:
|
||||
self.session.subscribePresence(number)
|
||||
buddy = self[number]
|
||||
self.backend.handleBuddyChanged(self.user, number, buddy.nick,
|
||||
buddy.groups, protocol_pb2.STATUS_NONE,
|
||||
iconHash = buddy.image_hash if buddy.image_hash is not None else "")
|
||||
|
@ -103,8 +104,10 @@ class BuddyList(dict):
|
|||
buddy = self[number]
|
||||
buddy.update(nick, groups, image_hash)
|
||||
else:
|
||||
self.sendSync([number], delta = True, interactive = True)
|
||||
self.session.sendSync([number], delta = True, interactive = True)
|
||||
self.session.subscribePresence(number)
|
||||
buddy = Buddy(self.owner, number, nick, "", groups, image_hash)
|
||||
self[number] = buddy
|
||||
self.logger.debug("Roster add: %s", buddy)
|
||||
|
||||
self.backend.handleBuddyChanged(self.user, number, buddy.nick,
|
||||
|
@ -116,11 +119,11 @@ class BuddyList(dict):
|
|||
def remove(self, number):
|
||||
try:
|
||||
buddy = self[number]
|
||||
buddy.delete()
|
||||
del self[number]
|
||||
self.backend.handleBuddyChanged(self.user, number, "", [],
|
||||
protocol_pb2.STATUS_NONE)
|
||||
self.backend.handleBuddyRemoved(self.user, number)
|
||||
# self.unsubscribePresence(number)
|
||||
self.session.unsubscribePresence(number)
|
||||
# TODO Sync remove
|
||||
return buddy
|
||||
except KeyError:
|
||||
|
|
12
session.py
12
session.py
|
@ -87,7 +87,7 @@ class Session(YowsupApp):
|
|||
self.lastMsgId = None
|
||||
self.synced = False
|
||||
|
||||
self.buddies = BuddyList(self.legacyName, self.backend, self.user, self.sendSync)
|
||||
self.buddies = BuddyList(self.legacyName, self.backend, self.user, self)
|
||||
self.bot = Bot(self)
|
||||
|
||||
self.imgMsgId = None
|
||||
|
@ -271,7 +271,7 @@ class Session(YowsupApp):
|
|||
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.number, self.msgIDs[_id].xmppId)
|
||||
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]
|
||||
|
@ -509,12 +509,12 @@ class Session(YowsupApp):
|
|||
|
||||
def onPresenceAvailable(self, buddy, statusmsg):
|
||||
self.logger.info("Is available: %s", buddy)
|
||||
self.backend.handleBuddyChanged(self.user, buddy.number.number,
|
||||
self.backend.handleBuddyChanged(self.user, buddy.number,
|
||||
buddy.nick, buddy.groups, protocol_pb2.STATUS_ONLINE, statusmsg, buddy.image_hash)
|
||||
|
||||
def onPresenceUnavailable(self, buddy, statusmsg):
|
||||
self.logger.info("Is unavailable: %s", buddy)
|
||||
self.backend.handleBuddyChanged(self.user, buddy.number.number,
|
||||
self.backend.handleBuddyChanged(self.user, buddy.number,
|
||||
buddy.nick, buddy.groups, protocol_pb2.STATUS_AWAY, statusmsg, buddy.image_hash)
|
||||
|
||||
# spectrum RequestMethods
|
||||
|
@ -756,8 +756,8 @@ class Session(YowsupApp):
|
|||
self.backend.handleMessage(self.user, msg[0], msg[1], "", "", msg[2])
|
||||
|
||||
# Called when user logs in to initialize the roster
|
||||
def loadBuddies(self, buddy):
|
||||
self.buddies.load(buddy)
|
||||
def loadBuddies(self, buddies):
|
||||
self.buddies.load(buddies)
|
||||
|
||||
# also for adding a new buddy
|
||||
def updateBuddy(self, buddy, nick, groups, image_hash = None):
|
||||
|
|
|
@ -80,6 +80,8 @@ io = IOChannel(args.host, args.port, handleTransportData, connectionClosed)
|
|||
|
||||
plugin = WhatsAppBackend(io, db, args.j)
|
||||
|
||||
plugin.handleBackendConfig('features', 'send_buddies_on_login', 1)
|
||||
|
||||
while True:
|
||||
try:
|
||||
asyncore.loop(timeout=1.0, count=10, use_poll = True)
|
||||
|
|
|
@ -90,6 +90,7 @@ class WhatsAppBackend(SpectrumBackend):
|
|||
def handleBuddies(self, buddies):
|
||||
"""Called when user logs in. Used to initialize roster."""
|
||||
self.logger.debug("handleBuddies(buddies=%s)", buddies)
|
||||
buddies = [b for b in buddies.buddy]
|
||||
user = buddies[0].userName
|
||||
self.sessions[user].loadBuddies(buddies)
|
||||
|
||||
|
|
Loading…
Reference in a new issue