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
/
Copy pathevents.go
77 lines (62 loc) · 1.91 KB
/
events.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
package main
import (
"fmt"
"github.com/katzenpost/catshadow"
"github.com/katzenpost/client"
)
func eventLoop(events <-chan interface{}, conversationModel *ConversationModel, contactListModel *ContactListModel) {
for {
ev, ok := <-events
if !ok {
return
}
handleEvent(ev, conversationModel, contactListModel)
}
}
func handleEvent(ev interface{}, conversationModel *ConversationModel, contactListModel *ContactListModel) {
switch event := ev.(type) {
case *client.ConnectionStatusEvent:
status := "Connecting..."
if event.IsConnected {
status = "Connected"
}
if event.Err != nil {
status = "Disconnected"
accountBridge.SetError(event.Err.Error())
}
accountBridge.SetStatus(status)
case *catshadow.KeyExchangeCompletedEvent:
fmt.Println(event.Nickname, event.Err)
if event.Err != nil {
accountBridge.SetError(event.Err.Error())
return
}
contactListModel.updateContactStatus(event.Nickname, true)
case *catshadow.MessageSentEvent:
conversationModel.updateMessageStatus(string(event.MessageID[:]), StatusSent)
case *catshadow.MessageNotSentEvent:
// XXX: conversationModel.updateMessageStatus(string(event.MessageID[:]), StatusNotSent)
return
case *catshadow.MessageDeliveredEvent:
conversationModel.updateMessageStatus(string(event.MessageID[:]), StatusDelivered)
case *catshadow.MessageReceivedEvent:
switch config.Notification {
case "Full":
notify("catchat", "New message received from "+event.Nickname)
case "Anonymized":
notify("catchat", "New message received")
}
if accountBridge.Recipient() != event.Nickname {
return
}
var m = NewMessage(nil)
m.Nickname = event.Nickname
m.Avatar = "" // FIXME: add avatar
m.Message = string(event.Message)
m.Timestamp = event.Timestamp
conversationModel.AppendMessage(m)
default:
// This case indicates a programming BUG!
panic(fmt.Sprintf("%s is an unknown event received, aborting", event))
}
}