Browse Source

Fixing New Group Invite flow

groupinvitefix
Sarah Jamie Lewis 1 year ago
parent
commit
8f3b607053
3 changed files with 14 additions and 10 deletions
  1. +4
    -4
      peer/cwtch_peer.go
  2. +4
    -6
      storage/profile_store.go
  3. +6
    -0
      storage/profile_store_test.go

+ 4
- 4
peer/cwtch_peer.go View File

@@ -120,10 +120,10 @@ func (cp *cwtchPeer) ImportGroup(exportedInvite string) (groupID string, err err
onion := utils.GetTorV3Hostname(edpk)
cp.Profile.AddContact(onion, &model.PublicProfile{Name: "", Ed25519PublicKey: edpk, Trusted: true, Blocked: false, Onion: onion})
cp.Profile.ProcessInvite(cpp.GetGroupChatInvite(), onion)
jsobj, err := json.Marshal(cp.GetGroup(cpp.GroupChatInvite.GetGroupName()))
jsobj, err := json.Marshal(cpp.GetGroupChatInvite())
if err == nil {
cp.eventBus.Publish(event.NewEvent(event.GroupCreated, map[event.Field]string{
event.Data: string(jsobj),
cp.eventBus.Publish(event.NewEvent(event.NewGroupInvite, map[event.Field]string{
event.GroupInvite: string(jsobj),
}))
} else {
log.Errorf("error serializing group: %v", err)
@@ -320,7 +320,7 @@ func (cp *cwtchPeer) eventHandler() {
}
case event.NewGroupInvite:
var groupInvite protocol.GroupChatInvite
proto.Unmarshal([]byte(ev.Data["GroupInvite"]), &groupInvite)
proto.Unmarshal([]byte(ev.Data[event.GroupInvite]), &groupInvite)
cp.Profile.ProcessInvite(&groupInvite, ev.Data[event.RemotePeer])
default:
if ev.EventType != "" {


+ 4
- 6
storage/profile_store.go View File

@@ -143,14 +143,12 @@ func (ps *profileStore) eventHandler() {
ps.save()
}
case event.NewGroupInvite:
var gci protocol.CwtchPeerPacket //protocol.GroupChatInvite
proto.Unmarshal([]byte(ev.Data["GroupInvite"]), &gci)
groupInvite := gci.GroupChatInvite
ps.profile.ProcessInvite(groupInvite, ev.Data[event.RemotePeer])
var gci protocol.GroupChatInvite
proto.Unmarshal([]byte(ev.Data[event.GroupInvite]), &gci)
ps.profile.ProcessInvite(&gci, ev.Data[event.RemotePeer])
ps.save()
group := ps.profile.Groups[groupInvite.GetGroupName()]
group := ps.profile.Groups[gci.GetGroupName()]
ps.streamStores[group.GroupID] = NewStreamStore(ps.directory, group.LocalID, ps.password)

case event.NewMessageFromGroup:
groupid := ev.Data[event.GroupID]
received, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampReceived])


+ 6
- 0
storage/profile_store_test.go View File

@@ -2,6 +2,8 @@ package storage

import (
"cwtch.im/cwtch/event"
"cwtch.im/cwtch/protocol"
"github.com/golang/protobuf/proto"
"os"
"testing"
"time"
@@ -30,6 +32,10 @@ func TestProfileStoreWriteRead(t *testing.T) {
if err != nil {
t.Errorf("Creating group invite: %v\n", err)
}

packet := protocol.CwtchPeerPacket{}
proto.Unmarshal(invite, &packet)
invite, _ = proto.Marshal(packet.GetGroupChatInvite())
eventBus.Publish(event.NewEvent(event.NewGroupInvite, map[event.Field]string{event.TimestampReceived: time.Now().Format(time.RFC3339Nano), event.RemotePeer: ps1.GetProfileCopy().Onion, event.GroupInvite: string(invite)}))
time.Sleep(1 * time.Second)



Loading…
Cancel
Save