carderne/signal-export

Messages timestamped incorrectly in some cases

codingWithJimmy opened this issue · 4 comments

Desktop (please complete the following information):

  • WSL 2/Docker

Describe the bug
When looking at some messages received, it seems some of the messages, depending on when they are written, are timestamped out of order. For example, I am seeing in Signal the sent timestamp of a message is 11:53PM however when I look at the info of the message, the received timestamp is actually 2 minutes ahead of that so 11:51PM. This could have something to do with messages being brought into Signal Desktop after the fact and the app not reading something properly from the server.

image

When looking at the JSON of the event, the serverTimestamp of the message looks to be closer than the timestamp posted in Signal Desktop as closer to when the message was actually sent.

{"timestamp":1714881219541,"attachments":[],"id":"xxxxxx","conversationId":"xxxxxx","readStatus":0,"received_at":1712423387852,"received_at_ms":1714881862634,"seenStatus":2,"sent_at":1714881219541,"serverGuid":"xxxxxx","serverTimestamp":1714881063571,"source":"xxxxxxxx","sourceDevice":1,"sourceServiceId":"xxxxxx","type":"incoming","unidentifiedDeliveryReceived":true,"schemaVersion":11,"body":"Which profile should I watch under? ","bodyRanges":[],"contact":[],"decrypted_at":1714881863161,"errors":[],"flags":0,"hasAttachments":0,"isViewOnce":false,"mentionsMe":false,"preview":[],"requiredProtocolVersion":0,"supportedVersionAtReceive":7}

To reproduce

  1. Close Signal Desktop and send some messages via mobile or another linked desktop app. The behavior is inconsistent as there are messages around the example above that look to be correct.
  2. Re-open Signal Desktop and look at messages sent and received timestamps and see if any messages are being timestamped out of order.
  3. Look at the info for any messages that are and look at the sent and received timestamps to confirm whether they are being timestamped improperly.

I am going to try my hand at comparing the sent_at and serverTimestamp values and have the timestamp use whichever is less since that is closer to the correct timestamp of the message but I wanted to bring it to your attention as it happens fairly often for me and it can be obnoxious.

Is this something that can be fixed/improved in signal-export or just an FYI?

Currently signal-export looks for these timestamps:

def get_ts(self: RawMessage) -> int:
if self.sent_at:
return self.sent_at
elif self.timestamp:
return self.timestamp
return 0

I think it can be fixed by determining if the field serverTimestamp is smaller than sent_at and, if it is, use that instead. Something like this:

    def get_ts(self: RawMessage) -> int:
        if self.sent_at>self.server_timestamp:
            return self.server_timestamp
        elif self.sent_at<=self.server_timestamp:
            return self.sent_at
        elif self.timestamp:
            return self.timestamp
        return 0

You would obviously also need to define the extraction of serverTimestamp.

Opened #124 with what I think should be all that's needed.