From e3d5bbc189e2300d2e0c95a6b948186451221f88 Mon Sep 17 00:00:00 2001 From: Malte E Date: Fri, 26 Jan 2024 21:27:28 +0100 Subject: [PATCH] fix issues --- pkg/signalmeow/groups.go | 19 +++---------------- portal.go | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/pkg/signalmeow/groups.go b/pkg/signalmeow/groups.go index 0efa0610..bc56efc8 100644 --- a/pkg/signalmeow/groups.go +++ b/pkg/signalmeow/groups.go @@ -498,7 +498,7 @@ func (cli *Client) fetchGroupByID(ctx context.Context, gid types.GroupIdentifier return group, nil } -func (cli *Client) DownloadGroupAvatarWithInfo(ctx context.Context, group GroupAvatarMeta) ([]byte, error) { +func (cli *Client) DownloadGroupAvatar(ctx context.Context, group GroupAvatarMeta) ([]byte, error) { groupMasterKey := group.getGroupMasterKey() avatarPath := group.GetAvatarPath() username, password := cli.Store.BasicAuthCreds() @@ -594,26 +594,14 @@ type GroupCache struct { activeCalls map[types.GroupIdentifier]string } -func (cli *Client) GetGroupChange(ctx context.Context, groupContext *signalpb.GroupContextV2, gid types.GroupIdentifier) (*GroupChange, error) { - // did I already get authorization for today if I received a GroupChange? +func DecryptGroupChange(ctx context.Context, groupContext *signalpb.GroupContextV2) (*GroupChange, error) { masterKeyBytes := libsignalgo.GroupMasterKey(groupContext.MasterKey) - _, err := cli.GetAuthorizationForToday(ctx, masterKeyBytes) - if err != nil { - return nil, err - } groupMasterKey := masterKeyFromBytes(masterKeyBytes) - if groupContext.GroupChange == nil { - return nil, fmt.Errorf("No GroupChange found") - } - groupChangeBytes := groupContext.GroupChange - return decryptGroupChange(ctx, groupChangeBytes, groupMasterKey) -} - -func decryptGroupChange(ctx context.Context, groupChangeBytes []byte, groupMasterKey types.SerializedGroupMasterKey) (*GroupChange, error) { log := zerolog.Ctx(ctx).With().Str("action", "decrypt group change").Logger() encryptedGroupChange := &signalpb.GroupChange{} + groupChangeBytes := groupContext.GroupChange err := proto.Unmarshal(groupChangeBytes, encryptedGroupChange) if err != nil { return nil, fmt.Errorf("Error unmarshalling group change: %w", err) @@ -641,7 +629,6 @@ func decryptGroupChange(ctx context.Context, groupChangeBytes []byte, groupMaste decryptedGroupChange := &GroupChange{groupMasterKey: groupMasterKey} - log.Info().Msg("trying to decrypt title") if encryptedActions.ModifyTitle != nil { titleBlob, err := decryptGroupPropertyIntoBlob(groupSecretParams, encryptedActions.ModifyTitle.Title) if err != nil { diff --git a/portal.go b/portal.go index 53659769..ad934155 100644 --- a/portal.go +++ b/portal.go @@ -907,7 +907,7 @@ func (portal *Portal) handleSignalGroupChange(source *User, sender *Puppet, grou Uint32("new_revision", groupMeta.GetRevision()). Logger() ctx := log.WithContext(context.TODO()) - groupChange, err := source.Client.GetGroupChange(ctx, groupMeta, types.GroupIdentifier(portal.ChatID)) + groupChange, err := signalmeow.DecryptGroupChange(ctx, groupMeta) if err != nil { log.Err(err).Msg("Handling GroupChange failed") return @@ -930,7 +930,7 @@ func (portal *Portal) handleSignalGroupChange(source *User, sender *Puppet, grou } reqInviteUser := mautrix.ReqInviteUser{ Reason: "", - UserID: puppet.MXID, + UserID: puppet.IntentFor(portal).UserID, } _, err = intent.InviteUser(ctx, portal.MXID, &reqInviteUser) if errors.Is(err, mautrix.MForbidden) { @@ -945,8 +945,7 @@ func (portal *Portal) handleSignalGroupChange(source *User, sender *Puppet, grou err = puppet.IntentFor(portal).EnsureJoined(ctx, portal.MXID) } if err != nil { - log.Err(err).Msg("Adding Member failed") - return + log.Err(err).Msg("inviting User failed") } } for _, deleteMember := range groupChange.DeleteMembers { @@ -956,14 +955,16 @@ func (portal *Portal) handleSignalGroupChange(source *User, sender *Puppet, grou continue } reqKickUser := mautrix.ReqKickUser{ - Reason: "", - UserID: puppet.MXID, + UserID: puppet.IntentFor(portal).UserID, } _, err := intent.KickUser(ctx, portal.MXID, &reqKickUser) if errors.Is(err, mautrix.MForbidden) { reqKickUser.Reason = fmt.Sprintf("Kicked by %s", sender.GetDisplayname()) _, err = portal.MainIntent().KickUser(ctx, portal.MXID, &reqKickUser) } + if err != nil { + log.Err(err).Msg("kicking User failed") + } } for _, modifyRole := range groupChange.ModifyMemberRoles { puppet := portal.bridge.GetPuppetBySignalID(modifyRole.UserID) @@ -979,7 +980,10 @@ func (portal *Portal) handleSignalGroupChange(source *User, sender *Puppet, grou } _, err = intent.SetPowerLevel(ctx, portal.MXID, puppet.MXID, powerLevel) if errors.Is(err, mautrix.MForbidden) { - _, err = portal.MainIntent().SetPowerLevel(ctx, portal.MXID, puppet.MXID, powerLevel) + _, err = portal.MainIntent().SetPowerLevel(ctx, portal.MXID, puppet.IntentFor(portal).UserID, powerLevel) + } + if err != nil { + log.Err(err).Msg("Changing power level failed") } } } @@ -1810,7 +1814,7 @@ func (portal *Portal) updateAvatarWithInfo(ctx context.Context, source *User, gr } log := zerolog.Ctx(ctx) log.Debug().Str("avatar_path", portal.AvatarPath).Msg("Downloading new group avatar from Signal") - avatarBytes, err := source.Client.DownloadGroupAvatarWithInfo(ctx, group) + avatarBytes, err := source.Client.DownloadGroupAvatar(ctx, group) if err != nil { log.Err(err).Msg("Failed to download new avatar for portal") return true