2022-01-15 22:19:29 +01:00
|
|
|
package meowlib
|
2021-10-18 21:05:44 +02:00
|
|
|
|
2022-01-15 22:19:29 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Contact struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
ContactPublicKey string `json:"contact_public_key,omitempty"`
|
|
|
|
EncryptionPublicKey string `json:"encryption_public_key,omitempty"`
|
|
|
|
LookupPublicKey string `json:"lookup_public_key,omitempty"`
|
|
|
|
PullServers []Server `json:"pull_servers,omitempty"`
|
|
|
|
}
|
2021-10-18 21:05:44 +02:00
|
|
|
|
|
|
|
type Peer struct {
|
2022-01-15 22:19:29 +01:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Me KeyPair `json:"me,omitempty"`
|
|
|
|
Contact Contact `json:"contact,omitempty"`
|
|
|
|
Visible bool `json:"visible,omitempty"`
|
|
|
|
VisiblePassword string `json:"visible_password,omitempty"`
|
|
|
|
PasswordType string `json:"password_type,omitempty"`
|
|
|
|
Blocked bool `json:"blocked,omitempty"`
|
|
|
|
MessageNotification string `json:"message_notification,omitempty"`
|
|
|
|
OnionMode bool `json:"onion_mode,omitempty"`
|
|
|
|
Conversation []InternalMessage `json:"convdersation,omitempty"`
|
|
|
|
LastMessage time.Time `json:"last_message,omitempty"`
|
|
|
|
EncryptionKp KeyPair `json:"conversation_kp,omitempty"`
|
|
|
|
LookupKp KeyPair `json:"lookup_kp,omitempty"`
|
2021-10-18 21:05:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type PeerList []Peer
|
|
|
|
|
2022-01-15 22:19:29 +01:00
|
|
|
type Group struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Members []Contact `json:"members,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:05:44 +02:00
|
|
|
func (pl *PeerList) GetFromPublicKey(publickey string) *Peer {
|
|
|
|
for _, peer := range *pl {
|
2022-01-15 22:19:29 +01:00
|
|
|
if peer.Contact.ContactPublicKey == publickey {
|
2021-10-18 21:05:44 +02:00
|
|
|
return &peer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-01-15 22:19:29 +01:00
|
|
|
|
|
|
|
func (pl *PeerList) GetFromName(name string) *Peer {
|
|
|
|
for _, peer := range *pl {
|
|
|
|
if peer.Contact.Name == name {
|
|
|
|
return &peer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (peer *Peer) SendText(text string) {
|
|
|
|
im := CreateText(*peer, text)
|
|
|
|
fmt.Println(im.MessageData.Destination)
|
|
|
|
}
|