Update group subject when notification received

This commit is contained in:
moyamo 2016-01-07 12:58:03 +02:00
parent f57b276665
commit 9c32dfbb38
2 changed files with 39 additions and 3 deletions

View file

@ -441,6 +441,24 @@ class Session(YowsupApp):
self.groups[room].addParticipants(group.getParticipants(), self.buddies, self.legacyName) self.groups[room].addParticipants(group.getParticipants(), self.buddies, self.legacyName)
self.groups[room].sendParticipantsToSpectrum(self.legacyName) self.groups[room].sendParticipantsToSpectrum(self.legacyName)
# Called by superclass
def onSubjectChanged(self, room, subject, subjectOwner, timestamp):
self.logger.debug(
"onSubjectChange(rrom=%s, subject=%s, subjectOwner=%s, timestamp=%s)",
room, subject, subjectOwner, timestamp)
try:
group = self.groups[room]
except KeyError:
self.logger.error("Subject of non-existant group (%s) changed", group)
else:
group.subject = subject
group.subjectOwner = subjectOwner
if not group.joined:
# We have not joined group so we should not send subject
return
self.backend.handleSubject(self.user, room, subject, subjectOwner)
self.backend.handleRoomNicknameChanged(self.user, room, subject)
# Called by superclass # Called by superclass
def onParticipantsRemovedFromGroup(self, room, participants): def onParticipantsRemovedFromGroup(self, room, participants):
self.logger.debug("Participants removed from group: %s, %s", self.logger.debug("Participants removed from group: %s, %s",

View file

@ -546,6 +546,17 @@ class YowsupApp(object):
""" """
pass pass
def onSubjectChanged(self, group, subject, subjectOwner, timestamp):
"""Called when someone changes the grousp subject
Args:
- group: (str) id of the group (e.g. 27831788123-144024456)
- subject: (str) the new subject
- subjectOwner: (str) the number of the person who changed the subject
- timestamp: (str) time the subject was changed
"""
pass
def onContactStatusChanged(self, number, status): def onContactStatusChanged(self, number, status):
"""Called when a contacts changes their status """Called when a contacts changes their status
@ -694,6 +705,13 @@ class YowsupAppLayer(YowInterfaceLayer):
entity.getGroupId().split('@')[0], entity.getGroupId().split('@')[0],
entity.getParticipants().keys() entity.getParticipants().keys()
) )
elif isinstance(entity, SubjectGroupsNotificationProtocolEntity):
self.caller.onSubjectChanged(
entity.getGroupId().split('@')[0],
entity.getSubject(),
entity.getSubjectOwner(full=False),
entity.getSubjectTimestamp()
)
elif isinstance(entity, StatusNotificationProtocolEntity): elif isinstance(entity, StatusNotificationProtocolEntity):
self.caller.onContactStatusChanged( self.caller.onContactStatusChanged(
entity._from.split('@')[0], entity._from.split('@')[0],