erinn
/
ui
forked from cwtch.im/ui
1
0
Fork 0
ui/go/characters/cwtchlistener.go

37 lines
651 B
Go
Raw Normal View History

2018-11-22 00:01:17 +00:00
package characters
import (
2018-11-28 19:12:01 +00:00
"cwtch.im/cwtch/model"
2018-11-28 22:14:02 +00:00
"cwtch.im/ui/go/gobjects"
"cwtch.im/ui/go/the"
2018-11-22 00:01:17 +00:00
)
func CwtchListener(callback func(message *gobjects.Message), groupID string, channel chan model.Message) {
for {
m := <-channel
name := m.PeerID
if name == the.Peer.GetProfile().Onion {
name = "me"
} else {
2018-11-28 19:12:01 +00:00
contact := the.Peer.GetContact(m.PeerID)
if contact != nil {
name, _ = contact.GetAttribute("name")
} else {
name = m.PeerID[:16] + "..."
2018-11-22 00:01:17 +00:00
}
}
callback(&gobjects.Message{
groupID,
m.PeerID,
name,
m.Message,
"",
m.PeerID == the.Peer.GetProfile().Onion,
0,
m.Timestamp,
})
}
2018-11-28 19:12:01 +00:00
}