Skip to content

Commit 192b5a7

Browse files
committed
msgconv/from-signal: add option to make view-once messages disappear
1 parent 4b63486 commit 192b5a7

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

pkg/connector/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type SignalConfig struct {
3939
DeviceName string `yaml:"device_name"`
4040
NoteToSelfAvatar id.ContentURIString `yaml:"note_to_self_avatar"`
4141
LocationFormat string `yaml:"location_format"`
42+
DisappearViewOnce bool `yaml:"disappear_view_once"`
4243

4344
displaynameTemplate *template.Template `yaml:"-"`
4445
}
@@ -81,6 +82,7 @@ func upgradeConfig(helper up.Helper) {
8182
helper.Copy(up.Str, "device_name")
8283
helper.Copy(up.Str, "note_to_self_avatar")
8384
helper.Copy(up.Str, "location_format")
85+
helper.Copy(up.Bool, "disappear_view_once")
8486
}
8587

8688
func (s *SignalConnector) GetConfig() (string, any, up.Upgrader) {

pkg/connector/connector.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ func (s *SignalConnector) Init(bridge *bridgev2.Bridge) {
6969
}
7070
s.Store = store.NewStore(bridge.DB.Database, dbutil.ZeroLogger(bridge.Log.With().Str("db_section", "signalmeow").Logger()))
7171
s.Bridge = bridge
72-
s.MsgConv = msgconv.NewMessageConverter(bridge, s.Config.LocationFormat)
72+
s.MsgConv = msgconv.NewMessageConverter(bridge)
73+
s.MsgConv.LocationFormat = s.Config.LocationFormat
74+
s.MsgConv.DisappearViewOnce = s.Config.DisappearViewOnce
7375
}
7476

7577
func (s *SignalConnector) SetMaxFileSize(maxSize int64) {

pkg/connector/example-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ note_to_self_avatar: mxc://maunium.net/REBIVrqjZwmaWpssCZpBlmlL
2121
# Google Maps: 'https://www.google.com/maps/place/%[1]s,%[2]s'
2222
# OpenStreetMap: 'https://www.openstreetmap.org/?mlat=%[1]s&mlon=%[2]s'
2323
location_format: 'https://www.google.com/maps/place/%[1]s,%[2]s'
24+
# Should view-once messages disappear shortly after sending a read receipt on Matrix?
25+
disappear_view_once: false

pkg/connector/handlesignal.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ func (evt *Bv2ChatEvent) ConvertMessage(ctx context.Context, portal *bridgev2.Po
314314
converted := evt.s.Main.MsgConv.ToMatrix(ctx, evt.s.Client, portal, intent, dataMsg)
315315
if converted.Disappear.Type != "" {
316316
evtTS := evt.GetTimestamp()
317-
portal.UpdateDisappearingSetting(ctx, converted.Disappear, nil, evtTS, true, true)
317+
if !dataMsg.GetIsViewOnce() {
318+
portal.UpdateDisappearingSetting(ctx, converted.Disappear, nil, evtTS, true, true)
319+
}
318320
if evt.Info.Sender == evt.s.Client.Store.ACI {
319321
converted.Disappear.DisappearAt = evtTS.Add(converted.Disappear.Timer)
320322
}

pkg/msgconv/from-signal.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ func CanConvertSignal(dm *signalpb.DataMessage) bool {
6868
return calculateLength(dm) > 0
6969
}
7070

71+
const ViewOnceDisappearTimer = 5 * time.Minute
72+
7173
func (mc *MessageConverter) ToMatrix(
7274
ctx context.Context,
7375
client *signalmeow.Client,
@@ -130,6 +132,17 @@ func (mc *MessageConverter) ToMatrix(
130132
},
131133
})
132134
}
135+
if dm.GetIsViewOnce() && mc.DisappearViewOnce && (cm.Disappear.Timer == 0 || cm.Disappear.Timer > ViewOnceDisappearTimer) {
136+
cm.Disappear.Type = database.DisappearingTypeAfterRead
137+
cm.Disappear.Timer = ViewOnceDisappearTimer
138+
cm.Parts = append(cm.Parts, &bridgev2.ConvertedMessagePart{
139+
Type: event.EventMessage,
140+
Content: &event.MessageEventContent{
141+
MsgType: event.MsgText,
142+
Body: "This is a view-once message. It will disappear in 5 minutes.",
143+
},
144+
})
145+
}
133146
cm.MergeCaption()
134147
for i, part := range cm.Parts {
135148
part.ID = signalid.MakeMessagePartID(i)

pkg/msgconv/msgconv.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ type MessageConverter struct {
4444
SignalFmtParams *signalfmt.FormatParams
4545
MatrixFmtParams *matrixfmt.HTMLParser
4646

47-
MaxFileSize int64
48-
LocationFormat string
47+
MaxFileSize int64
48+
LocationFormat string
49+
DisappearViewOnce bool
4950
}
5051

51-
func NewMessageConverter(br *bridgev2.Bridge, locationFormat string) *MessageConverter {
52+
func NewMessageConverter(br *bridgev2.Bridge) *MessageConverter {
5253
return &MessageConverter{
5354
Bridge: br,
5455
SignalFmtParams: &signalfmt.FormatParams{
@@ -89,8 +90,7 @@ func NewMessageConverter(br *bridgev2.Bridge, locationFormat string) *MessageCon
8990
return uuid.Nil
9091
},
9192
},
92-
MaxFileSize: 50 * 1024 * 1024,
93-
LocationFormat: locationFormat,
93+
MaxFileSize: 50 * 1024 * 1024,
9494
}
9595
}
9696

0 commit comments

Comments
 (0)