Harmonizing Group Invite Flow #215
|
@ -120,10 +120,10 @@ func (cp *cwtchPeer) ImportGroup(exportedInvite string) (groupID string, err err
|
||||||
onion := utils.GetTorV3Hostname(edpk)
|
onion := utils.GetTorV3Hostname(edpk)
|
||||||
cp.Profile.AddContact(onion, &model.PublicProfile{Name: "", Ed25519PublicKey: edpk, Trusted: true, Blocked: false, Onion: onion})
|
cp.Profile.AddContact(onion, &model.PublicProfile{Name: "", Ed25519PublicKey: edpk, Trusted: true, Blocked: false, Onion: onion})
|
||||||
cp.Profile.ProcessInvite(cpp.GetGroupChatInvite(), 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 {
|
if err == nil {
|
||||||
cp.eventBus.Publish(event.NewEvent(event.GroupCreated, map[event.Field]string{
|
cp.eventBus.Publish(event.NewEvent(event.NewGroupInvite, map[event.Field]string{
|
||||||
event.Data: string(jsobj),
|
event.GroupInvite: string(jsobj),
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("error serializing group: %v", err)
|
log.Errorf("error serializing group: %v", err)
|
||||||
|
@ -320,7 +320,7 @@ func (cp *cwtchPeer) eventHandler() {
|
||||||
}
|
}
|
||||||
case event.NewGroupInvite:
|
case event.NewGroupInvite:
|
||||||
var groupInvite protocol.GroupChatInvite
|
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])
|
cp.Profile.ProcessInvite(&groupInvite, ev.Data[event.RemotePeer])
|
||||||
default:
|
default:
|
||||||
if ev.EventType != "" {
|
if ev.EventType != "" {
|
||||||
|
|
|
@ -143,14 +143,12 @@ func (ps *profileStore) eventHandler() {
|
||||||
ps.save()
|
ps.save()
|
||||||
}
|
}
|
||||||
case event.NewGroupInvite:
|
case event.NewGroupInvite:
|
||||||
var gci protocol.CwtchPeerPacket //protocol.GroupChatInvite
|
var gci protocol.GroupChatInvite
|
||||||
proto.Unmarshal([]byte(ev.Data["GroupInvite"]), &gci)
|
proto.Unmarshal([]byte(ev.Data[event.GroupInvite]), &gci)
|
||||||
groupInvite := gci.GroupChatInvite
|
ps.profile.ProcessInvite(&gci, ev.Data[event.RemotePeer])
|
||||||
ps.profile.ProcessInvite(groupInvite, ev.Data[event.RemotePeer])
|
|
||||||
ps.save()
|
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)
|
ps.streamStores[group.GroupID] = NewStreamStore(ps.directory, group.LocalID, ps.password)
|
||||||
|
|
||||||
case event.NewMessageFromGroup:
|
case event.NewMessageFromGroup:
|
||||||
groupid := ev.Data[event.GroupID]
|
groupid := ev.Data[event.GroupID]
|
||||||
received, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampReceived])
|
received, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampReceived])
|
||||||
|
|
|
@ -2,6 +2,8 @@ package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cwtch.im/cwtch/event"
|
"cwtch.im/cwtch/event"
|
||||||
|
"cwtch.im/cwtch/protocol"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -30,6 +32,10 @@ func TestProfileStoreWriteRead(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Creating group invite: %v\n", err)
|
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)}))
|
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)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue