From 8ed7dd471ad6d441aae55a8c1f0d6e02f3cea784 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 23 Jul 2020 14:40:44 -0700 Subject: [PATCH] Small Fixes --- model/profile.go | 10 ++++------ peer/cwtch_peer.go | 4 +++- server/server_tokenboard.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/model/profile.go b/model/profile.go index 64f0577..39df5ce 100644 --- a/model/profile.go +++ b/model/profile.go @@ -78,12 +78,10 @@ func (p *PublicProfile) SetAttribute(name string, value string) { p.Attributes[name] = value } -// IsServer returns true if the onion address is associated with a server. -func (p *PublicProfile) IsServer(onion string) bool { - if _, isServer := p.GetAttribute(string(KeyTypeServerOnion)); isServer == true { - return true - } - return false +// IsServer returns true if the profile is associated with a server. +func (p *PublicProfile) IsServer() (isServer bool) { + _, isServer = p.GetAttribute(string(KeyTypeServerOnion)) + return } // GetAttribute returns the value of a value set with SetCustomAttribute. If no such value has been set exists is set to false. diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 68f84a8..31f0896 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -205,6 +205,9 @@ func (cp *cwtchPeer) AddContact(nick, onion string, authorization model.Authoriz cp.eventBus.Publish(event.NewEventList(event.SetPeerAttribute, event.RemotePeer, onion, event.SaveHistoryKey, event.DeleteHistoryDefault)) } +// AddServer takes in a serialized server specification (a bundle of related keys) and adds a contact for the +// server assuming there are no errors and the contact doesn't already exist. +// TODO in the future this function should also integrate with a trust provider to validate the key bundle. func (cp *cwtchPeer) AddServer(serverSpecification string) error { keyBundle := new(model.KeyBundle) err := json.Unmarshal([]byte(serverSpecification), &keyBundle) @@ -216,7 +219,6 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error { if cp.GetContact(onion) == nil { decodedPub, _ := base32.StdEncoding.DecodeString(strings.ToUpper(onion)) ab := keyBundle.AttributeBundle() - ab["nick"] = onion pp := &model.PublicProfile{Name: onion, Ed25519PublicKey: decodedPub, Authorization: model.AuthUnknown, Onion: onion, Attributes: ab} cp.Profile.AddContact(onion, pp) diff --git a/server/server_tokenboard.go b/server/server_tokenboard.go index 397a2c5..db35e3e 100644 --- a/server/server_tokenboard.go +++ b/server/server_tokenboard.go @@ -84,9 +84,9 @@ func (ta *TokenboardServer) Listen() { data, _ = json.Marshal(message) ta.connection.Send(data) } - newMessages := ta.LegacyMessageStore.FetchMessages() // Set sync and then send any new messages that might have happened while we were syncing ta.connection.SetCapability(groups.CwtchServerSyncedCapability) + newMessages := ta.LegacyMessageStore.FetchMessages() if len(newMessages) > len(messages) { for _, message := range newMessages[len(messages):] { data, _ = json.Marshal(groups.Message{MessageType: groups.NewMessageMessage, NewMessage: &groups.NewMessage{EGM: *message}})