package characters import ( "cwtch.im/cwtch/event" "cwtch.im/ui/go/cwutil" "cwtch.im/ui/go/gobjects" "cwtch.im/ui/go/gothings" "cwtch.im/ui/go/the" "time" ) func PresencePoller(uiState *gothings.InterfaceState) { time.Sleep(time.Second * 4) for { contacts := the.Peer.GetContacts() for i := range contacts { ct := uiState.GetContact(contacts[i]) 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") 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, })) } } } time.Sleep(time.Second * 4) } }