Skip to content

Commit 1ba7eba

Browse files
committed
appstate: add syncd recovery request builder
1 parent 83db047 commit 1ba7eba

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

appstate.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -522,22 +522,12 @@ func (cli *Client) MarkNotDirty(ctx context.Context, cleanType string, ts time.T
522522
return err
523523
}
524524

525-
func (cli *Client) SendFatalAppStateExceptionNotification(ctx context.Context, collections ...appstate.WAPatchName) (SendResponse, error) {
526-
if len(collections) == 0 {
527-
return SendResponse{}, nil
528-
}
529-
return cli.SendMessage(
530-
ctx,
531-
cli.getOwnID().ToNonAD(),
532-
BuildFatalAppStateExceptionNotification(collections...),
533-
SendRequestExtra{Peer: true},
534-
)
535-
}
536-
525+
// BuildFatalAppStateExceptionNotification builds a message to request the user's primary device
526+
// to reset specific app state collections. This will cause all linked devices to be logged out.
527+
//
528+
// The built message can be sent using Client.SendPeerMessage.
529+
// There is no response, as the client will get logged out.
537530
func BuildFatalAppStateExceptionNotification(collections ...appstate.WAPatchName) *waE2E.Message {
538-
if len(collections) == 0 {
539-
return nil
540-
}
541531
return &waE2E.Message{
542532
ProtocolMessage: &waE2E.ProtocolMessage{
543533
Type: waE2E.ProtocolMessage_APP_STATE_FATAL_EXCEPTION_NOTIFICATION.Enum(),
@@ -548,3 +538,23 @@ func BuildFatalAppStateExceptionNotification(collections ...appstate.WAPatchName
548538
},
549539
}
550540
}
541+
542+
// BuildAppStateRecoveryRequest builds a message to request the user's primary device to send
543+
// an unencrypted copy of the given app state collection.
544+
//
545+
// The built message can be sent using Client.SendPeerMessage.
546+
// The response will come as a ProtocolMessage with type `PEER_DATA_OPERATION_RESPONSE_MESSAGE`.
547+
func BuildAppStateRecoveryRequest(collection appstate.WAPatchName) *waE2E.Message {
548+
return &waE2E.Message{
549+
ProtocolMessage: &waE2E.ProtocolMessage{
550+
Type: waE2E.ProtocolMessage_PEER_DATA_OPERATION_REQUEST_MESSAGE.Enum(),
551+
PeerDataOperationRequestMessage: &waE2E.PeerDataOperationRequestMessage{
552+
PeerDataOperationRequestType: waE2E.PeerDataOperationRequestType_COMPANION_SYNCD_SNAPSHOT_FATAL_RECOVERY.Enum(),
553+
SyncdCollectionFatalRecoveryRequest: &waE2E.PeerDataOperationRequestMessage_SyncDCollectionFatalRecoveryRequest{
554+
CollectionName: (*string)(&collection),
555+
Timestamp: ptr.Ptr(time.Now().Unix()),
556+
},
557+
},
558+
},
559+
}
560+
}

send.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,14 @@ func (cli *Client) SendMessage(ctx context.Context, to types.JID, message *waE2E
461461
return
462462
}
463463

464+
func (cli *Client) SendPeerMessage(ctx context.Context, message *waE2E.Message) (SendResponse, error) {
465+
ownID := cli.getOwnID()
466+
if ownID.IsEmpty() {
467+
return SendResponse{}, ErrNotLoggedIn
468+
}
469+
return cli.SendMessage(ctx, ownID, message, SendRequestExtra{Peer: true})
470+
}
471+
464472
// RevokeMessage deletes the given message from everyone in the chat.
465473
//
466474
// This method will wait for the server to acknowledge the revocation message before returning.
@@ -526,7 +534,7 @@ func (cli *Client) BuildReaction(chat, sender types.JID, id types.MessageID, rea
526534
// BuildUnavailableMessageRequest builds a message to request the user's primary device to send
527535
// the copy of a message that this client was unable to decrypt.
528536
//
529-
// The built message can be sent using Client.SendMessage, but you must pass whatsmeow.SendRequestExtra{Peer: true} as the last parameter.
537+
// The built message can be sent using Client.SendPeerMessage.
530538
// The full response will come as a ProtocolMessage with type `PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE`.
531539
// The response events will also be dispatched as normal *events.Message's with UnavailableRequestID set to the request message ID.
532540
func (cli *Client) BuildUnavailableMessageRequest(chat, sender types.JID, id string) *waE2E.Message {
@@ -545,7 +553,7 @@ func (cli *Client) BuildUnavailableMessageRequest(chat, sender types.JID, id str
545553

546554
// BuildHistorySyncRequest builds a message to request additional history from the user's primary device.
547555
//
548-
// The built message can be sent using Client.SendMessage, but you must pass whatsmeow.SendRequestExtra{Peer: true} as the last parameter.
556+
// The built message can be sent using Client.SendPeerMessage.
549557
// The response will come as an *events.HistorySync with type `ON_DEMAND`.
550558
//
551559
// The response will contain to `count` messages immediately before the given message.

0 commit comments

Comments
 (0)