Update dependencies and remove old matterclient lib (#2067)

This commit is contained in:
Wim
2023-08-05 20:43:19 +02:00
committed by GitHub
parent 9459495484
commit 56e7bd01ca
772 changed files with 139315 additions and 121315 deletions

View File

@@ -169,7 +169,11 @@ func (cli *Client) handleRetryReceipt(receipt *events.Receipt, node *waBinary.No
return fmt.Errorf("didn't get prekey bundle for %s (response size: %d)", senderAD, len(keys))
}
}
encrypted, includeDeviceIdentity, err := cli.encryptMessageForDevice(plaintext, receipt.Sender, bundle)
encAttrs := waBinary.Attrs{}
if mediaType := getMediaTypeFromMessage(msg); mediaType != "" {
encAttrs["mediatype"] = mediaType
}
encrypted, includeDeviceIdentity, err := cli.encryptMessageForDevice(plaintext, receipt.Sender, bundle, encAttrs)
if err != nil {
return fmt.Errorf("failed to encrypt message for retry: %w", err)
}
@@ -193,14 +197,10 @@ func (cli *Client) handleRetryReceipt(receipt *events.Receipt, node *waBinary.No
if edit, ok := node.Attrs["edit"]; ok {
attrs["edit"] = edit
}
content := []waBinary.Node{*encrypted}
if includeDeviceIdentity {
content = append(content, cli.makeDeviceIdentityNode())
}
err = cli.sendNode(waBinary.Node{
Tag: "message",
Attrs: attrs,
Content: content,
Content: cli.getMessageContent(*encrypted, msg, attrs, includeDeviceIdentity),
})
if err != nil {
return fmt.Errorf("failed to send retry message: %w", err)
@@ -209,8 +209,63 @@ func (cli *Client) handleRetryReceipt(receipt *events.Receipt, node *waBinary.No
return nil
}
func (cli *Client) cancelDelayedRequestFromPhone(msgID types.MessageID) {
if !cli.AutomaticMessageRerequestFromPhone {
return
}
cli.pendingPhoneRerequestsLock.RLock()
cancelPendingRequest, ok := cli.pendingPhoneRerequests[msgID]
if ok {
cancelPendingRequest()
}
cli.pendingPhoneRerequestsLock.RUnlock()
}
// RequestFromPhoneDelay specifies how long to wait for the sender to resend the message before requesting from your phone.
// This is only used if Client.AutomaticMessageRerequestFromPhone is true.
var RequestFromPhoneDelay = 5 * time.Second
func (cli *Client) delayedRequestMessageFromPhone(info *types.MessageInfo) {
if !cli.AutomaticMessageRerequestFromPhone {
return
}
cli.pendingPhoneRerequestsLock.Lock()
_, alreadyRequesting := cli.pendingPhoneRerequests[info.ID]
if alreadyRequesting {
cli.pendingPhoneRerequestsLock.Unlock()
return
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cli.pendingPhoneRerequests[info.ID] = cancel
cli.pendingPhoneRerequestsLock.Unlock()
defer func() {
cli.pendingPhoneRerequestsLock.Lock()
delete(cli.pendingPhoneRerequests, info.ID)
cli.pendingPhoneRerequestsLock.Unlock()
}()
select {
case <-time.After(RequestFromPhoneDelay):
case <-ctx.Done():
cli.Log.Debugf("Cancelled delayed request for message %s from phone", info.ID)
return
}
_, err := cli.SendMessage(
ctx,
cli.Store.ID.ToNonAD(),
cli.BuildUnavailableMessageRequest(info.Chat, info.Sender, info.ID),
SendRequestExtra{Peer: true},
)
if err != nil {
cli.Log.Warnf("Failed to send request for unavailable message %s to phone: %v", info.ID, err)
} else {
cli.Log.Debugf("Requested message %s from phone", info.ID)
}
}
// sendRetryReceipt sends a retry receipt for an incoming message.
func (cli *Client) sendRetryReceipt(node *waBinary.Node, forceIncludeIdentity bool) {
func (cli *Client) sendRetryReceipt(node *waBinary.Node, info *types.MessageInfo, forceIncludeIdentity bool) {
id, _ := node.Attrs["id"].(string)
children := node.GetChildren()
var retryCountInMsg int
@@ -231,6 +286,9 @@ func (cli *Client) sendRetryReceipt(node *waBinary.Node, forceIncludeIdentity bo
cli.Log.Warnf("Not sending any more retry receipts for %s", id)
return
}
if retryCount == 1 {
go cli.delayedRequestMessageFromPhone(info)
}
var registrationIDBytes [4]byte
binary.BigEndian.PutUint32(registrationIDBytes[:], cli.Store.RegistrationID)