Minor bug fixes

This commit is contained in:
moyamo 2015-12-01 23:21:38 +02:00
parent 107354af81
commit 8385888e97
5 changed files with 23 additions and 17 deletions

View file

@ -437,8 +437,8 @@ class SpectrumBackend:
self.handleConvMessageAckPayload(wrapper.payload) self.handleConvMessageAckPayload(wrapper.payload)
elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_RAW_XML: elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_RAW_XML:
self.handleRawXmlRequest(wrapper.payload) self.handleRawXmlRequest(wrapper.payload)
elif wrapper.type == Protocol_pb2.WrapperMessage.TYPE_BUDDIES: elif wrapper.type == protocol_pb2.WrapperMessage.TYPE_BUDDIES:
self.handleBuddiesPayload() self.handleBuddiesPayload(wrapper.payload)
def send(self, data): def send(self, data):
header = struct.pack('!I',len(data)) header = struct.pack('!I',len(data))

View file

@ -50,10 +50,10 @@ class Buddy():
class BuddyList(dict): class BuddyList(dict):
def __init__(self, owner, backend, user, sendSync): def __init__(self, owner, backend, user, session):
self.owner = owner self.owner = owner
self.backend = backend self.backend = backend
self.sendSync = sendSync self.session = session
self.user = user self.user = user
self.logger = logging.getLogger(self.__class__.__name__) self.logger = logging.getLogger(self.__class__.__name__)
self.synced = False self.synced = False
@ -76,7 +76,7 @@ class BuddyList(dict):
contacts = self.keys() contacts = self.keys()
if self.synced == False: if self.synced == False:
self.sendSync(contacts, delta = False, interactive = True) self.session.sendSync(contacts, delta = False, interactive = True)
self.synced = True self.synced = True
# add = set(new) - set(old) # add = set(new) - set(old)
@ -91,8 +91,9 @@ class BuddyList(dict):
# self.backend.handleBuddyRemoved(self.user, number) # self.backend.handleBuddyRemoved(self.user, number)
# self.unsubscribePresence(number) # self.unsubscribePresence(number)
# #
for buddy in contacts: for number in contacts:
# self.subscribePresence(number) self.session.subscribePresence(number)
buddy = self[number]
self.backend.handleBuddyChanged(self.user, number, buddy.nick, self.backend.handleBuddyChanged(self.user, number, buddy.nick,
buddy.groups, protocol_pb2.STATUS_NONE, buddy.groups, protocol_pb2.STATUS_NONE,
iconHash = buddy.image_hash if buddy.image_hash is not None else "") iconHash = buddy.image_hash if buddy.image_hash is not None else "")
@ -103,8 +104,10 @@ class BuddyList(dict):
buddy = self[number] buddy = self[number]
buddy.update(nick, groups, image_hash) buddy.update(nick, groups, image_hash)
else: 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) buddy = Buddy(self.owner, number, nick, "", groups, image_hash)
self[number] = buddy
self.logger.debug("Roster add: %s", buddy) self.logger.debug("Roster add: %s", buddy)
self.backend.handleBuddyChanged(self.user, number, buddy.nick, self.backend.handleBuddyChanged(self.user, number, buddy.nick,
@ -116,11 +119,11 @@ class BuddyList(dict):
def remove(self, number): def remove(self, number):
try: try:
buddy = self[number] buddy = self[number]
buddy.delete() del self[number]
self.backend.handleBuddyChanged(self.user, number, "", [], self.backend.handleBuddyChanged(self.user, number, "", [],
protocol_pb2.STATUS_NONE) protocol_pb2.STATUS_NONE)
self.backend.handleBuddyRemoved(self.user, number) self.backend.handleBuddyRemoved(self.user, number)
# self.unsubscribePresence(number) self.session.unsubscribePresence(number)
# TODO Sync remove # TODO Sync remove
return buddy return buddy
except KeyError: except KeyError:

View file

@ -87,7 +87,7 @@ class Session(YowsupApp):
self.lastMsgId = None self.lastMsgId = None
self.synced = False 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.bot = Bot(self)
self.imgMsgId = None self.imgMsgId = None
@ -271,7 +271,7 @@ class Session(YowsupApp):
buddy = self.buddies[_from.split('@')[0]] buddy = self.buddies[_from.split('@')[0]]
#self.backend.handleBuddyChanged(self.user, buddy.number.number, #self.backend.handleBuddyChanged(self.user, buddy.number.number,
# buddy.nick, buddy.groups, protocol_pb2.STATUS_ONLINE) # 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 self.msgIDs[_id].cnt = self.msgIDs[_id].cnt +1
if self.msgIDs[_id].cnt == 2: if self.msgIDs[_id].cnt == 2:
del self.msgIDs[_id] del self.msgIDs[_id]
@ -509,12 +509,12 @@ class Session(YowsupApp):
def onPresenceAvailable(self, buddy, statusmsg): def onPresenceAvailable(self, buddy, statusmsg):
self.logger.info("Is available: %s", buddy) 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) buddy.nick, buddy.groups, protocol_pb2.STATUS_ONLINE, statusmsg, buddy.image_hash)
def onPresenceUnavailable(self, buddy, statusmsg): def onPresenceUnavailable(self, buddy, statusmsg):
self.logger.info("Is unavailable: %s", buddy) 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) buddy.nick, buddy.groups, protocol_pb2.STATUS_AWAY, statusmsg, buddy.image_hash)
# spectrum RequestMethods # spectrum RequestMethods
@ -756,8 +756,8 @@ class Session(YowsupApp):
self.backend.handleMessage(self.user, msg[0], msg[1], "", "", msg[2]) self.backend.handleMessage(self.user, msg[0], msg[1], "", "", msg[2])
# Called when user logs in to initialize the roster # Called when user logs in to initialize the roster
def loadBuddies(self, buddy): def loadBuddies(self, buddies):
self.buddies.load(buddy) self.buddies.load(buddies)
# also for adding a new buddy # also for adding a new buddy
def updateBuddy(self, buddy, nick, groups, image_hash = None): def updateBuddy(self, buddy, nick, groups, image_hash = None):
@ -794,7 +794,7 @@ class Session(YowsupApp):
name=os.path.basename(self.imgPath) name=os.path.basename(self.imgPath)
self.logger.info("Buddy %s",self.imgBuddy) self.logger.info("Buddy %s",self.imgBuddy)
self.image_send(self.imgBuddy, self.imgPath) self.image_send(self.imgBuddy, self.imgPath)
#self.logger.info("Sending picture %s of size %s with name %s",self.imgPath, statinfo.st_size, name) #self.logger.info("Sending picture %s of size %s with name %s",self.imgPath, statinfo.st_size, name)
#mtype = "image" #mtype = "image"

View file

@ -80,6 +80,8 @@ io = IOChannel(args.host, args.port, handleTransportData, connectionClosed)
plugin = WhatsAppBackend(io, db, args.j) plugin = WhatsAppBackend(io, db, args.j)
plugin.handleBackendConfig('features', 'send_buddies_on_login', 1)
while True: while True:
try: try:
asyncore.loop(timeout=1.0, count=10, use_poll = True) asyncore.loop(timeout=1.0, count=10, use_poll = True)

View file

@ -90,6 +90,7 @@ class WhatsAppBackend(SpectrumBackend):
def handleBuddies(self, buddies): def handleBuddies(self, buddies):
"""Called when user logs in. Used to initialize roster.""" """Called when user logs in. Used to initialize roster."""
self.logger.debug("handleBuddies(buddies=%s)", buddies) self.logger.debug("handleBuddies(buddies=%s)", buddies)
buddies = [b for b in buddies.buddy]
user = buddies[0].userName user = buddies[0].userName
self.sessions[user].loadBuddies(buddies) self.sessions[user].loadBuddies(buddies)