2023-11-08 21:52:09 +01:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"forge.redroom.link/yves/meowlib"
|
|
|
|
)
|
|
|
|
|
2024-03-02 10:07:59 +01:00
|
|
|
type PeerList []*Peer
|
2023-11-08 21:52:09 +01:00
|
|
|
|
|
|
|
func (pl *PeerList) GetFromPublicKey(publickey string) *Peer {
|
|
|
|
for _, peer := range *pl {
|
2024-02-10 22:36:25 +01:00
|
|
|
if peer.ContactPublicKey == publickey {
|
2024-03-02 10:07:59 +01:00
|
|
|
return peer
|
2023-11-08 21:52:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pl *PeerList) GetFromMyLookupKey(publickey string) *Peer {
|
|
|
|
for _, peer := range *pl {
|
|
|
|
if peer.MyLookupKp.Public == publickey {
|
2024-03-02 10:07:59 +01:00
|
|
|
return peer
|
2023-11-08 21:52:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pl *PeerList) GetFromName(name string) *Peer {
|
|
|
|
for _, peer := range *pl {
|
2024-02-10 22:36:25 +01:00
|
|
|
if peer.Name == name {
|
2024-03-02 10:07:59 +01:00
|
|
|
return peer
|
2023-11-08 21:52:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-14 15:49:24 +01:00
|
|
|
// ! Wrong implementation, does not discriminate on different servers
|
2023-11-08 21:52:09 +01:00
|
|
|
func (pl *PeerList) GetConversationRequests() []*meowlib.ConversationRequest {
|
|
|
|
var list []*meowlib.ConversationRequest
|
|
|
|
for _, peer := range *pl {
|
|
|
|
var cr meowlib.ConversationRequest
|
|
|
|
cr.LookupKey = peer.MyLookupKp.Public
|
|
|
|
// TODO Add key signature
|
|
|
|
list = append(list, &cr)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|