Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
add the uuid to all message handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Feb 9, 2021
1 parent fa5491c commit 31abfa2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-redis/redis v6.15.7+incompatible h1:3skhDh95XQMpnqeqNftPkQD9jL9e5e36z/1SUm6dy1U=
github.com/go-redis/redis v6.15.7+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
Expand Down
2 changes: 1 addition & 1 deletion sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// handleSyncMessage handles an incoming SyncMessage.
func handleSyncMessage(src string, timestamp uint64, sm *signalservice.SyncMessage) error {
func handleSyncMessage(src string, srcUUID string, timestamp uint64, sm *signalservice.SyncMessage) error {
log.Debugf("[textsecure] SyncMessage recieved at %d", timestamp)

if sm.GetSent() != nil {
Expand Down
70 changes: 49 additions & 21 deletions textsecure.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ type Client struct {
GetVerificationCode func() string
GetPin func() string
GetStoragePassword func() string
GetCaptchaToken func() string
GetCaptchaToken func() string
GetConfig func() (*Config, error)
GetLocalContacts func() ([]Contact, error)
MessageHandler func(*Message)
Expand Down Expand Up @@ -331,8 +331,8 @@ func registerDevice() error {
transport.SetupTransporter(config.Server, config.Tel, registrationInfo.password, config.UserAgent, config.ProxyServer)
// try to register without token
code, responseCode, err := requestCode(config.Tel, config.VerificationType, "")
if responseCode != nil{
if *responseCode == responseNeedCaptcha{
if responseCode != nil {
if *responseCode == responseNeedCaptcha {
// Need to generate a token on https://signalcaptchas.org/registration/generate.html
log.Infoln("[textsecure] registration needs captcha")

Expand All @@ -344,7 +344,7 @@ func registerDevice() error {
} else {
return err
}
} else if err != nil {
} else if err != nil {
return err
}
if config.VerificationType != "dev" {
Expand Down Expand Up @@ -414,13 +414,13 @@ func handleMessage(srcE164 string, srcUUID string, timestamp uint64, b []byte) e
if dm := content.GetDataMessage(); dm != nil {
return handleDataMessage(srcE164, srcUUID, timestamp, dm)
} else if sm := content.GetSyncMessage(); sm != nil && config.Tel == srcE164 {
return handleSyncMessage(srcUUID, timestamp, sm)
return handleSyncMessage(srcE164, srcUUID, timestamp, sm)
} else if cm := content.GetCallMessage(); cm != nil {
return handleCallMessage(srcUUID, timestamp, cm)
return handleCallMessage(srcE164, srcUUID, timestamp, cm)
} else if rm := content.GetReceiptMessage(); rm != nil {
return handleReceiptMessage(srcUUID, timestamp, rm)
return handleReceiptMessage(srcE164, srcUUID, timestamp, rm)
} else if tm := content.GetTypingMessage(); tm != nil {
return handleTypingMessage(srcUUID, timestamp, tm)
return handleTypingMessage(srcE164, srcUUID, timestamp, tm)
}

//FIXME get the right content
Expand Down Expand Up @@ -460,8 +460,8 @@ func handleDataMessage(src string, srcUUID string, timestamp uint64, dm *signals
return err
}
msg := &Message{
sourceUUID: srcUUID,
source: src,
sourceUUID: srcUUID,
message: dm.GetBody(),
attachments: atts,
group: gr,
Expand All @@ -483,37 +483,65 @@ func handleDataMessage(src string, srcUUID string, timestamp uint64, dm *signals
}
return nil
}
func handleCallMessage(src string, timestamp uint64, cm *signalservice.CallMessage) error {
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,
message: "callMessage",
timestamp: timestamp,
source: src,
sourceUUID: srcUUID,
message: message,
timestamp: timestamp,
}

if client.MessageHandler != nil {
client.MessageHandler(msg)
}
return nil
}
func handleTypingMessage(src string, timestamp uint64, cm *signalservice.TypingMessage) error {
func handleTypingMessage(src string, srcUUID string, timestamp uint64, cm *signalservice.TypingMessage) error {

msg := &Message{
source: src,
message: "typingMessage",
timestamp: timestamp,
source: src,
sourceUUID: srcUUID,
message: "typingMessage",
timestamp: timestamp,
}

if client.TypingMessageHandler != nil {
client.TypingMessageHandler(msg)
}
return nil
}
func handleReceiptMessage(src string, timestamp uint64, cm *signalservice.ReceiptMessage) error {
func handleReceiptMessage(src string, srcUUID string, timestamp uint64, cm *signalservice.ReceiptMessage) error {
msg := &Message{
source: src,
message: "sentReceiptMessage",
timestamp: cm.GetTimestamp()[0],
source: src,
sourceUUID: srcUUID,
message: "sentReceiptMessage",
timestamp: cm.GetTimestamp()[0],
}
if *cm.Type == signalservice.ReceiptMessage_READ {
msg.message = "readReceiptMessage"
Expand Down

0 comments on commit 31abfa2

Please sign in to comment.