From f5fa45d8536871d08e2bfc55135fcdbd07b6033f Mon Sep 17 00:00:00 2001 From: blue Date: Sat, 31 Aug 2019 23:50:05 +0300 Subject: [PATCH] muc joining leaving debug, notification debug, delayed delivery wannabe detection --- core/account.cpp | 5 +++- core/conference.cpp | 2 +- core/squawk.cpp | 2 +- ui/models/contact.cpp | 4 ++-- ui/models/room.cpp | 53 +++++++++++++++++++++++++++++++++++-------- ui/models/room.h | 8 ++++++- ui/models/roster.cpp | 26 +++++++++++++++++---- ui/squawk.cpp | 9 ++++++-- 8 files changed, 87 insertions(+), 22 deletions(-) diff --git a/core/account.cpp b/core/account.cpp index 9aedf26..422a7eb 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -572,7 +572,10 @@ bool Core::Account::handleGroupMessage(const QXmppMessage& msg, bool outgoing, b } cnt->appendMessageToArchive(sMsg); - emit message(sMsg); + QDateTime fiveMinsAgo = QDateTime::currentDateTime().addSecs(-300); + if (sMsg.getTime() > fiveMinsAgo) { //otherwise it's considered a delayed delivery, most probably MUC history receipt + emit message(sMsg); + } if (!forwarded && !outgoing) { if (msg.isReceiptRequested() && id.size() > 0) { diff --git a/core/conference.cpp b/core/conference.cpp index b6e8819..18e46da 100644 --- a/core/conference.cpp +++ b/core/conference.cpp @@ -64,7 +64,7 @@ bool Core::Conference::getJoined() const void Core::Conference::setJoined(bool p_joined) { if (joined != p_joined) { - if (joined) { + if (p_joined) { room->join(); } else { room->leave(); diff --git a/core/squawk.cpp b/core/squawk.cpp index 6de9064..08eb31b 100644 --- a/core/squawk.cpp +++ b/core/squawk.cpp @@ -424,7 +424,7 @@ void Core::Squawk::setRoomJoined(const QString& account, const QString& jid, boo { AccountsMap::const_iterator itr = amap.find(account); if (itr == amap.end()) { - qDebug() << "An attempt to set autoJoin to the room" << jid << "of non existing account" << account << ", skipping"; + qDebug() << "An attempt to set jouned to the room" << jid << "of non existing account" << account << ", skipping"; return; } itr->second->setRoomJoined(jid, joined); diff --git a/ui/models/contact.cpp b/ui/models/contact.cpp index b8f128f..6f79662 100644 --- a/ui/models/contact.cpp +++ b/ui/models/contact.cpp @@ -219,11 +219,11 @@ void Models::Contact::setState(Shared::SubscriptionState p_state) QIcon Models::Contact::getStatusIcon(bool big) const { if (getMessagesCount() > 0) { - return Shared::icon("mail-message"); + return Shared::icon("mail-message", big); } else if (state == Shared::both) { return Shared::availabilityIcon(availability, big);; } else { - return Shared::subscriptionStateIcon(state); + return Shared::subscriptionStateIcon(state, big); } } diff --git a/ui/models/room.cpp b/ui/models/room.cpp index 2a435e3..62b47fb 100644 --- a/ui/models/room.cpp +++ b/ui/models/room.cpp @@ -54,7 +54,7 @@ unsigned int Models::Room::getUnreadMessagesCount() const int Models::Room::columnCount() const { - return 5; + return 6; } QString Models::Room::getJid() const @@ -99,6 +99,8 @@ QVariant Models::Room::data(int column) const return getAutoJoin(); case 4: return getNick(); + case 5: + return getMessagesCount(); default: return QVariant(); } @@ -153,17 +155,21 @@ void Models::Room::update(const QString& field, const QVariant& value) QIcon Models::Room::getStatusIcon(bool big) const { - if (autoJoin) { - if (joined) { - return Shared::connectionStateIcon(Shared::connected, big); - } else { - return Shared::connectionStateIcon(Shared::disconnected, big); - } + if (messages.size() > 0) { + return Shared::icon("mail-message", big); } else { - if (joined) { - return Shared::connectionStateIcon(Shared::connecting, big); + if (autoJoin) { + if (joined) { + return Shared::connectionStateIcon(Shared::connected, big); + } else { + return Shared::connectionStateIcon(Shared::disconnected, big); + } } else { - return Shared::connectionStateIcon(Shared::error, big); + if (joined) { + return Shared::connectionStateIcon(Shared::connecting, big); + } else { + return Shared::connectionStateIcon(Shared::error, big); + } } } } @@ -184,3 +190,30 @@ QString Models::Room::getStatusText() const } } } + +unsigned int Models::Room::getMessagesCount() const +{ + return messages.size(); +} + +void Models::Room::addMessage(const Shared::Message& data) +{ + messages.emplace_back(data); + changed(5); +} + +void Models::Room::dropMessages() +{ + if (messages.size() > 0) { + messages.clear(); + changed(5); + } +} + +void Models::Room::getMessages(Models::Room::Messages& container) const +{ + for (Messages::const_iterator itr = messages.begin(), end = messages.end(); itr != end; ++itr) { + const Shared::Message& msg = *itr; + container.push_back(msg); + } +} diff --git a/ui/models/room.h b/ui/models/room.h index 640de26..456c13e 100644 --- a/ui/models/room.h +++ b/ui/models/room.h @@ -31,6 +31,7 @@ class Room : public Models::Item { Q_OBJECT public: + typedef std::deque Messages; Room(const QString& p_jid, const QMap &data, Item *parentItem = 0); ~Room(); @@ -53,6 +54,11 @@ public: void setNick(const QString& p_nick); void update(const QString& field, const QVariant& value); + + void addMessage(const Shared::Message& data); + unsigned int getMessagesCount() const; + void dropMessages(); + void getMessages(Messages& container) const; protected: @@ -61,7 +67,7 @@ private: bool joined; QString jid; QString nick; - std::deque messages; + Messages messages; }; diff --git a/ui/models/roster.cpp b/ui/models/roster.cpp index 2e62bb5..c91d909 100644 --- a/ui/models/roster.cpp +++ b/ui/models/roster.cpp @@ -615,6 +615,11 @@ void Models::Roster::addMessage(const QString& account, const Shared::Message& d for (;cBeg != cEnd; ++cBeg) { cBeg->second->addMessage(data); } + + std::map::const_iterator rItr = rooms.find(id); + if (rItr != rooms.end()) { + rItr->second->addMessage(data); + } } void Models::Roster::dropMessages(const QString& account, const QString& jid) @@ -623,6 +628,11 @@ void Models::Roster::dropMessages(const QString& account, const QString& jid) for (std::multimap::iterator cBeg = contacts.lower_bound(id), cEnd = contacts.upper_bound(id) ;cBeg != cEnd; ++cBeg) { cBeg->second->dropMessages(); } + + std::map::const_iterator rItr = rooms.find(id); + if (rItr != rooms.end()) { + rItr->second->dropMessages(); + } } void Models::Roster::removeAccount(const QString& account) @@ -677,12 +687,20 @@ void Models::Roster::removeAccount(const QString& account) QString Models::Roster::getContactName(const QString& account, const QString& jid) { - std::multimap::const_iterator cItr = contacts.find({account, jid}); + ElId id(account, jid); + std::multimap::const_iterator cItr = contacts.find(id); + QString name = ""; if (cItr == contacts.end()) { - qDebug() << "An attempt to get a name of non existing contact " << account << ":" << jid << ", skipping"; - return ""; + std::map::const_iterator rItr = rooms.find(id); + if (rItr == rooms.end()) { + qDebug() << "An attempt to get a name of non existing contact/room " << account << ":" << jid << ", skipping"; + } else { + name = rItr->second->getName(); + } + } else { + name = cItr->second->getContactName(); } - return cItr->second->getContactName(); + return name; } void Models::Roster::addRoom(const QString& account, const QString jid, const QMap& data) diff --git a/ui/squawk.cpp b/ui/squawk.cpp index c1c822e..4dccdf2 100644 --- a/ui/squawk.cpp +++ b/ui/squawk.cpp @@ -295,7 +295,7 @@ void Squawk::onConversationClosed(QObject* parent) } if (conv->isMuc) { Room* room = static_cast(conv); - if (room->autoJoined()) { + if (!room->autoJoined()) { emit setRoomJoined(id.account, id.name, false); } } @@ -327,11 +327,16 @@ void Squawk::accountMessage(const QString& account, const Shared::Message& data) void Squawk::notify(const QString& account, const Shared::Message& msg) { + QString name = QString(rosterModel.getContactName(account, msg.getPenPalJid()));; QVariantList args; args << QString(QCoreApplication::applicationName()); args << QVariant(QVariant::UInt); //TODO some normal id args << QString("mail-message"); //TODO icon - args << QString(rosterModel.getContactName(account, msg.getPenPalJid())); + if (msg.getType() == Shared::Message::groupChat) { + args << msg.getFromResource() + " from " + name; + } else { + args << name; + } args << QString(msg.getBody()); args << QStringList(); args << QVariantMap();