This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
handler.go
155 lines (141 loc) · 4.16 KB
/
handler.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package textsecure
import (
"github.com/golang/protobuf/proto"
"github.com/signal-golang/textsecure/groupsv2"
signalservice "github.com/signal-golang/textsecure/protobuf"
log "github.com/sirupsen/logrus"
)
func handleMessage(srcE164 string, srcUUID string, timestamp uint64, b []byte) error {
content := &signalservice.Content{}
err := proto.Unmarshal(b, content)
if err != nil {
log.Errorln("[textsecure] handleMessage umarshalling", err)
return err
}
log.Debugln("[textsecure] handleMessage")
if dm := content.GetDataMessage(); dm != nil {
return handleDataMessage(srcE164, srcUUID, timestamp, dm)
} else if sm := content.GetSyncMessage(); sm != nil {
return handleSyncMessage(srcE164, srcUUID, timestamp, sm)
} else if cm := content.GetCallMessage(); cm != nil {
return handleCallMessage(srcE164, srcUUID, timestamp, cm)
} else if rm := content.GetReceiptMessage(); rm != nil {
return handleReceiptMessage(srcE164, srcUUID, timestamp, rm)
} else if tm := content.GetTypingMessage(); tm != nil {
return handleTypingMessage(srcE164, srcUUID, timestamp, tm)
} else if nm := content.GetNullMessage(); nm != nil {
log.Errorln("[textsecure] Nullmessage content received", content)
return nil
}
//FIXME get the right content
// log.Errorf(content)
log.Errorln("[textsecure] Unknown message content received", content)
return nil
}
func handleTypingMessage(src string, srcUUID string, timestamp uint64, cm *signalservice.TypingMessage) error {
msg := &Message{
source: src,
sourceUUID: srcUUID,
message: "typingMessage",
timestamp: timestamp,
}
if client.TypingMessageHandler != nil {
client.TypingMessageHandler(msg)
}
return nil
}
func handleReceiptMessage(src string, srcUUID string, timestamp uint64, cm *signalservice.ReceiptMessage) error {
msg := &Message{
source: src,
sourceUUID: srcUUID,
message: "sentReceiptMessage",
timestamp: cm.GetTimestamp()[0],
}
if *cm.Type == signalservice.ReceiptMessage_READ {
msg.message = "readReceiptMessage"
}
if *cm.Type == signalservice.ReceiptMessage_DELIVERY {
msg.message = "deliveryReceiptMessage"
}
if client.ReceiptMessageHandler != nil {
client.ReceiptMessageHandler(msg)
}
return nil
}
// handleDataMessage handles an incoming DataMessage and calls client callbacks
func handleDataMessage(src string, srcUUID string, timestamp uint64, dm *signalservice.DataMessage) error {
flags, err := handleFlags(srcUUID, dm)
if err != nil {
return err
}
atts, err := handleAttachments(dm)
if err != nil {
return err
}
log.Debugln("[textsecure] handleDataMessage", timestamp, *dm.Timestamp, dm.GetExpireTimer())
gr2, err := groupsv2.HandleGroupsV2(src, dm)
if err != nil {
return err
}
msg := &Message{
source: src,
sourceUUID: srcUUID,
message: dm.GetBody(),
attachments: atts,
groupV2: gr2,
flags: flags,
expireTimer: dm.GetExpireTimer(),
profileKey: dm.GetProfileKey(),
timestamp: *dm.Timestamp,
quote: dm.GetQuote(),
contact: dm.GetContact(),
sticker: dm.GetSticker(),
reaction: dm.GetReaction(),
// requiredProtocolVersion: dm.GetRequiredProtocolVersion(),
// isViewOnce: *dm.IsViewOnce,
}
if client.MessageHandler != nil {
client.MessageHandler(msg)
}
return nil
}
func handleCallMessage(src string, srcUUID string, timestamp uint64, cm *signalservice.CallMessage) error {
message := "Call "
if m := cm.GetAnswer(); m != nil {
message += "answer"
}
if m := cm.GetOffer(); m != nil {
message += "offer"
}
if m := cm.GetHangup(); m != nil {
message += "hangup"
}
if m := cm.GetBusy(); m != nil {
message += "busy"
}
if m := cm.GetLegacyHangup(); m != nil {
message += "hangup"
}
// if m := cm.GetMultiRing(); m == true {
// message += "ring "
// }
if m := cm.GetIceUpdate(); m != nil {
message += "ring"
}
// if m := cm.GetOpaque(); m != nil {
// message += "opaque"
// }
msg := &Message{
source: src,
sourceUUID: srcUUID,
message: message,
timestamp: timestamp,
}
if client.MessageHandler != nil {
client.MessageHandler(msg)
}
return nil
}
func handleUnidentifiedSenderMessage(srcUUID string, timestamp uint64, sm *signalservice.SyncMessage) error {
return nil
}