muc joining leaving debug, notification debug, delayed delivery wannabe detection

This commit is contained in:
Blue 2019-08-31 23:50:05 +03:00
parent a51907b810
commit f5fa45d853
8 changed files with 87 additions and 22 deletions

View File

@ -572,7 +572,10 @@ bool Core::Account::handleGroupMessage(const QXmppMessage& msg, bool outgoing, b
} }
cnt->appendMessageToArchive(sMsg); cnt->appendMessageToArchive(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); emit message(sMsg);
}
if (!forwarded && !outgoing) { if (!forwarded && !outgoing) {
if (msg.isReceiptRequested() && id.size() > 0) { if (msg.isReceiptRequested() && id.size() > 0) {

View File

@ -64,7 +64,7 @@ bool Core::Conference::getJoined() const
void Core::Conference::setJoined(bool p_joined) void Core::Conference::setJoined(bool p_joined)
{ {
if (joined != p_joined) { if (joined != p_joined) {
if (joined) { if (p_joined) {
room->join(); room->join();
} else { } else {
room->leave(); room->leave();

View File

@ -424,7 +424,7 @@ void Core::Squawk::setRoomJoined(const QString& account, const QString& jid, boo
{ {
AccountsMap::const_iterator itr = amap.find(account); AccountsMap::const_iterator itr = amap.find(account);
if (itr == amap.end()) { 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; return;
} }
itr->second->setRoomJoined(jid, joined); itr->second->setRoomJoined(jid, joined);

View File

@ -219,11 +219,11 @@ void Models::Contact::setState(Shared::SubscriptionState p_state)
QIcon Models::Contact::getStatusIcon(bool big) const QIcon Models::Contact::getStatusIcon(bool big) const
{ {
if (getMessagesCount() > 0) { if (getMessagesCount() > 0) {
return Shared::icon("mail-message"); return Shared::icon("mail-message", big);
} else if (state == Shared::both) { } else if (state == Shared::both) {
return Shared::availabilityIcon(availability, big);; return Shared::availabilityIcon(availability, big);;
} else { } else {
return Shared::subscriptionStateIcon(state); return Shared::subscriptionStateIcon(state, big);
} }
} }

View File

@ -54,7 +54,7 @@ unsigned int Models::Room::getUnreadMessagesCount() const
int Models::Room::columnCount() const int Models::Room::columnCount() const
{ {
return 5; return 6;
} }
QString Models::Room::getJid() const QString Models::Room::getJid() const
@ -99,6 +99,8 @@ QVariant Models::Room::data(int column) const
return getAutoJoin(); return getAutoJoin();
case 4: case 4:
return getNick(); return getNick();
case 5:
return getMessagesCount();
default: default:
return QVariant(); return QVariant();
} }
@ -153,6 +155,9 @@ void Models::Room::update(const QString& field, const QVariant& value)
QIcon Models::Room::getStatusIcon(bool big) const QIcon Models::Room::getStatusIcon(bool big) const
{ {
if (messages.size() > 0) {
return Shared::icon("mail-message", big);
} else {
if (autoJoin) { if (autoJoin) {
if (joined) { if (joined) {
return Shared::connectionStateIcon(Shared::connected, big); return Shared::connectionStateIcon(Shared::connected, big);
@ -167,6 +172,7 @@ QIcon Models::Room::getStatusIcon(bool big) const
} }
} }
} }
}
QString Models::Room::getStatusText() const QString Models::Room::getStatusText() const
{ {
@ -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);
}
}

View File

@ -31,6 +31,7 @@ class Room : public Models::Item
{ {
Q_OBJECT Q_OBJECT
public: public:
typedef std::deque<Shared::Message> Messages;
Room(const QString& p_jid, const QMap<QString, QVariant> &data, Item *parentItem = 0); Room(const QString& p_jid, const QMap<QString, QVariant> &data, Item *parentItem = 0);
~Room(); ~Room();
@ -54,6 +55,11 @@ public:
void update(const QString& field, const QVariant& value); 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: protected:
private: private:
@ -61,7 +67,7 @@ private:
bool joined; bool joined;
QString jid; QString jid;
QString nick; QString nick;
std::deque<Shared::Message> messages; Messages messages;
}; };

View File

@ -615,6 +615,11 @@ void Models::Roster::addMessage(const QString& account, const Shared::Message& d
for (;cBeg != cEnd; ++cBeg) { for (;cBeg != cEnd; ++cBeg) {
cBeg->second->addMessage(data); cBeg->second->addMessage(data);
} }
std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
if (rItr != rooms.end()) {
rItr->second->addMessage(data);
}
} }
void Models::Roster::dropMessages(const QString& account, const QString& jid) 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<ElId, Contact*>::iterator cBeg = contacts.lower_bound(id), cEnd = contacts.upper_bound(id) ;cBeg != cEnd; ++cBeg) { for (std::multimap<ElId, Contact*>::iterator cBeg = contacts.lower_bound(id), cEnd = contacts.upper_bound(id) ;cBeg != cEnd; ++cBeg) {
cBeg->second->dropMessages(); cBeg->second->dropMessages();
} }
std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
if (rItr != rooms.end()) {
rItr->second->dropMessages();
}
} }
void Models::Roster::removeAccount(const QString& account) 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) QString Models::Roster::getContactName(const QString& account, const QString& jid)
{ {
std::multimap<ElId, Contact*>::const_iterator cItr = contacts.find({account, jid}); ElId id(account, jid);
std::multimap<ElId, Contact*>::const_iterator cItr = contacts.find(id);
QString name = "";
if (cItr == contacts.end()) { if (cItr == contacts.end()) {
qDebug() << "An attempt to get a name of non existing contact " << account << ":" << jid << ", skipping"; std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
return ""; if (rItr == rooms.end()) {
qDebug() << "An attempt to get a name of non existing contact/room " << account << ":" << jid << ", skipping";
} else {
name = rItr->second->getName();
} }
return cItr->second->getContactName(); } else {
name = cItr->second->getContactName();
}
return name;
} }
void Models::Roster::addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data) void Models::Roster::addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data)

View File

@ -295,7 +295,7 @@ void Squawk::onConversationClosed(QObject* parent)
} }
if (conv->isMuc) { if (conv->isMuc) {
Room* room = static_cast<Room*>(conv); Room* room = static_cast<Room*>(conv);
if (room->autoJoined()) { if (!room->autoJoined()) {
emit setRoomJoined(id.account, id.name, false); 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) void Squawk::notify(const QString& account, const Shared::Message& msg)
{ {
QString name = QString(rosterModel.getContactName(account, msg.getPenPalJid()));;
QVariantList args; QVariantList args;
args << QString(QCoreApplication::applicationName()); args << QString(QCoreApplication::applicationName());
args << QVariant(QVariant::UInt); //TODO some normal id args << QVariant(QVariant::UInt); //TODO some normal id
args << QString("mail-message"); //TODO icon 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 << QString(msg.getBody());
args << QStringList(); args << QStringList();
args << QVariantMap(); args << QVariantMap();