From 58a1b873489a8afb88dcd9eb6b48304b6c60cf64 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 19 Jun 2024 23:30:38 +0300 Subject: [PATCH] v2: implement note to self avatar --- go.mod | 2 +- go.sum | 4 ++-- pkg/connector/chatinfo.go | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index fd1ea3f9..e36b1c15 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 golang.org/x/net v0.26.0 google.golang.org/protobuf v1.34.2 - maunium.net/go/mautrix v0.19.0-beta.1.0.20240619195836-2a7a5070fb32 + maunium.net/go/mautrix v0.19.0-beta.1.0.20240619204109-68d8ab6896fd nhooyr.io/websocket v1.8.11 ) diff --git a/go.sum b/go.sum index a6c0ff3a..9c14fb46 100644 --- a/go.sum +++ b/go.sum @@ -93,7 +93,7 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M= maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA= -maunium.net/go/mautrix v0.19.0-beta.1.0.20240619195836-2a7a5070fb32 h1:BiUVpB1hejeuCivlLOv5jKzU/Y8TTwDlQ0i1qO+JGdI= -maunium.net/go/mautrix v0.19.0-beta.1.0.20240619195836-2a7a5070fb32/go.mod h1:cxv1w6+syudmEpOewHYIQT9yO7TM5UOWmf6xEBVI4H4= +maunium.net/go/mautrix v0.19.0-beta.1.0.20240619204109-68d8ab6896fd h1:NZYFpztfJCdynpWJTGOyPcYfr+95zCut/IobMzaKCdU= +maunium.net/go/mautrix v0.19.0-beta.1.0.20240619204109-68d8ab6896fd/go.mod h1:cxv1w6+syudmEpOewHYIQT9yO7TM5UOWmf6xEBVI4H4= nhooyr.io/websocket v1.8.11 h1:f/qXNc2/3DpoSZkHt1DQu6rj4zGC8JmkkLkWss0MgN0= nhooyr.io/websocket v1.8.11/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= diff --git a/pkg/connector/chatinfo.go b/pkg/connector/chatinfo.go index eea43811..ceb2a86e 100644 --- a/pkg/connector/chatinfo.go +++ b/pkg/connector/chatinfo.go @@ -18,6 +18,7 @@ package connector import ( "context" + "crypto/sha256" "errors" "fmt" "strconv" @@ -193,12 +194,19 @@ func (s *SignalClient) makeCreateDMResponse(recipient *types.Recipient) *bridgev topic = fmt.Sprintf("%s with %s", PrivateChatTopic, recipient.E164) } var serviceID libsignalgo.ServiceID + var avatar *bridgev2.Avatar if recipient.ACI == uuid.Nil { name = s.Main.Config.FormatDisplayname(recipient) serviceID = libsignalgo.NewPNIServiceID(recipient.PNI) } else { if recipient.ACI == s.Client.Store.ACI { name = NoteToSelfName + avatar = &bridgev2.Avatar{ + ID: networkid.AvatarID(s.Main.Config.NoteToSelfAvatar), + Remove: len(s.Main.Config.NoteToSelfAvatar) == 0, + MXC: s.Main.Config.NoteToSelfAvatar, + Hash: sha256.Sum256([]byte(s.Main.Config.NoteToSelfAvatar)), + } } else { // The other user is only present if their ACI is known members = append(members, makeUserID(recipient.ACI)) @@ -209,6 +217,7 @@ func (s *SignalClient) makeCreateDMResponse(recipient *types.Recipient) *bridgev PortalID: s.makeDMPortalKey(serviceID), PortalInfo: &bridgev2.PortalInfo{ Name: &name, + Avatar: avatar, Topic: &topic, Members: members, IsDirectChat: &isDirectChat,