Skip to content

Commit

Permalink
[libcommhistory] Always use matchesPhoneNumber for phone numbers. Con…
Browse files Browse the repository at this point in the history
…tributes to JB#38835
  • Loading branch information
Timur Kristóf committed Jan 29, 2020
1 parent eaa3464 commit 713fede
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/recipient.cpp
Expand Up @@ -206,8 +206,15 @@ bool Recipient::matches(const Recipient &o) const
return false;
if (!d->isPhoneNumber && d->localUid != o.d->localUid)
return false;

// Phone numbers are a special case
if (d->isPhoneNumber)
return matchesPhoneNumber(o.toPhoneNumberMatchDetails());

// For non-phonenumbers, matching the minimized remote uid is sufficient
if (!d->minimizedRemoteUid.isEmpty() || !o.d->minimizedRemoteUid.isEmpty())
return d->minimizedRemoteUid == o.d->minimizedRemoteUid;

return d->remoteUid == o.d->remoteUid;
}

Expand All @@ -222,6 +229,10 @@ bool Recipient::isSameContact(const Recipient &o) const

bool Recipient::matchesRemoteUid(const QString &o) const
{
// Phone numbers are a special case
if (d->isPhoneNumber)
return matchesPhoneNumber(Recipient::phoneNumberMatchDetails(o));

const QString minimizedMatch(::minimizeRemoteUid(o, d->isPhoneNumber));
if (!minimizedMatch.isEmpty())
return d->minimizedRemoteUid == minimizedMatch;
Expand Down Expand Up @@ -334,6 +345,21 @@ Recipient::PhoneNumberMatchDetails Recipient::phoneNumberMatchDetails(const QStr
return rv;
}

Recipient::PhoneNumberMatchDetails Recipient::toPhoneNumberMatchDetails() const
{
Q_ASSERT(d->isPhoneNumber);

if (d->minimizedRemoteUid.isEmpty() || d->remoteUidHash == 0) {
return phoneNumberMatchDetails(d->remoteUid);
}

PhoneNumberMatchDetails det;
det.number = d->remoteUid;
det.minimizedNumber = d->minimizedRemoteUid;
det.minimizedNumberHash = d->remoteUidHash;
return det;
}

RecipientList::RecipientList()
{
}
Expand Down
4 changes: 4 additions & 0 deletions src/recipient.h
Expand Up @@ -141,6 +141,10 @@ class LIBCOMMHISTORY_EXPORT Recipient
*/
static PhoneNumberMatchDetails phoneNumberMatchDetails(const QString &s);

/* Represent the current recipient as suitable for phone number matching
*/
PhoneNumberMatchDetails toPhoneNumberMatchDetails() const;

private:
QSharedPointer<RecipientPrivate> d;

Expand Down

0 comments on commit 713fede

Please sign in to comment.