diff --git a/model/group.go b/model/group.go index 0ec8c86..aaa2ddb 100644 --- a/model/group.go +++ b/model/group.go @@ -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 { diff --git a/storage/v1/profile_store.go b/storage/v1/profile_store.go index 1c5f22b..709ffe5 100644 --- a/storage/v1/profile_store.go +++ b/storage/v1/profile_store.go @@ -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