stv0g / transwhat

A gateway between the XMPP and the WhatsApp IM networks
https://dev.0l.de/wiki/projects/transwhat/
GNU General Public License v3.0
122 stars 25 forks source link

Sending queued offline group messages #82

Closed SmartHoneybee closed 7 years ago

SmartHoneybee commented 7 years ago

Hello,

group messages written while the user is offline are not delivered on login. Instead they are only mentioned in log where they trigger a warning, e.g.:

INFO Session: Auth success: danny.gray12@example.com
INFO Session: Message received from 3824608301-4257 to 6639944257: Message content (at ts=...)
WARNING Session: Group is not in group list

I think the issue is that _updateGroups in transWhat/session.py calls self.backend.handleMessage before calling self.joinRoom.

Suggested fix is to rewrite _updateGroups:

def _updateGroups(self, response, _):
    self.logger.debug('Received groups list %s' % response)
    groups = response.getGroups()
    for group in groups:
        room = group.getId()
        # ensure self.groups[room] exists
        if room not in self.groups:
            owner = group.getOwner().split('@')[0]
            subjectOwner = group.getSubjectOwner().split('@')[0]
            subject = utils.softToUni(group.getSubject())
            self.groups[room] = Group(room, owner, subject, subjectOwner,
                                      self.backend, self.user)
        # add/update room participants
        self.groups[room].addParticipants(group.getParticipants().keys(),
                                          self.buddies, self.legacyName)
    self.gotGroupList = True
    # join rooms
    while self.joinRoomQueue:
        self.joinRoom(*self.joinRoomQueue.pop(0))
    # deliver queued offline messages
    for room in self.groupOfflineQueue:
        while self.groupOfflineQueue[room]:
            msg = self.groupOfflineQueue[room].pop(0)
            self.backend.handleMessage(self.user, room, msg[1], msg[0], "",
                                       msg[2])
            self.logger.debug("Send queued group message to: %s %s %s" %
                              (msg[0], msg[1], msg[2]))

    # pass update to backend
    self.updateRoomList()

Thanks for providing transWhat.

stv0g commented 7 years ago

Hi Bee,

Can you provivde a pull request for that change?

I don’t have a working environment to test your contribution.

Steffen

From: Bee notifications@github.com Reply-To: stv0g/transwhat reply@reply.github.com Date: Sunday, 2. July 2017 at 13:46 To: stv0g/transwhat transwhat@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [stv0g/transwhat] Sending queued offline group messages (#82)

Hello,

group messages written while the user is offline are not delivered on login. Instead they are only mentioned in log where they trigger a warning, e.g.: INFO Session: Auth success: danny.gray12@example.com INFO Session: Message received from 3824608301-4257 to 6639944257: Message content (at ts=...) WARNING Session: Group is not in group list I think the issue is that _updateGroups in transWhat/session.py calls self.backend.handleMessage before calling self.joinRoom.

Suggested fix is to rewrite _updateGroups:

def updateGroups(self, response, ):     self.logger.debug('Received groups list %s' % response)     groups = response.getGroups()     for group in groups:         room = group.getId()         # ensure self.groups[room] exists         if room not in self.groups:             owner = group.getOwner().split('@')[0]             subjectOwner = group.getSubjectOwner().split('@')[0]             subject = utils.softToUni(group.getSubject())             self.groups[room] = Group(room, owner, subject, subjectOwner,                                       self.backend, self.user)         # add/update room participants         self.groups[room].addParticipants(group.getParticipants().keys(),                                           self.buddies, self.legacyName)     self.gotGroupList = True     # join rooms     while self.joinRoomQueue:         self.joinRoom(*self.joinRoomQueue.pop(0))     # deliver queued offline messages     for room in self.groupOfflineQueue:         while self.groupOfflineQueue[room]:             msg = self.groupOfflineQueue[room].pop(0)             self.backend.handleMessage(self.user, room, msg[1], msg[0], "",                                        msg[2])             self.logger.debug("Send queued group message to: %s %s %s" %                               (msg[0], msg[1], msg[2]))

    # pass update to backend     self.updateRoomList() Thanks for providing transWhat.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

SmartHoneybee commented 7 years ago

Thank you. :+1: