-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp_contacts.go
More file actions
64 lines (59 loc) · 1.63 KB
/
app_contacts.go
File metadata and controls
64 lines (59 loc) · 1.63 KB
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
package main
// GetContacts возвращает список контактов.
func (a *App) GetContacts() ([]*ContactInfo, error) {
coreContacts, err := a.core.GetContacts()
if err != nil {
return nil, err
}
// Маппим внутреннюю структуру в структуру фронтенда
result := make([]*ContactInfo, len(coreContacts))
for i, c := range coreContacts {
info := &ContactInfo{
ID: c.ID,
Nickname: c.Nickname,
PublicKey: c.PublicKey,
Avatar: c.Avatar,
I2PAddress: c.I2PAddress,
ChatID: c.ChatID,
UnreadCount: c.UnreadCount,
}
if c.LastMessage != "" {
info.LastMessage = c.LastMessage
}
if c.LastMessageTime != nil {
info.LastMessageTime = c.LastMessageTime.UnixMilli()
}
result[i] = info
}
return result, nil
}
// AddContact добавляет контакт.
func (a *App) AddContact(name, dest string) (*ContactInfo, error) {
c, err := a.core.AddContact(name, dest)
if err != nil {
return nil, err
}
return &ContactInfo{
ID: c.ID,
Nickname: c.Nickname,
I2PAddress: c.I2PAddress,
ChatID: c.ChatID,
}, nil
}
// AddContactFromClipboard добавляет контакт из буфера обмена.
func (a *App) AddContactFromClipboard(name string) (*ContactInfo, error) {
c, err := a.core.AddContactFromClipboard(name)
if err != nil {
return nil, err
}
return &ContactInfo{
ID: c.ID,
Nickname: c.Nickname,
I2PAddress: c.I2PAddress,
ChatID: c.ChatID,
}, nil
}
// DeleteContact удаляет контакт.
func (a *App) DeleteContact(id string) error {
return a.core.DeleteContact(id)
}