forked from Silverfish/proton-bridge
feat(GODT-2569): Support multiple externalID matching if we send one of it when looking for parentID.
Change behavior of `getParentID`: when `getParentID` gets called on an external ID and more than one message with that ID is found, inspect the metadata flags and if only one of those messages is `MessageFlagSent`, then choose that as the parent.
This commit is contained in:
@ -300,7 +300,9 @@ func getParentID(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If no parent was found, try to find it in the last external reference.
|
// If no parent was found, try to find it in the last external reference.
|
||||||
// There can be multiple messages with the same external ID; in this case, we don't pick any parent.
|
// There can be multiple messages with the same external ID; in this case, we first look if
|
||||||
|
// there is a single one sent by this account (with the `MessageFlagSent` flag set), if yes,
|
||||||
|
// then pick that, otherwise don't pick any parent.
|
||||||
if parentID == "" && len(external) > 0 {
|
if parentID == "" && len(external) > 0 {
|
||||||
var addrID string
|
var addrID string
|
||||||
|
|
||||||
@ -316,8 +318,25 @@ func getParentID(
|
|||||||
return "", fmt.Errorf("failed to get message metadata: %w", err)
|
return "", fmt.Errorf("failed to get message metadata: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(metadata) == 1 {
|
switch len(metadata) {
|
||||||
|
case 1:
|
||||||
|
// found exactly one parent
|
||||||
parentID = metadata[0].ID
|
parentID = metadata[0].ID
|
||||||
|
case 0:
|
||||||
|
// found no parents
|
||||||
|
default:
|
||||||
|
// found multiple parents, search through metadata to try to find a singular parent that
|
||||||
|
// was sent by this account.
|
||||||
|
found_sent_by_us := false
|
||||||
|
for _, metadata := range metadata {
|
||||||
|
if metadata.Flags.Has(proton.MessageFlagSent) {
|
||||||
|
if found_sent_by_us == true {
|
||||||
|
parentID = ""
|
||||||
|
}
|
||||||
|
parentID = metadata.ID
|
||||||
|
found_sent_by_us = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user