Skip to content

Commit

Permalink
dbmeta: add support for expiration timer versions
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 3, 2024
1 parent b1bd303 commit 81841f4
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 27 deletions.
4 changes: 4 additions & 0 deletions pkg/msgconv/from-matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (mc *MessageConverter) ToSignal(
}
if portal.Disappear.Timer > 0 {
dm.ExpireTimer = proto.Uint32(uint32(portal.Disappear.Timer.Seconds()))
timerVersion := portal.Metadata.(*signalid.PortalMetadata).ExpirationTimerVersion
if timerVersion > 0 {
dm.ExpireTimerVersion = &timerVersion
}
}
if content.MsgType == event.MsgEmote && !relaybotFormatted {
content.Body = "/me " + content.Body
Expand Down
18 changes: 16 additions & 2 deletions pkg/msgconv/from-signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (mc *MessageConverter) ToMatrix(
Parts: make([]*bridgev2.ConvertedMessagePart, 0, calculateLength(dm)),
}
if dm.GetFlags()&uint32(signalpb.DataMessage_EXPIRATION_TIMER_UPDATE) != 0 {
cm.Parts = append(cm.Parts, mc.ConvertDisappearingTimerChangeToMatrix(ctx, dm.GetExpireTimer(), true))
cm.Parts = append(cm.Parts, mc.ConvertDisappearingTimerChangeToMatrix(ctx, dm.GetExpireTimer(), dm.ExpireTimerVersion, true))
// Don't allow any other parts in a disappearing timer change message
return cm
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func (mc *MessageConverter) ToMatrix(
return cm
}

func (mc *MessageConverter) ConvertDisappearingTimerChangeToMatrix(ctx context.Context, timer uint32, updatePortal bool) *bridgev2.ConvertedMessagePart {
func (mc *MessageConverter) ConvertDisappearingTimerChangeToMatrix(ctx context.Context, timer uint32, timerVersion *uint32, updatePortal bool) *bridgev2.ConvertedMessagePart {
part := &bridgev2.ConvertedMessagePart{
Type: event.EventMessage,
Content: &event.MessageEventContent{
Expand All @@ -164,12 +164,26 @@ func (mc *MessageConverter) ConvertDisappearingTimerChangeToMatrix(ctx context.C
}
if updatePortal {
portal := getPortal(ctx)
portalMeta := portal.Metadata.(*signalid.PortalMetadata)
if timerVersion != nil && portalMeta.ExpirationTimerVersion > *timerVersion {
zerolog.Ctx(ctx).Warn().
Uint32("current_version", portalMeta.ExpirationTimerVersion).
Uint32("new_version", *timerVersion).
Msg("Ignoring outdated disappearing timer change")
part.Content.Body += " (change ignored)"
return part
}
portal.Disappear.Timer = time.Duration(timer) * time.Second
if timer == 0 {
portal.Disappear.Type = ""
} else {
portal.Disappear.Type = database.DisappearingTypeAfterRead
}
if timerVersion != nil {
portalMeta.ExpirationTimerVersion = *timerVersion
} else {
portalMeta.ExpirationTimerVersion = 1
}
err := portal.Save(ctx)
if err != nil {
zerolog.Ctx(ctx).Err(err).Msg("Failed to update portal disappearing timer in database")
Expand Down
3 changes: 2 additions & 1 deletion pkg/signalid/dbmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
)

type PortalMetadata struct {
Revision uint32 `json:"revision,omitempty"`
Revision uint32 `json:"revision,omitempty"`
ExpirationTimerVersion uint32 `json:"expiration_timer_version,omitempty"`
}

type MessageMetadata struct {
Expand Down
36 changes: 26 additions & 10 deletions pkg/signalmeow/protobuf/SignalService.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/signalmeow/protobuf/SignalService.pb.raw
Binary file not shown.
24 changes: 13 additions & 11 deletions pkg/signalmeow/protobuf/SignalService.proto
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ message DataMessage {
optional GroupContextV2 groupV2 = 15;
optional uint32 flags = 4;
optional uint32 expireTimer = 5;
optional uint32 expireTimerVersion = 23;
optional bytes profileKey = 6;
optional uint64 timestamp = 7;
optional Quote quote = 8;
Expand Down Expand Up @@ -793,17 +794,18 @@ message ContactDetails {
optional uint32 length = 2;
}

optional string number = 1;
optional string aci = 9;
optional string name = 2;
optional Avatar avatar = 3;
optional string color = 4;
optional Verified verified = 5;
optional bytes profileKey = 6;
reserved /*blocked*/ 7;
optional uint32 expireTimer = 8;
optional uint32 inboxPosition = 10;
optional bool archived = 11;
optional string number = 1;
optional string aci = 9;
optional string name = 2;
optional Avatar avatar = 3;
optional string color = 4;
optional Verified verified = 5;
optional bytes profileKey = 6;
reserved /*blocked*/ 7;
optional uint32 expireTimer = 8;
optional uint32 expireTimerVersion = 12;
optional uint32 inboxPosition = 10;
optional bool archived = 11;
}

message GroupDetails {
Expand Down
4 changes: 2 additions & 2 deletions pkg/signalmeow/protobuf/update-protos.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
set -euo pipefail

ANDROID_GIT_REVISION=${1:-68c7ce582378b5f752e5971007b2c203e81cecbd}
DESKTOP_GIT_REVISION=${1:-faea93e5cea24893a8976dc6329faa751f59df5c}
ANDROID_GIT_REVISION=${1:-ab7bdc3c03ecda2d746fd56cfd747f56feab7b17}
DESKTOP_GIT_REVISION=${1:-1898e964adcfc8a9096b4aaebff895813fb4f35c}

update_proto() {
case "$1" in
Expand Down
3 changes: 2 additions & 1 deletion pkg/signalmeow/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ func continueProvisioning(ctx context.Context, ws *websocket.Conn, provisioningC
}

var signalCapabilities = map[string]any{
"deleteSync": true,
"deleteSync": true,
"versionedExpirationTimer": true,
}

var signalCapabilitiesBody = exerrors.Must(json.Marshal(signalCapabilities))
Expand Down

0 comments on commit 81841f4

Please sign in to comment.