Fix search bar sorter + timeline contact update

This commit is contained in:
Julien Wadel 2021-08-11 21:18:19 +02:00
parent 38d01ce997
commit adffd91b14
6 changed files with 25 additions and 15 deletions

View file

@ -215,6 +215,11 @@ ChatRoomModel::ChatRoomModel (std::shared_ptr<linphone::ChatRoom> chatRoom, QObj
QObject::connect(coreHandlers, &CoreHandlers::callStateChanged, this, &ChatRoomModel::handleCallStateChanged);
QObject::connect(coreHandlers, &CoreHandlers::presenceStatusReceived, this, &ChatRoomModel::handlePresenceStatusReceived);
//QObject::connect(coreHandlers, &CoreHandlers::isComposingChanged, this, &ChatRoomModel::handleIsComposingChanged);
QObject::connect(coreManager->getContactsListModel(), &ContactsListModel::contactAdded, this, &ChatRoomModel::usernameChanged);
QObject::connect(coreManager->getContactsListModel(), &ContactsListModel::contactAdded, this, &ChatRoomModel::fullPeerAddressChanged);
QObject::connect(coreManager->getContactsListModel(), &ContactsListModel::contactRemoved, this, &ChatRoomModel::usernameChanged);
QObject::connect(coreManager->getContactsListModel(), &ContactsListModel::contactRemoved, this, &ChatRoomModel::fullPeerAddressChanged);
//QObject::connect(this, &ChatRoomModel::messageCountReset, coreManager, &CoreManager::eventCountChanged );
if(mChatRoom){

View file

@ -78,8 +78,8 @@ bool SearchSipAddressesProxyModel::filterAcceptsRow (int sourceRow, const QModel
}
bool SearchSipAddressesProxyModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
const QVariantMap mapA = sourceModel()->data(left).toMap();
const QVariantMap mapB = sourceModel()->data(right).toMap();
return SipAddressesSorter::lessThan(mFilter, mapA, mapB);
const SearchResultModel * modelA = sourceModel()->data(left).value<SearchResultModel*>();
const SearchResultModel * modelB = sourceModel()->data(right).value<SearchResultModel*>();
return SipAddressesSorter::lessThan(mFilter, modelA, modelB);
}

View file

@ -24,6 +24,8 @@
#include "SipAddressesSorter.hpp"
#include "../search/SearchResultModel.hpp"
// =============================================================================
namespace {
@ -43,9 +45,10 @@ SipAddressesSorter::SipAddressesSorter (QObject *parent) : QObject(parent) {
// -----------------------------------------------------------------------------
bool SipAddressesSorter::lessThan (const QString& filter, const QVariantMap &left, const QVariantMap &right) {
const QString sipAddressA = left["sipAddress"].toString();
const QString sipAddressB = right["sipAddress"].toString();
//bool SipAddressesSorter::lessThan (const QString& filter, const QVariantMap &left, const QVariantMap &right) {
bool SipAddressesSorter::lessThan (const QString& filter, const SearchResultModel *left, const SearchResultModel *right) {
const QString sipAddressA = left->getAddressString();
const QString sipAddressB = right->getAddressString();
// TODO: Use a cache, do not compute the same value as `filterAcceptsRow`.
int weightA = computeEntryWeight(filter, left);
@ -55,8 +58,8 @@ bool SipAddressesSorter::lessThan (const QString& filter, const QVariantMap &lef
if (weightA != weightB)
return weightA > weightB;
const ContactModel *contactA = left.value("contact").value<ContactModel *>();
const ContactModel *contactB = right.value("contact").value<ContactModel *>();
const ContactModel *contactA = left->getContactModel();
const ContactModel *contactB = right->getContactModel();
// 2. No contacts.
if (!contactA && !contactB)
@ -79,10 +82,10 @@ bool SipAddressesSorter::lessThan (const QString& filter, const QVariantMap &lef
return sipAddressA <= sipAddressB;
}
int SipAddressesSorter::computeEntryWeight (const QString& filter, const QVariantMap &entry) {
int weight = computeStringWeight(filter, entry["sipAddress"].toString().mid(4));
int SipAddressesSorter::computeEntryWeight (const QString& filter, const SearchResultModel *entry) {
int weight = computeStringWeight(filter, entry->getAddressString().mid(4));
const ContactModel *contact = entry.value("contact").value<ContactModel *>();
const ContactModel *contact = entry->getContactModel();
if (contact)
weight += computeStringWeight(filter, contact->getVcardModel()->getUsername());

View file

@ -26,6 +26,7 @@
#include <QVariantMap>
// =============================================================================
class SearchResultModel;
class SipAddressesSorter : public QObject{
Q_OBJECT
@ -33,10 +34,11 @@ class SipAddressesSorter : public QObject{
public:
SipAddressesSorter (QObject *parent = Q_NULLPTR);
static bool lessThan( const QString& filter, const QVariantMap &left, const QVariantMap &right);
//static bool lessThan( const QString& filter, const QVariantMap &left, const QVariantMap &right);
static bool lessThan (const QString& filter, const SearchResultModel *left, const SearchResultModel *right);
private:
static int computeEntryWeight (const QString& filter, const QVariantMap &entry);
static int computeEntryWeight (const QString& filter, const SearchResultModel *entry);
static int computeStringWeight (const QString& filter, const QString &string);
static const QRegExp SearchSeparators;

View file

@ -116,7 +116,7 @@ RowLayout {
delegate: Item {
implicitHeight: textInput.height
width: parent.width
width: ListView.width
TransparentTextInput {
id: textInput

View file

@ -178,7 +178,7 @@ ApplicationWindow {
if (entry.contact && SettingsModel.contactsEnabled) {
window.setView('ContactEdit', { sipAddress: entry.sipAddress })
} else {
CallsListModel.createChatRoom( "", false, sipAddress )
CallsListModel.createChatRoom( "", false, [entry] )
}
}