Commit 7821bf16 authored by Ronan Abhamon's avatar Ronan Abhamon

fix(src/components/smart-search-bar/SmartSearchBarModel): use contact (if...

fix(src/components/smart-search-bar/SmartSearchBarModel): use contact (if exists) username on search
parent 735554d4
......@@ -36,7 +36,7 @@ void SmartSearchBarModel::setFilter (const QString &pattern) {
bool SmartSearchBarModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent);
return computeStringWeight(index.data().toMap()["sipAddress"].toString()) > 0;
return computeEntryWeight(index.data().toMap()) > 0;
}
bool SmartSearchBarModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
......@@ -46,8 +46,9 @@ bool SmartSearchBarModel::lessThan (const QModelIndex &left, const QModelIndex &
const QString &sip_address_a = map_a["sipAddress"].toString();
const QString &sip_address_b = map_b["sipAddress"].toString();
int weight_a = computeStringWeight(sip_address_a);
int weight_b = computeStringWeight(sip_address_b);
// TODO: Use a cache, do not compute the same value as `filterAcceptsRow`.
int weight_a = computeEntryWeight(map_a);
int weight_b = computeEntryWeight(map_b);
// 1. Not the same weight.
if (weight_a != weight_b)
......@@ -77,6 +78,16 @@ bool SmartSearchBarModel::lessThan (const QModelIndex &left, const QModelIndex &
return sip_address_a <= sip_address_b;
}
int SmartSearchBarModel::computeEntryWeight (const QVariantMap &entry) const {
int weight = computeStringWeight(entry["sipAddress"].toString().mid(4));
const ContactModel *contact = entry.value("contact").value<ContactModel *>();
if (contact)
weight += computeStringWeight(contact->getVcardModel()->getUsername());
return weight;
}
int SmartSearchBarModel::computeStringWeight (const QString &string) const {
int index = -1;
int offset = -1;
......
......@@ -23,6 +23,7 @@ protected:
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override;
private:
int computeEntryWeight (const QVariantMap &entry) const;
int computeStringWeight (const QString &string) const;
QString m_filter;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment