Merge pull request #49 from dazzzl/yowsup2-port

Add support for participant VCards
This commit is contained in:
Steffen Vogel 2016-02-11 12:46:27 +01:00
commit 9eae269918
5 changed files with 176 additions and 214 deletions

View file

@ -154,13 +154,14 @@ class SpectrumBackend:
self.send(message);
def handleParticipantChanged(self, user, nickname, room, flags, status, statusMessage = "", newname = ""):
def handleParticipantChanged(self, user, nickname, room, flags, status, statusMessage = "", newname = "", iconHash = ""):
d = protocol_pb2.Participant()
d.userName = user
d.nickname = nickname
d.room = room
d.flag = flags
d.newname = newname
d.iconHash = iconHash
d.status = status
d.statusMessage = statusMessage

View file

@ -110,6 +110,7 @@ message Participant {
required StatusType status = 5;
optional string statusMessage = 6;
optional string newname = 7;
optional string iconHash = 8;
}
message VCard {

File diff suppressed because one or more lines are too long

View file

@ -172,15 +172,29 @@ class BuddyList(dict):
return None
def requestVCard(self, buddy, ID=None):
if buddy == self.user or buddy == self.user.split('@')[0]:
buddy = self.session.legacyName
if "/" in buddy:
room, nick = buddy.split("/")
group = self.session.groups[room]
buddynr = None
for othernumber, othernick in group.participants.iteritems():
if othernick == nick:
buddynr = othernumber
break
if buddynr is None:
return
else:
buddynr = buddy
if buddynr == self.user or buddynr == self.user.split('@')[0]:
buddynr = self.session.legacyName
# Get profile picture
self.logger.debug('Requesting profile picture of %s', buddy)
self.logger.debug('Requesting profile picture of %s', buddynr)
response = deferred.Deferred()
# Error probably means image doesn't exist
error = deferred.Deferred()
self.session.requestProfilePicture(buddy, onSuccess=response.run,
self.session.requestProfilePicture(buddynr, onSuccess=response.run,
onFailure=error.run)
response = response.arg(0)
@ -196,9 +210,9 @@ class BuddyList(dict):
error.when(self.backend.handleVCard, self.user, ID, buddy, "", "", "")
# Send image hash
if not buddy == self.session.legacyName:
if not buddynr == self.session.legacyName:
try:
obuddy = self[buddy]
obuddy = self[buddynr]
nick = obuddy.nick
groups = obuddy.groups
except KeyError:
@ -206,10 +220,10 @@ class BuddyList(dict):
groups = []
image_hash = pictureData.then(utils.sha1hash)
call(self.logger.debug, 'Image hash is %s', image_hash)
call(self.update, buddy, nick, groups, image_hash)
call(self.update, buddynr, nick, groups, image_hash)
# No image
error.when(self.logger.debug, 'No image')
error.when(self.update, buddy, nick, groups, '')
error.when(self.update, buddynr, nick, groups, '')
def refresh(self, number):
self.session.unsubscribePresence(number)

View file

@ -68,6 +68,10 @@ class Group():
if number == yourNumber:
flags = flags | protocol_pb2.PARTICIPANT_FLAG_ME
try:
self._updateParticipant(number, flags, protocol_pb2.STATUS_ONLINE,
self.backend.sessions[self.user].buddies[number].image_hash)
except KeyError:
self._updateParticipant(number, flags, protocol_pb2.STATUS_ONLINE)
def removeParticipants(self, participants):
@ -94,10 +98,10 @@ class Group():
self._updateParticipant(number, flags, protocol_pb2.STATUS_ONLINE, new_nick)
self.participants[number] = new_nick
def _updateParticipant(self, number, flags, status, newNick = ""):
def _updateParticipant(self, number, flags, status, imageHash = "", newNick = ""):
nick = self.participants[number]
# Notice the status message is the buddy's number
if self.joined:
self.backend.handleParticipantChanged(
self.user, nick, self.id, flags,
status, number, newname = newNick)
status, number, newname = newNick, iconHash = imageHash)