From 6db93d513a53d8dfeff9bd73cea0c67a086ecf76 Mon Sep 17 00:00:00 2001 From: Scott Weber Date: Sun, 15 Sep 2024 10:43:11 -0400 Subject: [PATCH 1/2] signalmeow/receiving: keep ServerTimestamp for received messages --- pkg/signalmeow/events/message.go | 3 ++- pkg/signalmeow/receiving.go | 36 ++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/pkg/signalmeow/events/message.go b/pkg/signalmeow/events/message.go index a6fcc7f1..0038657f 100644 --- a/pkg/signalmeow/events/message.go +++ b/pkg/signalmeow/events/message.go @@ -40,7 +40,8 @@ type MessageInfo struct { Sender uuid.UUID ChatID string - GroupRevision uint32 + GroupRevision uint32 + ServerTimestamp uint64 } type ChatEvent struct { diff --git a/pkg/signalmeow/receiving.go b/pkg/signalmeow/receiving.go index 9b36b840..be5e9585 100644 --- a/pkg/signalmeow/receiving.go +++ b/pkg/signalmeow/receiving.go @@ -744,9 +744,9 @@ func (cli *Client) handleDecryptedResult( log.Warn().Msg("sync message sent destination is nil") } else if content.SyncMessage.Sent.Message != nil { // TODO handle expiration start ts, and maybe the sync message ts? - cli.incomingDataMessage(ctx, content.SyncMessage.Sent.Message, cli.Store.ACI, syncDestinationServiceID) + cli.incomingDataMessage(ctx, content.SyncMessage.Sent.Message, cli.Store.ACI, syncDestinationServiceID, envelope.GetServerTimestamp()) } else if content.SyncMessage.Sent.EditMessage != nil { - cli.incomingEditMessage(ctx, content.SyncMessage.Sent.EditMessage, cli.Store.ACI, syncDestinationServiceID) + cli.incomingEditMessage(ctx, content.SyncMessage.Sent.EditMessage, cli.Store.ACI, syncDestinationServiceID, envelope.GetServerTimestamp()) } } if content.SyncMessage.Contacts != nil { @@ -794,9 +794,9 @@ func (cli *Client) handleDecryptedResult( var sendDeliveryReceipt bool if content.DataMessage != nil { - sendDeliveryReceipt = cli.incomingDataMessage(ctx, content.DataMessage, theirServiceID.UUID, theirServiceID) + sendDeliveryReceipt = cli.incomingDataMessage(ctx, content.DataMessage, theirServiceID.UUID, theirServiceID, envelope.GetServerTimestamp()) } else if content.EditMessage != nil { - sendDeliveryReceipt = cli.incomingEditMessage(ctx, content.EditMessage, theirServiceID.UUID, theirServiceID) + sendDeliveryReceipt = cli.incomingEditMessage(ctx, content.EditMessage, theirServiceID.UUID, theirServiceID, envelope.GetServerTimestamp()) } if sendDeliveryReceipt { // TODO send delivery receipts after actually bridging instead of here @@ -814,8 +814,9 @@ func (cli *Client) handleDecryptedResult( } cli.handleEvent(&events.ChatEvent{ Info: events.MessageInfo{ - Sender: theirServiceID.UUID, - ChatID: groupOrUserID(groupID, theirServiceID), + Sender: theirServiceID.UUID, + ChatID: groupOrUserID(groupID, theirServiceID), + ServerTimestamp: envelope.GetServerTimestamp(), }, Event: content.TypingMessage, }) @@ -825,8 +826,9 @@ func (cli *Client) handleDecryptedResult( if content.CallMessage != nil && (content.CallMessage.Offer != nil || content.CallMessage.Hangup != nil) { cli.handleEvent(&events.Call{ Info: events.MessageInfo{ - Sender: theirServiceID.UUID, - ChatID: theirServiceID.String(), + Sender: theirServiceID.UUID, + ChatID: theirServiceID.String(), + ServerTimestamp: envelope.GetServerTimestamp(), }, IsRinging: content.CallMessage.Offer != nil, }) @@ -954,7 +956,7 @@ func (cli *Client) handlePNISignatureMessage(ctx context.Context, sender libsign return nil } -func (cli *Client) incomingEditMessage(ctx context.Context, editMessage *signalpb.EditMessage, messageSenderACI uuid.UUID, chatRecipient libsignalgo.ServiceID) bool { +func (cli *Client) incomingEditMessage(ctx context.Context, editMessage *signalpb.EditMessage, messageSenderACI uuid.UUID, chatRecipient libsignalgo.ServiceID, serverTimestamp uint64) bool { // If it's a group message, get the ID and invalidate cache if necessary var groupID types.GroupIdentifier var groupRevision uint32 @@ -972,16 +974,17 @@ func (cli *Client) incomingEditMessage(ctx context.Context, editMessage *signalp } cli.handleEvent(&events.ChatEvent{ Info: events.MessageInfo{ - Sender: messageSenderACI, - ChatID: groupOrUserID(groupID, chatRecipient), - GroupRevision: groupRevision, + Sender: messageSenderACI, + ChatID: groupOrUserID(groupID, chatRecipient), + GroupRevision: groupRevision, + ServerTimestamp: serverTimestamp, }, Event: editMessage, }) return true } -func (cli *Client) incomingDataMessage(ctx context.Context, dataMessage *signalpb.DataMessage, messageSenderACI uuid.UUID, chatRecipient libsignalgo.ServiceID) bool { +func (cli *Client) incomingDataMessage(ctx context.Context, dataMessage *signalpb.DataMessage, messageSenderACI uuid.UUID, chatRecipient libsignalgo.ServiceID, serverTimestamp uint64) bool { // If there's a profile key, save it if dataMessage.ProfileKey != nil { profileKey := libsignalgo.ProfileKey(dataMessage.ProfileKey) @@ -1009,9 +1012,10 @@ func (cli *Client) incomingDataMessage(ctx context.Context, dataMessage *signalp } evtInfo := events.MessageInfo{ - Sender: messageSenderACI, - ChatID: groupOrUserID(groupID, chatRecipient), - GroupRevision: groupRevision, + Sender: messageSenderACI, + ChatID: groupOrUserID(groupID, chatRecipient), + GroupRevision: groupRevision, + ServerTimestamp: serverTimestamp, } // Hacky special case for group calls to cache the state if dataMessage.GroupCallUpdate != nil { From 92c5439cf272f43a37db12f3aad4544b7b74b13c Mon Sep 17 00:00:00 2001 From: Scott Weber Date: Sun, 15 Sep 2024 10:43:44 -0400 Subject: [PATCH 2/2] handlesignal: use ServerTimestamp as StreamOrder --- pkg/connector/handlesignal.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pkg/connector/handlesignal.go b/pkg/connector/handlesignal.go index b39f2028..2d863acb 100644 --- a/pkg/connector/handlesignal.go +++ b/pkg/connector/handlesignal.go @@ -135,15 +135,16 @@ type Bv2ChatEvent struct { } var ( - _ bridgev2.RemoteMessage = (*Bv2ChatEvent)(nil) - _ bridgev2.RemoteEdit = (*Bv2ChatEvent)(nil) - _ bridgev2.RemoteEventWithTimestamp = (*Bv2ChatEvent)(nil) - _ bridgev2.RemoteReaction = (*Bv2ChatEvent)(nil) - _ bridgev2.RemoteReactionRemove = (*Bv2ChatEvent)(nil) - _ bridgev2.RemoteMessageRemove = (*Bv2ChatEvent)(nil) - _ bridgev2.RemoteTyping = (*Bv2ChatEvent)(nil) - _ bridgev2.RemotePreHandler = (*Bv2ChatEvent)(nil) - _ bridgev2.RemoteChatInfoChange = (*Bv2ChatEvent)(nil) + _ bridgev2.RemoteMessage = (*Bv2ChatEvent)(nil) + _ bridgev2.RemoteEdit = (*Bv2ChatEvent)(nil) + _ bridgev2.RemoteEventWithTimestamp = (*Bv2ChatEvent)(nil) + _ bridgev2.RemoteReaction = (*Bv2ChatEvent)(nil) + _ bridgev2.RemoteReactionRemove = (*Bv2ChatEvent)(nil) + _ bridgev2.RemoteMessageRemove = (*Bv2ChatEvent)(nil) + _ bridgev2.RemoteTyping = (*Bv2ChatEvent)(nil) + _ bridgev2.RemotePreHandler = (*Bv2ChatEvent)(nil) + _ bridgev2.RemoteChatInfoChange = (*Bv2ChatEvent)(nil) + _ bridgev2.RemoteEventWithStreamOrder = (*Bv2ChatEvent)(nil) ) func (evt *Bv2ChatEvent) GetType() bridgev2.RemoteEventType { @@ -337,6 +338,10 @@ func (evt *Bv2ChatEvent) ConvertEdit(ctx context.Context, portal *bridgev2.Porta }, nil } +func (evt *Bv2ChatEvent) GetStreamOrder() int64 { + return int64(evt.Info.ServerTimestamp) +} + type Bv2Receipt struct { Type signalpb.ReceiptMessage_Type Chat networkid.PortalKey