This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
account.go
83 lines (66 loc) · 1.97 KB
/
account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"sort"
"time"
"github.com/katzenpost/catshadow"
)
// loadContactList loads the contact list for an account
func loadContactList(contactListModel *ContactListModel, contacts map[string]*catshadow.Contact) {
for _, c := range contacts {
var contact = NewContact(nil)
contact.Nickname = c.Nickname
contact.KeyExchanged = !c.IsPending
// XXX contact.Avatar = "https://picsum.photos/128/128"
contactListModel.AddContact(contact)
}
}
// loadConversation loads the conversation with a contact
func loadConversation(client *catshadow.Client, contact string) {
c := contactListModel.getContact(contact)
if c == nil {
panic("Could not find unknown contact with name: " + contact)
}
accountBridge.SetRecipient(c.Nickname)
accountBridge.SetKeyExchanged(c.KeyExchanged)
conversationModel.Clear()
conversation := client.GetConversation(contact)
var msgs Messages
for _, message := range conversation {
var m = NewMessage(nil)
if message.Outbound {
m.Nickname = accountBridge.Nickname()
} else {
m.Nickname = c.Nickname
}
m.Avatar = ""
m.Message = string(message.Plaintext)
m.Timestamp = message.Timestamp
m.Outbound = message.Outbound
msgs = append(msgs, m)
}
sort.Sort(msgs)
for _, m := range msgs {
conversationModel.AddMessage(m)
}
}
// addContact adds a contact to the contact list
func addContact(client *catshadow.Client, nickname string, passphrase string) bool {
client.NewContact(nickname, []byte(passphrase))
var c = NewContact(nil)
c.Nickname = nickname
c.Avatar = ""
contactListModel.AddContact(c)
return true
}
// sendMessage sends a message to a contact
func sendMessage(client *catshadow.Client, nickname string, message string) {
id := client.SendMessage(nickname, []byte(message))
var m = NewMessage(nil)
m.MessageID = string(id[:])
m.Nickname = accountBridge.Nickname()
m.Avatar = accountBridge.Nickname()
m.Message = message
m.Timestamp = time.Now()
m.Outbound = true
conversationModel.AddMessage(m)
}