diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-08-19 11:23:51 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-08-30 02:46:41 +0200 |
| commit | 8cbcb1f98f5982f56c9b3ac5b8e089b3b18cf305 (patch) | |
| tree | b1b8011d8bf978476037ca296a69c979c810b038 /xxcc.cpp | |
| parent | 6ecc6b6f0272a47d41ce5d619eaa779a29fcf9df (diff) | |
| download | xxcc-8cbcb1f98f5982f56c9b3ac5b8e089b3b18cf305.tar.gz | |
Replace QList with QHash
Diffstat (limited to 'xxcc.cpp')
| -rw-r--r-- | xxcc.cpp | 57 |
1 files changed, 27 insertions, 30 deletions
@@ -74,17 +74,15 @@ xxcc::xxcc(QWidget *const parent) : break; } - for (const auto *const db : databases) - if (db->jid == selected->jidBare()) - { - static const auto n_messages = 20; - const auto messages = db->getMessages(conv->to, n_messages); - - for (auto it = messages.rbegin(); it != messages.rend(); it++) - new Message(it->body, it->dt, it->direction, ui.messages); + if (databases.contains(selected->jidBare())) + { + const auto db = databases[selected->jidBare()]; + static const auto n_messages = 20; + const auto messages = db->getMessages(conv->to, n_messages); - break; - } + for (auto it = messages.rbegin(); it != messages.rend(); it++) + new Message(it->body, it->dt, it->direction, ui.messages); + } ui.sw->setCurrentIndex(Tab::Chat); ui.jid->setText(conv->to); @@ -125,7 +123,7 @@ void xxcc::connectAccounts(const QList<Credentials::Pair> &pairs) void xxcc::setupDatabases(const QList<Credentials::Pair> &pairs) { for (const auto &p : pairs) - databases.append(new JidDb(p.first)); + databases[p.first] = new JidDb(p.first); } void xxcc::startChat(const QString from, const QString to) @@ -196,12 +194,12 @@ void xxcc::addAccount(Client *const c) roster->connect(roster, &QXmppRosterManager::rosterReceived, c, [this, c, roster] { - for (const auto db : databases) - if (db->jid == c->jidBare()) - { - db->addToRoster(roster->getRosterBareJids()); - break; - } + if (databases.contains(c->jidBare())) + { + const auto db = databases[c->jidBare()]; + + db->addToRoster(roster->getRosterBareJids()); + } }); else throw std::runtime_error("Expected non-null QXmppRosterManager"); @@ -241,23 +239,22 @@ void xxcc::storeMessage(const QXmppMessage &msg, const Direction dir) const break; } - for (const auto db : databases) - if (db->jid == jid) - { - JidDb::Message m; - - m.body = msg.body(); - m.dt = msg.stamp(); - m.direction = dir; - m.contact = contact; - db->storeMessage(m); - break; - } + if (databases.contains(jid)) + { + const auto db = databases[jid]; + JidDb::Message m; + + m.body = msg.body(); + m.dt = msg.stamp(); + m.direction = dir; + m.contact = contact; + db->storeMessage(m); + } } void xxcc::retrieveConversations() { - for (const auto *const db : databases) + for (const auto db : databases) for (const auto &conv : db->getConversations()) new Conversation(db->jid, conv.to, ui.conversations_list, conv.last_msg, conv.dt); |
