Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
maltee1 committed Jan 26, 2024
1 parent 98a7090 commit e3d5bbc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
19 changes: 3 additions & 16 deletions pkg/signalmeow/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 12 additions & 8 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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")
}
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e3d5bbc

Please sign in to comment.