better new message handling, subscription with adding new contact, out of roster contacts handling

This commit is contained in:
Blue 2019-06-18 18:08:03 +03:00
parent bb509be29a
commit b2699e0087
11 changed files with 100 additions and 23 deletions

View file

@ -76,11 +76,7 @@ QVariant Models::Contact::data(int column) const
{
switch (column) {
case 0:
if (name == "") {
return jid;
} else {
return Item::data(column);
}
return getContactName();
case 1:
return jid;
case 2:
@ -94,6 +90,15 @@ QVariant Models::Contact::data(int column) const
}
}
QString Models::Contact::getContactName() const
{
if (name == "") {
return jid;
} else {
return name;
}
}
void Models::Contact::update(const QString& field, const QVariant& value)
{
if (field == "name") {

View file

@ -36,6 +36,7 @@ public:
QString getAccountName() const;
QString getAccountJid() const;
QString getAccountResource() const;
QString getContactName() const;
void addMessage(const Shared::Message& data);
unsigned int getMessagesCount() const;

View file

@ -556,3 +556,13 @@ void Models::Roster::removeAccount(const QString& account)
acc->deleteLater();
}
QString Models::Roster::getContactName(const QString& account, const QString& jid)
{
std::multimap<ElId, Contact*>::const_iterator cItr = contacts.find({account, jid});
if (cItr == contacts.end()) {
qDebug() << "An attempt to get a name of non existing contact " << account << ":" << jid << ", skipping";
return "";
}
return cItr->second->getContactName();
}

View file

@ -35,6 +35,7 @@ public:
void removePresence(const QString& account, const QString& jid, const QString& name);
void addMessage(const QString& account, const Shared::Message& data);
void dropMessages(const QString& account, const QString& jid);
QString getContactName(const QString& account, const QString& jid);
QVariant data ( const QModelIndex& index, int role ) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;