forked from cwtch.im/cwtch
1
0
Fork 0

Group V2 Logic

This commit is contained in:
Sarah Jamie Lewis 2020-09-28 11:18:18 -07:00
parent 1e34eb67a7
commit 6739df68c3
2 changed files with 13 additions and 0 deletions

View File

@ -14,6 +14,9 @@ import (
"time"
)
// CurrentGroupVersion is used to set the version of newly created groups and make sure group structs stored are correct and up to date
const CurrentGroupVersion = 2
// Group defines and encapsulates Cwtch's conception of group chat. Which are sessions
// tied to a server under a given group key. Each group has a set of Messages.
type Group struct {
@ -31,11 +34,13 @@ type Group struct {
LocalID string
State string `json:"-"`
unacknowledgedMessages []Message
Version int
}
// NewGroup initializes a new group associated with a given CwtchServer
func NewGroup(server string) (*Group, error) {
group := new(Group)
group.Version = CurrentGroupVersion
group.LocalID = GenerateRandomID()
if tor.IsValidHostname(server) == false {

View File

@ -247,6 +247,7 @@ func (ps *ProfileStoreV1) load() error {
}
cp := new(model.Profile)
err = json.Unmarshal(decrypted, &cp)
if err == nil {
ps.profile = cp
@ -275,12 +276,19 @@ func (ps *ProfileStoreV1) load() error {
}
for gid, group := range cp.Groups {
if group.Version == 0 {
log.Infof("group %v is of unsupported version 0. dropping group...\n", group.GroupID)
delete(cp.Groups, gid)
continue
}
ss := NewStreamStore(ps.directory, group.LocalID, ps.key)
cp.Groups[gid].Timeline.SetMessages(ss.Read())
ps.streamStores[group.GroupID] = ss
}
ps.save()
}
return err