Skip to content

Commit b90b12f

Browse files
committed
Send notes to self properly
1 parent 0cb6ec6 commit b90b12f

File tree

2 files changed

+46
-29
lines changed

2 files changed

+46
-29
lines changed

pkg/signalmeow/sending.go

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,29 @@ func (cli *Client) SendGroupMessage(ctx context.Context, gid types.GroupIdentifi
582582
return result, nil
583583
}
584584

585+
func (cli *Client) sendSyncCopy(ctx context.Context, content *signalpb.Content, messageTS uint64, result *SuccessfulSendResult) bool {
586+
// If we have other devices, send Sync messages to them too
587+
if cli.howManyOtherDevicesDoWeHave(ctx) > 0 {
588+
var syncContent *signalpb.Content
589+
if content.GetDataMessage() != nil {
590+
syncContent = syncMessageFromSoloDataMessage(content.DataMessage, *result)
591+
} else if content.GetEditMessage() != nil {
592+
syncContent = syncMessageFromSoloEditMessage(content.EditMessage, *result)
593+
} else if content.GetReceiptMessage().GetType() == signalpb.ReceiptMessage_READ {
594+
syncContent = syncMessageFromReadReceiptMessage(ctx, content.ReceiptMessage, result.RecipientUUID)
595+
}
596+
if syncContent != nil {
597+
_, selfSendErr := cli.sendContent(ctx, cli.Store.ACI, messageTS, syncContent, 0)
598+
if selfSendErr != nil {
599+
zerolog.Ctx(ctx).Err(selfSendErr).Msg("Failed to send sync message to myself")
600+
} else {
601+
return true
602+
}
603+
}
604+
}
605+
return false
606+
}
607+
585608
func (cli *Client) SendMessage(ctx context.Context, recipientID uuid.UUID, content *signalpb.Content) SendMessageResult {
586609
// Assemble the content to send
587610
var messageTimestamp uint64
@@ -593,6 +616,19 @@ func (cli *Client) SendMessage(ctx context.Context, recipientID uuid.UUID, conte
593616
messageTimestamp = currentMessageTimestamp()
594617
}
595618

619+
isDeliveryReceipt := content.ReceiptMessage != nil && content.GetReceiptMessage().GetType() == signalpb.ReceiptMessage_DELIVERY
620+
if recipientID == cli.Store.ACI && !isDeliveryReceipt {
621+
res := &SuccessfulSendResult{
622+
RecipientUUID: recipientID,
623+
Unidentified: false,
624+
}
625+
ok := cli.sendSyncCopy(ctx, content, messageTimestamp, res)
626+
return SendMessageResult{
627+
WasSuccessful: ok,
628+
SuccessfulSendResult: res,
629+
}
630+
}
631+
596632
// Send to the recipient
597633
sentUnidentified, err := cli.sendContent(ctx, recipientID, messageTimestamp, content, 0)
598634
if err != nil {
@@ -612,28 +648,8 @@ func (cli *Client) SendMessage(ctx context.Context, recipientID uuid.UUID, conte
612648
},
613649
}
614650

615-
// TODO: don't fetch every time
616-
// (But for now this makes sure we know about all our other devices)
617-
// ((Actually I don't think this is necessary?))
618-
//FetchAndProcessPreKey(ctx, device, device.Data.ACI, -1)
651+
cli.sendSyncCopy(ctx, content, messageTimestamp, result.SuccessfulSendResult)
619652

620-
// If we have other devices, send Sync messages to them too
621-
if cli.howManyOtherDevicesDoWeHave(ctx) > 0 {
622-
var syncContent *signalpb.Content
623-
if content.GetDataMessage() != nil {
624-
syncContent = syncMessageFromSoloDataMessage(content.DataMessage, *result.SuccessfulSendResult)
625-
} else if content.GetEditMessage() != nil {
626-
syncContent = syncMessageFromSoloEditMessage(content.EditMessage, *result.SuccessfulSendResult)
627-
} else if content.GetReceiptMessage().GetType() == signalpb.ReceiptMessage_READ {
628-
syncContent = syncMessageFromReadReceiptMessage(ctx, content.ReceiptMessage, recipientID)
629-
}
630-
if syncContent != nil {
631-
_, selfSendErr := cli.sendContent(ctx, cli.Store.ACI, messageTimestamp, syncContent, 0)
632-
if selfSendErr != nil {
633-
zerolog.Ctx(ctx).Err(selfSendErr).Msg("Failed to send sync message to myself")
634-
}
635-
}
636-
}
637653
return result
638654
}
639655

portal.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,13 @@ func (portal *Portal) GetRelayUser() *User {
267267
return portal.relayUser
268268
}
269269

270-
func isUUID(s string) bool {
271-
if _, uuidErr := uuid.Parse(s); uuidErr == nil {
272-
return true
273-
}
274-
return false
270+
func (portal *Portal) IsPrivateChat() bool {
271+
return portal.UserID() != uuid.Nil
275272
}
276273

277-
func (portal *Portal) IsPrivateChat() bool {
278-
// If ChatID is a UUID, it's a private chat, otherwise it's base64 and a group chat
279-
return isUUID(portal.ChatID)
274+
func (portal *Portal) IsNoteToSelf() bool {
275+
userID := portal.UserID()
276+
return userID != uuid.Nil && userID == portal.Receiver
280277
}
281278

282279
func (portal *Portal) MainIntent() *appservice.IntentAPI {
@@ -1264,6 +1261,10 @@ func (portal *Portal) setTyping(userIDs []id.UserID, isTyping bool) {
12641261
}
12651262

12661263
func (portal *Portal) HandleMatrixTyping(newTyping []id.UserID) {
1264+
if portal.IsNoteToSelf() {
1265+
return
1266+
}
1267+
12671268
portal.currentlyTypingLock.Lock()
12681269
defer portal.currentlyTypingLock.Unlock()
12691270
startedTyping, stoppedTyping := typingDiff(portal.currentlyTyping, newTyping)

0 commit comments

Comments
 (0)