This repository has been archived on 2021-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
ui/go/characters/presencepoller.go

47 lines
1.0 KiB
Go
Raw Normal View History

2018-11-22 00:01:17 +00:00
package characters
import (
2019-01-21 21:41:47 +00:00
"cwtch.im/cwtch/event"
2018-11-28 22:14:02 +00:00
"cwtch.im/ui/go/cwutil"
"cwtch.im/ui/go/gobjects"
"cwtch.im/ui/go/gothings"
2018-11-28 22:14:02 +00:00
"cwtch.im/ui/go/the"
2018-11-22 00:01:17 +00:00
"time"
)
func PresencePoller(uiState *gothings.InterfaceState) {
2018-11-22 00:01:17 +00:00
time.Sleep(time.Second * 4)
for {
contacts := the.Peer.GetContacts()
for i := range contacts {
ct := uiState.GetContact(contacts[i])
2018-11-22 00:01:17 +00:00
if ct == nil { // new contact has attempted to connect with us, treat it as an invite
toc := the.Peer.GetContact(contacts[i])
c, _ := the.Peer.GetProfile().GetContact(contacts[i])
deleted, _ := c.GetAttribute("deleted")
2019-01-28 19:57:44 +00:00
if deleted != "deleted" {
uiState.AddContact(&gobjects.Contact{
toc.Onion,
toc.Name,
cwutil.RandomProfileImage(toc.Onion),
"",
0,
0,
c.Trusted,
false,
})
the.EventBus.Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{
event.RemotePeer: contacts[i],
event.Key: "name",
event.Data: c.Name,
}))
}
2018-11-22 00:01:17 +00:00
}
}
time.Sleep(time.Second * 4)
}
2018-11-28 22:14:02 +00:00
}