Browse Source

Merge branch 'groupimportfix' of cwtch.im/cwtch into master

pull/222/head
erinn Gogs 1 year ago
parent
commit
d15585eda7
3 changed files with 14 additions and 4 deletions
  1. +3
    -0
      event/common.go
  2. +1
    -0
      peer/cwtch_peer.go
  3. +10
    -4
      storage/profile_store.go

+ 3
- 0
event/common.go View File

@@ -24,6 +24,9 @@ const (
// GroupInvite: [eg "torv3....."]
NewGroupInvite = Type("NewGroupInvite")

// GroupID
AcceptGroupInvite = Type("AcceptGroupInvite")

SendMessageToGroup = Type("SendMessagetoGroup")
EncryptedGroupMessage = Type("EncryptedGroupMessage")
NewMessageFromGroup = Type("NewMessageFromGroup")


+ 1
- 0
peer/cwtch_peer.go View File

@@ -274,6 +274,7 @@ func (cp *cwtchPeer) BlockPeer(peer string) error {

// AcceptInvite accepts a given existing group invite
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)
}



+ 10
- 4
storage/profile_store.go View File

@@ -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.SetPeerAttribute, 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.NewMessageFromGroup, ps.queue.EventChannel)

@@ -83,11 +84,9 @@ func (ps *profileStore) Load() error {
}

for _, group := range cp.Groups {
log.Debugf("loading group %v", group)
ss := NewStreamStore(ps.directory, group.LocalID, ps.password)
group.Timeline.SetMessages(ss.Read())
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)
}
case event.SetGroupAttribute:
group, exists := ps.profile.Groups[ev.Data[event.GroupID]]
if exists {
group := ps.profile.GetGroupByGroupID(ev.Data[event.GroupID])
if group != nil {
group.SetAttribute(ev.Data[event.Key], ev.Data[event.Data])
ps.save()
} else {
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:
var gci protocol.GroupChatInvite
err := proto.Unmarshal([]byte(ev.Data[event.GroupInvite]), &gci)


Loading…
Cancel
Save