forked from cwtch.im/cwtch
Adding sync around timeline, adding hooks for latency checks
This commit is contained in:
parent
e01a4b2018
commit
b4eb27ae1d
|
@ -299,7 +299,8 @@ func main() {
|
|||
if group == nil {
|
||||
fmt.Printf("Error: group does not exist\n")
|
||||
} else {
|
||||
for _, m := range group.Timeline.Messages {
|
||||
timeline := group.GetTimeline()
|
||||
for _, m := range timeline.Messages {
|
||||
verified := "not-verified"
|
||||
if m.Verified {
|
||||
verified = "verified"
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"golang.org/x/crypto/nacl/secretbox"
|
||||
"io"
|
||||
"time"
|
||||
"sync"
|
||||
)
|
||||
|
||||
//Group defines and encapsulates Cwtch's conception of group chat. Which are sessions
|
||||
|
@ -21,6 +22,7 @@ type Group struct {
|
|||
Timeline Timeline
|
||||
Accepted bool
|
||||
Owner string
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
// NewGroup initializes a new group associated with a given CwtchServer
|
||||
|
@ -64,26 +66,27 @@ func (g *Group) Invite() []byte {
|
|||
}
|
||||
|
||||
func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, verified bool) *Message {
|
||||
g.lock.Lock()
|
||||
timelineMessage := &Message{
|
||||
Message: message.GetText(),
|
||||
Timestamp: time.Unix(int64(message.GetTimestamp()), 0),
|
||||
Received: time.Now(),
|
||||
Signature: message.GetSignature(),
|
||||
Verified: verified,
|
||||
PeerID: message.GetOnion(),
|
||||
PreviousMessageSig: message.GetPreviousMessageSig(),
|
||||
}
|
||||
g.Timeline.Insert(timelineMessage)
|
||||
g.lock.Unlock()
|
||||
return timelineMessage
|
||||
}
|
||||
|
||||
// AddMember ...
|
||||
func (g *Group) AddMember() {
|
||||
// TODO: Rotate Key
|
||||
}
|
||||
func (g *Group) GetTimeline() (t Timeline) {
|
||||
g.lock.Lock()
|
||||
t = g.Timeline
|
||||
g.lock.Unlock()
|
||||
return
|
||||
|
||||
// RemoveMember ...
|
||||
func (g *Group) RemoveMember() {
|
||||
// TODO: Rotate Key
|
||||
}
|
||||
|
||||
//EncryptMessage takes a message and encrypts the message under the group key.
|
||||
|
|
|
@ -14,6 +14,7 @@ type Timeline struct {
|
|||
// Message is a local representation of a given message sent over a group chat channel.
|
||||
type Message struct {
|
||||
Timestamp time.Time
|
||||
Received time.Time
|
||||
PeerID string
|
||||
Message string
|
||||
Signature []byte
|
||||
|
|
Loading…
Reference in New Issue