Added searching on both fields all the time and generalized check for address
This commit is contained in:
parent
518f161b4f
commit
cd0259aba6
7 changed files with 35 additions and 31 deletions
|
@ -285,7 +285,7 @@ void ConversationListModel::createConversationForAddress(const QString& address)
|
|||
appendRow(item);
|
||||
}
|
||||
|
||||
bool ConversationListModel::isPhoneNumberValid(const QString& number)
|
||||
bool ConversationListModel::isAddressValid(const QString& address)
|
||||
{
|
||||
return SmsHelper::isPhoneNumberValid(number);
|
||||
return SmsHelper::isAddressValid(address);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
* TODO: This is here because I don't know how to make the QML call the smshelper directly
|
||||
* but that is what should be happening!
|
||||
*/
|
||||
Q_INVOKABLE bool isPhoneNumberValid(const QString& number);
|
||||
Q_INVOKABLE bool isAddressValid(const QString& address);
|
||||
|
||||
/**
|
||||
* This method creates conversation with an arbitrary address
|
||||
|
|
|
@ -46,9 +46,9 @@ bool ConversationsSortFilterProxyModel::lessThan(const QModelIndex& leftIndex, c
|
|||
{
|
||||
// This if block checks for multitarget conversations and sorts it at bottom of the list when the filtring is done on the basis of SenderRole
|
||||
// This keeps the individual contacts with matching address at the top of the list
|
||||
if (filterRole() == ConversationListModel::SenderRole) {
|
||||
if (filterRole() == ConversationListModel::AddressesRole) {
|
||||
const bool isLeftMultitarget = sourceModel()->data(leftIndex, ConversationListModel::MultitargetRole).toBool();
|
||||
const bool isRightMultitarget = sourceModel()->data(leftIndex, ConversationListModel::MultitargetRole).toBool();
|
||||
const bool isRightMultitarget = sourceModel()->data(rightIndex, ConversationListModel::MultitargetRole).toBool();
|
||||
if (isLeftMultitarget && !isRightMultitarget) {
|
||||
return false;
|
||||
}
|
||||
|
@ -72,28 +72,25 @@ bool ConversationsSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QM
|
|||
{
|
||||
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
|
||||
if (filterRole() == Qt::DisplayRole) {
|
||||
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
}
|
||||
if (filterRole() == ConversationListModel::ConversationIdRole) {
|
||||
return sourceModel()->data(index, ConversationListModel::ConversationIdRole) != INVALID_THREAD_ID;
|
||||
} else {
|
||||
if (sourceModel()->data(index, Qt::DisplayRole).toString().contains(filterRegExp())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (filterRole() == ConversationListModel::SenderRole) {
|
||||
if (!sourceModel()->data(index, ConversationListModel::MultitargetRole).toBool()) {
|
||||
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
} else {
|
||||
// This block of code compares each address in the multi target conversation to find a match
|
||||
QList<ConversationAddress> addressList = sourceModel()->data(index, ConversationListModel::AddressesRole).value<QList<ConversationAddress>>();
|
||||
for (const ConversationAddress address : addressList) {
|
||||
if (address.address().contains(filterRegExp())) {
|
||||
return true;
|
||||
}
|
||||
// This block of code compares each address in the multi target conversation to find a match
|
||||
QList<ConversationAddress> addressList = sourceModel()->data(index, ConversationListModel::AddressesRole).value<QList<ConversationAddress>>();
|
||||
for (const ConversationAddress address : addressList) {
|
||||
if (address.address().contains(filterRegExp())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return sourceModel()->data(index, ConversationListModel::ConversationIdRole) != INVALID_THREAD_ID;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConversationsSortFilterProxyModel::doesPhoneNumberExists(const QString &address)
|
||||
bool ConversationsSortFilterProxyModel::doesAddressExists(const QString &address)
|
||||
{
|
||||
for(int i = 0; i < rowCount(); ++i) {
|
||||
if (!data(index(i, 0), ConversationListModel::MultitargetRole).toBool()) {
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
* This method gets name of conversations or contact if it find any matching address
|
||||
* Needed to check if the conversation or contact already exist or no before adding an arbitrary contact
|
||||
*/
|
||||
Q_INVOKABLE bool doesPhoneNumberExists(const QString& address);
|
||||
Q_INVOKABLE bool doesAddressExists(const QString& address);
|
||||
|
||||
ConversationsSortFilterProxyModel();
|
||||
~ConversationsSortFilterProxyModel();
|
||||
|
|
|
@ -170,11 +170,10 @@ Kirigami.ScrollablePage
|
|||
Layout.fillHeight: true
|
||||
onTextChanged: {
|
||||
if (filter.text != "") {
|
||||
if (conversationListModel.isPhoneNumberValid(filter.text)) {
|
||||
view.model.setConversationsFilterRole(ConversationListModel.SenderRole)
|
||||
view.model.setConversationsFilterRole(ConversationListModel.AddressesRole)
|
||||
if (conversationListModel.isAddressValid(filter.text)) {
|
||||
newButton.enabled = true
|
||||
} else {
|
||||
view.model.setConversationsFilterRole(Qt.DisplayRole)
|
||||
newButton.enabled = false
|
||||
}
|
||||
} else {
|
||||
|
@ -215,7 +214,7 @@ Kirigami.ScrollablePage
|
|||
filter.enabled = false
|
||||
|
||||
// If the address entered by the user already exists then ignore adding new contact
|
||||
if (!view.model.doesPhoneNumberExists(filter.text) && conversationListModel.isPhoneNumberValid(filter.text)) {
|
||||
if (!view.model.doesAddressExists(filter.text) && conversationListModel.isAddressValid(filter.text)) {
|
||||
conversationListModel.createConversationForAddress(filter.text)
|
||||
view.currentIndex = 0
|
||||
}
|
||||
|
|
|
@ -127,13 +127,21 @@ QString SmsHelper::canonicalizePhoneNumber(const QString& phoneNumber)
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
bool SmsHelper::isPhoneNumberValid(const QString& phoneNumber)
|
||||
bool SmsHelper::isAddressValid(const QString& address)
|
||||
{
|
||||
QString canonicalizedNumber = canonicalizePhoneNumber(phoneNumber);
|
||||
QString canonicalizedNumber = canonicalizePhoneNumber(address);
|
||||
|
||||
// This regular expression matches a wide range of international Phone numbers, minimum of 3 digits and maximum upto 15 digits
|
||||
QRegularExpression validNumberPattern(QStringLiteral("^(\\d{3,15})$"));
|
||||
return validNumberPattern.match(canonicalizedNumber).hasMatch();
|
||||
static const QRegularExpression validNumberPattern(QStringLiteral("^(\\d{3,15})$"));
|
||||
if (validNumberPattern.match(canonicalizedNumber).hasMatch()) {
|
||||
return true;
|
||||
} else {
|
||||
static const QRegularExpression emailPattern(QStringLiteral("^[\\w\\.]*@[\\w\\.]*$"));
|
||||
if (emailPattern.match(address).hasMatch()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class PersonsCache : public QObject {
|
||||
|
|
|
@ -121,7 +121,7 @@ public:
|
|||
/**
|
||||
* Used to validate arbitrary phone number entered by the user
|
||||
*/
|
||||
static bool isPhoneNumberValid(const QString& phoneNumber);
|
||||
static bool isAddressValid(const QString& address);
|
||||
|
||||
private:
|
||||
SmsHelper(){};
|
||||
|
|
Loading…
Reference in a new issue