Saving Messages

This commit is contained in:
Sarah Jamie Lewis 2018-11-28 12:34:49 -08:00
parent b5875453fb
commit 7a8e102b2a
1 changed files with 9 additions and 8 deletions

View File

@ -1,19 +1,19 @@
package gothings package gothings
import ( import (
"bounce/go/constants"
"bounce/go/gobjects"
"bounce/go/the"
"cwtch.im/cwtch/model" "cwtch.im/cwtch/model"
"encoding/base32" "encoding/base32"
"strings"
"log" "log"
"bounce/go/constants" "strings"
"bounce/go/the"
"bounce/go/gobjects"
) )
type InterfaceState struct { type InterfaceState struct {
parentGcd *GrandCentralDispatcher parentGcd *GrandCentralDispatcher
contacts map[string]*gobjects.Contact contacts map[string]*gobjects.Contact
messages map[string][]*gobjects.Message messages map[string][]*gobjects.Message
} }
func NewUIState(gcd *GrandCentralDispatcher) (uis InterfaceState) { func NewUIState(gcd *GrandCentralDispatcher) (uis InterfaceState) {
@ -39,7 +39,7 @@ func (this *InterfaceState) AddContact(c *gobjects.Contact) {
if the.Peer.GetContact(c.Handle) == nil { if the.Peer.GetContact(c.Handle) == nil {
decodedPub, _ := base32.StdEncoding.DecodeString(strings.ToUpper(c.Handle)) decodedPub, _ := base32.StdEncoding.DecodeString(strings.ToUpper(c.Handle))
pp := &model.PublicProfile{Name: c.DisplayName, Ed25519PublicKey: decodedPub[:32], Trusted: c.Trusted, Blocked:false, Onion:c.Handle, Attributes:make(map[string]string)} pp := &model.PublicProfile{Name: c.DisplayName, Ed25519PublicKey: decodedPub[:32], Trusted: c.Trusted, Blocked: false, Onion: c.Handle, Attributes: make(map[string]string)}
pp.SetAttribute("name", c.DisplayName) pp.SetAttribute("name", c.DisplayName)
the.Peer.GetProfile().Contacts[c.Handle] = pp the.Peer.GetProfile().Contacts[c.Handle] = pp
if c.Trusted { if c.Trusted {
@ -98,6 +98,7 @@ func (this *InterfaceState) AddMessage(m *gobjects.Message) {
c.Badge++ c.Badge++
this.UpdateContact(c.Handle) this.UpdateContact(c.Handle)
} }
the.CwtchApp.SaveProfile(the.Peer)
} }
func (this *InterfaceState) GetMessages(handle string) []*gobjects.Message { func (this *InterfaceState) GetMessages(handle string) []*gobjects.Message {
@ -113,4 +114,4 @@ func (this *InterfaceState) UpdateContact(handle string) {
if found { if found {
this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted) this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted)
} }
} }