Navigation Menu

Skip to content

Commit

Permalink
[libcommhistory] Use minimized phone number to identify RecipientPriv…
Browse files Browse the repository at this point in the history
…ate instances. Fixes JB#52774

Minimized phone numbers are needed to compare numbers with different
country calling codes correctly. Also in case of phone numbers it should
in practice ignore localUid so instead of keeping it as is use only
RING_ACCOUNT (which is the prefix of localUid for phone numbers) to
identify those RecipientPrivate instances.

This fixes problems with commhistory-daemon unit tests.

It would be better to fix this so that libphonenumber was used to
compare these values and localUid was correctly handled but that would
require greater changes.

Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
  • Loading branch information
Tomin1 committed Apr 12, 2021
1 parent 251c21d commit 16073d9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/recipient.cpp
Expand Up @@ -48,6 +48,15 @@ quint32 addressFlagValues(quint64 statusFlags)
return statusFlags & (QContactStatusFlags::HasPhoneNumber | QContactStatusFlags::HasEmailAddress | QContactStatusFlags::HasOnlineAccount);
}

QPair<QString, QString> makeUidPair(const QString &localUid, const QString &remoteUid)
{
// If localUid is for phone number, use prefix alone to find the RecipientPrivate
// this avoids problems with different SIMs etc.
const bool usesPhoneNumberComparison = CommHistory::localUidComparesPhoneNumbers(localUid);
return qMakePair(usesPhoneNumberComparison ? CommHistory::RING_ACCOUNT : localUid,
::minimizeRemoteUid(remoteUid, usesPhoneNumberComparison));
}

}

bool recipient_initialized = initializeTypes();
Expand Down Expand Up @@ -135,7 +144,7 @@ RecipientPrivate::RecipientPrivate(const QString &local, const QString &remote)
RecipientPrivate::~RecipientPrivate()
{
if (!recipientInstances.isDestroyed()) {
recipientInstances->remove(qMakePair(localUid, remoteUid.toLower()));
recipientInstances->remove(makeUidPair(localUid, remoteUid));
}
}

Expand All @@ -145,7 +154,7 @@ QSharedPointer<RecipientPrivate> RecipientPrivate::get(const QString &localUid,
return *sharedNullRecipient;
}

const QPair<QString,QString> uids = qMakePair(localUid, remoteUid.toLower());
const QPair<QString, QString> uids = makeUidPair(localUid, remoteUid);
QSharedPointer<RecipientPrivate> instance = recipientInstances->value(uids);
if (!instance) {
instance = QSharedPointer<RecipientPrivate>(new RecipientPrivate(localUid, remoteUid));
Expand Down

0 comments on commit 16073d9

Please sign in to comment.