From dd0fc13b89bf36ff145b33cf72f3ecdc910d8008 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 18 May 2021 13:42:38 -0700 Subject: [PATCH] Using new group API to avoid replicated code --- utils/eventHandler.go | 19 ++++++++----------- utils/manager.go | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 0013578..579163b 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -6,14 +6,11 @@ import ( "cwtch.im/cwtch/model" "cwtch.im/cwtch/model/attr" "cwtch.im/cwtch/protocol/connections" - groups2 "cwtch.im/cwtch/protocol/groups" - "encoding/base64" "encoding/json" "git.openprivacy.ca/flutter/libcwtch-go/constants" "git.openprivacy.ca/flutter/libcwtch-go/features/groups" "git.openprivacy.ca/openprivacy/log" "strconv" - "strings" ) import "cwtch.im/cwtch/event" @@ -269,15 +266,15 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { uiManager.AddSendMessageError(e.Data[event.RemotePeer], e.Data[event.EventID], e.Data[event.Error]) */ case event.NewGroup: - var invite = groups2.GroupInvite{} + // This event should only happen after we have validated the invite, as such the error + // condition *should* never happen. serializedInvite := ev.Event.Data[event.GroupInvite] - if strings.HasPrefix(serializedInvite, "torv3") { - inviteJson, err := base64.StdEncoding.DecodeString(serializedInvite[5:]) - if err == nil { - json.Unmarshal(inviteJson, &invite) - groupPic := ph.GetProfilePic(invite.GroupID) - ev.Event.Data["PicturePath"] = groupPic - } + if invite, err := model.ValidateInvite(serializedInvite); err == nil { + groupPic := ph.GetProfilePic(invite.GroupID) + ev.Event.Data["PicturePath"] = groupPic + } else { + log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivcy.ca/cwtch.im/cwtch", err) + return "" } case event.PeerStateChange: cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] diff --git a/utils/manager.go b/utils/manager.go index 7c78275..be2326a 100644 --- a/utils/manager.go +++ b/utils/manager.go @@ -284,7 +284,7 @@ func EnrichNewPeer(handle string, ph *PeerHelper, ev *EventProfileEnvelope) erro } } else { // could be a server? - log.Errorf("sorry, unable to handle AddContact(%v)", handle) + log.Infof("sorry, unable to handle AddContact(%v)", handle) return errors.New("Not a peer or group") } return nil