Merge branch 'group-attributes' of cwtch.im/cwtch into master
This commit is contained in:
commit
6cce18120d
|
@ -26,6 +26,7 @@ type Group struct {
|
||||||
Owner string
|
Owner string
|
||||||
IsCompromised bool
|
IsCompromised bool
|
||||||
InitialMessage []byte
|
InitialMessage []byte
|
||||||
|
Attributes map[string]string
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
NewMessage chan Message `json:"-"`
|
NewMessage chan Message `json:"-"`
|
||||||
}
|
}
|
||||||
|
@ -49,6 +50,7 @@ func NewGroup(server string) (*Group, error) {
|
||||||
}
|
}
|
||||||
copy(group.GroupKey[:], groupKey[:])
|
copy(group.GroupKey[:], groupKey[:])
|
||||||
group.Owner = "self"
|
group.Owner = "self"
|
||||||
|
group.Attributes = make(map[string]string)
|
||||||
return group, nil
|
return group, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,3 +154,18 @@ func (g *Group) DecryptMessage(ciphertext []byte) (bool, *protocol.DecryptedGrou
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetAttribute allows applications to store arbitrary configuration info at the group level.
|
||||||
|
func (g *Group) SetAttribute(name string, value string) {
|
||||||
|
g.lock.Lock()
|
||||||
|
defer g.lock.Unlock()
|
||||||
|
g.Attributes[name] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAttribute returns the value of a value set with SetAttribute. If no such value has been set exists is set to false.
|
||||||
|
func (g *Group) GetAttribute(name string) (value string, exists bool) {
|
||||||
|
g.lock.Lock()
|
||||||
|
defer g.lock.Unlock()
|
||||||
|
value, exists = g.Attributes[name]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -23,5 +23,10 @@ func TestGroup(t *testing.T) {
|
||||||
t.Errorf("group encryption was invalid, or returned wrong message decrypted:%v message:%v", ok, message)
|
t.Errorf("group encryption was invalid, or returned wrong message decrypted:%v message:%v", ok, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
g.SetAttribute("test", "test_value")
|
||||||
|
value, exists := g.GetAttribute("test")
|
||||||
|
if !exists || value != "test_value" {
|
||||||
|
t.Errorf("Custom Attribute Should have been set, instead %v %v", exists, value)
|
||||||
|
}
|
||||||
t.Logf("Got message %v", message)
|
t.Logf("Got message %v", message)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue