Skip to content

Commit 0cb6ec6

Browse files
committed
Add proper name for notes to self room
1 parent e33fa95 commit 0cb6ec6

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

config/bridge.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type BridgeConfig struct {
3535
DisplaynameTemplate string `yaml:"displayname_template"`
3636
PrivateChatPortalMeta string `yaml:"private_chat_portal_meta"`
3737
UseContactAvatars bool `yaml:"use_contact_avatars"`
38+
NumberInTopic bool `yaml:"number_in_topic"`
39+
40+
NoteToSelfAvatar id.ContentURIString `yaml:"note_to_self_avatar"`
3841

3942
PortalMessageBuffer int `yaml:"portal_message_buffer"`
4043

config/upgrade.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func DoUpgrade(helper *up.Helper) {
8383
}
8484
helper.Copy(up.Str, "bridge", "private_chat_portal_meta")
8585
helper.Copy(up.Bool, "bridge", "use_contact_avatars")
86+
helper.Copy(up.Bool, "bridge", "number_in_topic")
87+
helper.Copy(up.Str, "bridge", "note_to_self_avatar")
8688
helper.Copy(up.Int, "bridge", "portal_message_buffer")
8789
helper.Copy(up.Bool, "bridge", "personal_filtering_spaces")
8890
helper.Copy(up.Bool, "bridge", "bridge_notices")

example-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ bridge:
106106
private_chat_portal_meta: default
107107
# Should avatars from the user's contact list be used? This is not safe on multi-user instances.
108108
use_contact_avatars: false
109+
# Should the Signal user's phone number be included in the room topic in private chat portal rooms?
110+
number_in_topic: true
111+
# Avatar image for the Note to Self room.
112+
note_to_self_avatar: mxc://maunium.net/REBIVrqjZwmaWpssCZpBlmlL
109113

110114
portal_message_buffer: 128
111115

portal.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,9 @@ func (portal *Portal) handleSignalDataMessage(source *User, sender *Puppet, msg
878878
// If this message is a group change, don't handle it here, it's handled below.
879879
if msg.GetGroupV2().GetGroupChange() == nil && portal.Revision < msg.GetGroupV2().GetRevision() {
880880
portal.UpdateInfo(genericCtx, source, nil, msg.GetGroupV2().GetRevision())
881+
} else if portal.IsPrivateChat() && portal.UserID() == portal.Receiver && portal.Name != NoteToSelfName {
882+
// Slightly hacky way to make note to self names backfill
883+
portal.UpdateDMInfo(genericCtx, false)
881884
}
882885

883886
switch {
@@ -1554,8 +1557,6 @@ func (portal *Portal) GetDMPuppet() *Puppet {
15541557
return portal.bridge.GetPuppetBySignalID(portal.UserID())
15551558
}
15561559

1557-
const PrivateChatTopic = "Signal private chat"
1558-
15591560
func (portal *Portal) UpdateInfo(ctx context.Context, source *User, groupInfo *signalmeow.Group, revision uint32) {
15601561
if portal.IsPrivateChat() {
15611562
portal.UpdateDMInfo(ctx, false)
@@ -1567,6 +1568,9 @@ func (portal *Portal) UpdateInfo(ctx context.Context, source *User, groupInfo *s
15671568
}
15681569
}
15691570

1571+
const PrivateChatTopic = "Signal private chat"
1572+
const NoteToSelfName = "Signal Note to Self"
1573+
15701574
func (portal *Portal) UpdateDMInfo(ctx context.Context, forceSave bool) {
15711575
log := zerolog.Ctx(ctx).With().
15721576
Str("function", "UpdateDMInfo").
@@ -1576,12 +1580,18 @@ func (portal *Portal) UpdateDMInfo(ctx context.Context, forceSave bool) {
15761580
puppet := portal.GetDMPuppet()
15771581

15781582
update := forceSave
1579-
if portal.shouldSetDMRoomMetadata() {
1583+
if portal.UserID() == portal.Receiver {
1584+
noteToSelfAvatar := portal.bridge.Config.Bridge.NoteToSelfAvatar.ParseOrIgnore()
1585+
avatarHash := sha256.Sum256([]byte(noteToSelfAvatar.String()))
1586+
1587+
update = portal.updateName(ctx, NoteToSelfName) || update
1588+
update = portal.updateAvatarWithMXC(ctx, "notetoself", hex.EncodeToString(avatarHash[:]), noteToSelfAvatar) || update
1589+
} else if portal.shouldSetDMRoomMetadata() {
15801590
update = portal.updateName(ctx, puppet.Name) || update
15811591
update = portal.updateAvatarWithMXC(ctx, puppet.AvatarPath, puppet.AvatarHash, puppet.AvatarURL) || update
15821592
}
15831593
topic := PrivateChatTopic
1584-
if puppet.Number != "" {
1594+
if portal.bridge.Config.Bridge.NumberInTopic && puppet.Number != "" {
15851595
topic = fmt.Sprintf("%s with %s", topic, puppet.Number)
15861596
}
15871597
update = portal.updateTopic(ctx, topic) || update

0 commit comments

Comments
 (0)