Using new group API to avoid replicated code
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-05-18 13:42:38 -07:00
parent 2c76504e0b
commit dd0fc13b89
2 changed files with 9 additions and 12 deletions

View File

@ -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]]

View File

@ -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