Merge branch 'syncContacts' of dan/ui into master
This commit is contained in:
commit
f973a2bfe5
|
@ -18,7 +18,6 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
|
|||
the.EventBus.Subscribe(event.NewGroupInvite, q.EventChannel)
|
||||
the.EventBus.Subscribe(event.SendMessageToGroupError, q.EventChannel)
|
||||
the.EventBus.Subscribe(event.SendMessageToPeerError, q.EventChannel)
|
||||
the.EventBus.Subscribe(event.JoinServer, q.EventChannel)
|
||||
the.EventBus.Subscribe(event.ServerStateChange, q.EventChannel)
|
||||
the.EventBus.Subscribe(event.PeerStateChange, q.EventChannel)
|
||||
subscribed <- true
|
||||
|
|
|
@ -308,7 +308,9 @@ func (this *GrandCentralDispatcher) savePeerSettings(onion, nick string) {
|
|||
event.Data: nick,
|
||||
}))
|
||||
|
||||
this.UIState.contacts[onion].DisplayName = nick
|
||||
cif, _ := this.UIState.contacts.Load(onion)
|
||||
c := cif.(*gobjects.Contact)
|
||||
c.DisplayName = nick
|
||||
this.UIState.UpdateContact(onion)
|
||||
}
|
||||
|
||||
|
@ -352,7 +354,9 @@ func (this *GrandCentralDispatcher) saveGroupSettings(groupID, nick string) {
|
|||
event.Data: nick,
|
||||
}))
|
||||
|
||||
this.UIState.contacts[groupID].DisplayName = nick
|
||||
cif, _ := this.UIState.contacts.Load(groupID)
|
||||
c := cif.(*gobjects.Contact)
|
||||
c.DisplayName = nick
|
||||
this.UIState.UpdateContact(groupID)
|
||||
}
|
||||
|
||||
|
|
|
@ -13,20 +13,20 @@ import (
|
|||
|
||||
type InterfaceState struct {
|
||||
parentGcd *GrandCentralDispatcher
|
||||
contacts map[string]*gobjects.Contact
|
||||
contacts sync.Map // string : *gobjects.Contact
|
||||
messages sync.Map
|
||||
}
|
||||
|
||||
func NewUIState(gcd *GrandCentralDispatcher) (uis InterfaceState) {
|
||||
uis = InterfaceState{gcd, make(map[string]*gobjects.Contact), sync.Map{}}
|
||||
uis = InterfaceState{gcd, sync.Map{}, sync.Map{}}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *InterfaceState) AddContact(c *gobjects.Contact) {
|
||||
if len(c.Handle) == 32 { // ADD GROUP
|
||||
if _, found := this.contacts[c.Handle]; !found {
|
||||
if _, found := this.contacts.Load(c.Handle); !found {
|
||||
this.parentGcd.AddContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted, c.Loading)
|
||||
this.contacts[c.Handle] = c
|
||||
this.contacts.Store(c.Handle, c)
|
||||
}
|
||||
return
|
||||
} else if len(c.Handle) != 56 {
|
||||
|
@ -35,8 +35,8 @@ func (this *InterfaceState) AddContact(c *gobjects.Contact) {
|
|||
return
|
||||
}
|
||||
|
||||
if _, found := this.contacts[c.Handle]; !found {
|
||||
this.contacts[c.Handle] = c
|
||||
if _, found := this.contacts.Load(c.Handle); !found {
|
||||
this.contacts.Store(c.Handle, c)
|
||||
this.parentGcd.AddContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted, false)
|
||||
if the.Peer.GetContact(c.Handle) == nil {
|
||||
the.Peer.AddContact(c.DisplayName, c.Handle, c.Trusted)
|
||||
|
@ -46,13 +46,17 @@ func (this *InterfaceState) AddContact(c *gobjects.Contact) {
|
|||
}
|
||||
|
||||
func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
|
||||
if _, found := this.contacts[handle]; !found {
|
||||
if _, found := this.contacts.Load(handle); !found {
|
||||
if len(handle) == 32 {
|
||||
group := the.Peer.GetGroup(handle)
|
||||
if group != nil {
|
||||
nick, exists := group.GetAttribute("nick")
|
||||
if !exists {
|
||||
nick = group.GroupID[:12]
|
||||
}
|
||||
this.AddContact(&gobjects.Contact{
|
||||
handle,
|
||||
handle,
|
||||
nick,
|
||||
cwutil.RandomGroupImage(handle),
|
||||
group.GroupServer,
|
||||
0,
|
||||
|
@ -68,9 +72,13 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
|
|||
} else {
|
||||
contact := the.Peer.GetContact(handle)
|
||||
if contact != nil && handle != contact.Onion {
|
||||
nick, exists := contact.GetAttribute("name")
|
||||
if !exists {
|
||||
nick = contact.Onion
|
||||
}
|
||||
this.AddContact(&gobjects.Contact{
|
||||
handle,
|
||||
handle,
|
||||
nick,
|
||||
cwutil.RandomProfileImage(handle),
|
||||
"",
|
||||
0,
|
||||
|
@ -84,7 +92,12 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
|
|||
}
|
||||
}
|
||||
|
||||
return this.contacts[handle]
|
||||
contactIntf, _ := this.contacts.Load(handle)
|
||||
if contactIntf == nil {
|
||||
return nil
|
||||
}
|
||||
contact := contactIntf.(*gobjects.Contact)
|
||||
return contact
|
||||
}
|
||||
|
||||
func (this *InterfaceState) AddSendMessageError(peer string, signature string, err string) {
|
||||
|
@ -166,8 +179,9 @@ func (this *InterfaceState) GetMessages(handle string) []*gobjects.Message {
|
|||
}
|
||||
|
||||
func (this *InterfaceState) UpdateContact(handle string) {
|
||||
c, found := this.contacts[handle]
|
||||
cif, found := this.contacts.Load(handle)
|
||||
if found {
|
||||
c := cif.(*gobjects.Contact)
|
||||
this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted, c.Loading)
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue