Merge branch 'groupimportfix' of cwtch.im/cwtch into master
This commit is contained in:
commit
d15585eda7
|
@ -24,6 +24,9 @@ const (
|
||||||
// GroupInvite: [eg "torv3....."]
|
// GroupInvite: [eg "torv3....."]
|
||||||
NewGroupInvite = Type("NewGroupInvite")
|
NewGroupInvite = Type("NewGroupInvite")
|
||||||
|
|
||||||
|
// GroupID
|
||||||
|
AcceptGroupInvite = Type("AcceptGroupInvite")
|
||||||
|
|
||||||
SendMessageToGroup = Type("SendMessagetoGroup")
|
SendMessageToGroup = Type("SendMessagetoGroup")
|
||||||
EncryptedGroupMessage = Type("EncryptedGroupMessage")
|
EncryptedGroupMessage = Type("EncryptedGroupMessage")
|
||||||
NewMessageFromGroup = Type("NewMessageFromGroup")
|
NewMessageFromGroup = Type("NewMessageFromGroup")
|
||||||
|
|
|
@ -274,6 +274,7 @@ func (cp *cwtchPeer) BlockPeer(peer string) error {
|
||||||
|
|
||||||
// AcceptInvite accepts a given existing group invite
|
// AcceptInvite accepts a given existing group invite
|
||||||
func (cp *cwtchPeer) AcceptInvite(groupID string) error {
|
func (cp *cwtchPeer) AcceptInvite(groupID string) error {
|
||||||
|
cp.eventBus.Publish(event.NewEvent(event.AcceptGroupInvite, map[event.Field]string{event.GroupID: groupID}))
|
||||||
return cp.Profile.AcceptInvite(groupID)
|
return cp.Profile.AcceptInvite(groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ func NewProfileStore(eventManager *event.Manager, directory, password string, pr
|
||||||
ps.eventManager.Subscribe(event.SetAttribute, ps.queue.EventChannel)
|
ps.eventManager.Subscribe(event.SetAttribute, ps.queue.EventChannel)
|
||||||
ps.eventManager.Subscribe(event.SetPeerAttribute, ps.queue.EventChannel)
|
ps.eventManager.Subscribe(event.SetPeerAttribute, ps.queue.EventChannel)
|
||||||
ps.eventManager.Subscribe(event.SetGroupAttribute, ps.queue.EventChannel)
|
ps.eventManager.Subscribe(event.SetGroupAttribute, ps.queue.EventChannel)
|
||||||
|
ps.eventManager.Subscribe(event.AcceptGroupInvite, ps.queue.EventChannel)
|
||||||
ps.eventManager.Subscribe(event.NewGroupInvite, ps.queue.EventChannel)
|
ps.eventManager.Subscribe(event.NewGroupInvite, ps.queue.EventChannel)
|
||||||
ps.eventManager.Subscribe(event.NewMessageFromGroup, ps.queue.EventChannel)
|
ps.eventManager.Subscribe(event.NewMessageFromGroup, ps.queue.EventChannel)
|
||||||
|
|
||||||
|
@ -83,11 +84,9 @@ func (ps *profileStore) Load() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, group := range cp.Groups {
|
for _, group := range cp.Groups {
|
||||||
log.Debugf("loading group %v", group)
|
|
||||||
ss := NewStreamStore(ps.directory, group.LocalID, ps.password)
|
ss := NewStreamStore(ps.directory, group.LocalID, ps.password)
|
||||||
group.Timeline.SetMessages(ss.Read())
|
group.Timeline.SetMessages(ss.Read())
|
||||||
ps.streamStores[group.GroupID] = ss
|
ps.streamStores[group.GroupID] = ss
|
||||||
log.Debugf("loading group %v", group)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,13 +137,20 @@ func (ps *profileStore) eventHandler() {
|
||||||
log.Errorf("error setting attribute on peer %v peer does not exist", ev)
|
log.Errorf("error setting attribute on peer %v peer does not exist", ev)
|
||||||
}
|
}
|
||||||
case event.SetGroupAttribute:
|
case event.SetGroupAttribute:
|
||||||
group, exists := ps.profile.Groups[ev.Data[event.GroupID]]
|
group := ps.profile.GetGroupByGroupID(ev.Data[event.GroupID])
|
||||||
if exists {
|
if group != nil {
|
||||||
group.SetAttribute(ev.Data[event.Key], ev.Data[event.Data])
|
group.SetAttribute(ev.Data[event.Key], ev.Data[event.Data])
|
||||||
ps.save()
|
ps.save()
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("error setting attribute on group %v group does not exist", ev)
|
log.Errorf("error setting attribute on group %v group does not exist", ev)
|
||||||
}
|
}
|
||||||
|
case event.AcceptGroupInvite:
|
||||||
|
err := ps.profile.AcceptInvite(ev.Data[event.GroupID])
|
||||||
|
if err == nil {
|
||||||
|
ps.save()
|
||||||
|
} else {
|
||||||
|
log.Errorf("error accepting group invite")
|
||||||
|
}
|
||||||
case event.NewGroupInvite:
|
case event.NewGroupInvite:
|
||||||
var gci protocol.GroupChatInvite
|
var gci protocol.GroupChatInvite
|
||||||
err := proto.Unmarshal([]byte(ev.Data[event.GroupInvite]), &gci)
|
err := proto.Unmarshal([]byte(ev.Data[event.GroupInvite]), &gci)
|
||||||
|
|
Loading…
Reference in New Issue