client: add option to manually acknowledge history syncs (#1100)
This commit is contained in:
1 parent
8528b5e027
commit
60c048850e
3 files changed
+55
-12
No files matched your search
@@ -100,9 +100,10 @@ type Client struct {
|
||||
appStateProc *appstate.Processor
|
||||
appStateSyncLock sync.Mutex
|
||||
|
||||
historySyncNotifications chan *waE2E.HistorySyncNotification
|
||||
historySyncHandlerStarted atomic.Bool
|
||||
ManualHistorySyncDownload bool
|
||||
historySyncNotifications chan *waE2E.HistorySyncNotification
|
||||
historySyncHandlerStarted atomic.Bool
|
||||
ManualHistorySyncDownload bool
|
||||
DisableManualHistorySyncReceipt bool
|
||||
|
||||
uploadPreKeysLock sync.Mutex
|
||||
lastPreKeyUpload time.Time
|
||||
|
||||
Generated
-4
@@ -391,10 +391,6 @@ func (int *DangerousInternalClient) HandleDecryptedMessage(ctx context.Context,
|
||||
return int.c.handleDecryptedMessage(ctx, info, msg, retryCount)
|
||||
}
|
||||
|
||||
func (int *DangerousInternalClient) SendProtocolMessageReceipt(ctx context.Context, id types.MessageID, msgType types.ReceiptType) {
|
||||
int.c.sendProtocolMessageReceipt(ctx, id, msgType)
|
||||
}
|
||||
|
||||
func (int *DangerousInternalClient) DecryptMsgSecret(ctx context.Context, msg *events.Message, useCase MsgSecretType, encrypted messageEncryptedSecret, origMsgKey *waCommon.MessageKey) ([]byte, error) {
|
||||
return int.c.decryptMsgSecret(ctx, msg, useCase, encrypted, origMsgKey)
|
||||
}
|
||||
|
||||
+51
-5
@@ -701,6 +701,38 @@ func (cli *Client) handleHistorySyncNotificationLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
// SendHistorySyncServerErrorReceipt sends a history sync server-error receipt, which
|
||||
// asks the phone to re-upload the referenced history sync payload.
|
||||
func (cli *Client) SendHistorySyncServerErrorReceipt(ctx context.Context, msgID types.MessageID, mediaKey []byte) error {
|
||||
ciphertext, iv, err := encryptMediaRetryReceipt(msgID, mediaKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encrypt history sync server-error receipt: %w", err)
|
||||
}
|
||||
ownID := cli.getOwnID().ToNonAD()
|
||||
if ownID.IsEmpty() {
|
||||
return ErrNotLoggedIn
|
||||
}
|
||||
err = cli.sendNode(ctx, waBinary.Node{
|
||||
Tag: "receipt",
|
||||
Attrs: waBinary.Attrs{
|
||||
"id": string(msgID),
|
||||
"type": "server-error",
|
||||
"to": ownID,
|
||||
"category": "peer",
|
||||
},
|
||||
Content: []waBinary.Node{
|
||||
{Tag: "encrypt", Content: []waBinary.Node{
|
||||
{Tag: "enc_p", Content: ciphertext},
|
||||
{Tag: "enc_iv", Content: iv},
|
||||
}},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to send history sync server-error receipt: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DownloadHistorySync will download and parse the history sync blob from the given history sync notification.
|
||||
//
|
||||
// You only need to call this manually if you set [Client.ManualHistorySyncDownload] to true.
|
||||
@@ -815,7 +847,14 @@ func (cli *Client) handleProtocolMessage(ctx context.Context, info *types.Messag
|
||||
go cli.handleHistorySyncNotificationLoop()
|
||||
}
|
||||
}
|
||||
go cli.sendProtocolMessageReceipt(ctx, info.ID, types.ReceiptTypeHistorySync)
|
||||
if !(cli.ManualHistorySyncDownload && cli.DisableManualHistorySyncReceipt) {
|
||||
go func() {
|
||||
err := cli.SendProtocolMessageReceipt(ctx, info.ID, types.ReceiptTypeHistorySync)
|
||||
if err != nil {
|
||||
cli.Log.Warnf("Failed to send acknowledgement for protocol message %s: %v", info.ID, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
if protoMsg.GetLidMigrationMappingSyncMessage() != nil {
|
||||
@@ -837,7 +876,12 @@ func (cli *Client) handleProtocolMessage(ctx context.Context, info *types.Messag
|
||||
}
|
||||
|
||||
if info.Category == "peer" {
|
||||
go cli.sendProtocolMessageReceipt(ctx, info.ID, types.ReceiptTypePeerMsg)
|
||||
go func() {
|
||||
err := cli.SendProtocolMessageReceipt(ctx, info.ID, types.ReceiptTypePeerMsg)
|
||||
if err != nil {
|
||||
cli.Log.Warnf("Failed to send acknowledgement for protocol message %s: %v", info.ID, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1047,9 +1091,10 @@ func (cli *Client) handleDecryptedMessage(ctx context.Context, info *types.Messa
|
||||
return cli.dispatchEvent(evt.UnwrapRaw())
|
||||
}
|
||||
|
||||
func (cli *Client) sendProtocolMessageReceipt(ctx context.Context, id types.MessageID, msgType types.ReceiptType) {
|
||||
// SendProtocolMessageReceipt sends a receipt for a protocol message back to the phone.
|
||||
func (cli *Client) SendProtocolMessageReceipt(ctx context.Context, id types.MessageID, msgType types.ReceiptType) error {
|
||||
if len(id) == 0 {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
err := cli.sendNode(ctx, waBinary.Node{
|
||||
Tag: "receipt",
|
||||
@@ -1061,6 +1106,7 @@ func (cli *Client) sendProtocolMessageReceipt(ctx context.Context, id types.Mess
|
||||
Content: nil,
|
||||
})
|
||||
if err != nil {
|
||||
cli.Log.Warnf("Failed to send acknowledgement for protocol message %s: %v", id, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user