diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-08-21 00:37:36 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-08-30 02:46:41 +0200 |
| commit | 78d9bd40849a39db1fbdbfc87b2c45e9d3e73d06 (patch) | |
| tree | bb3898abbdaf5d11c62c5deee8debe582ace8c60 /xxcc.cpp | |
| parent | 8cbcb1f98f5982f56c9b3ac5b8e089b3b18cf305 (diff) | |
Insert JidDb into Client
Diffstat (limited to 'xxcc.cpp')
| -rw-r--r-- | xxcc.cpp | 64 |
1 files changed, 30 insertions, 34 deletions
@@ -23,7 +23,6 @@ xxcc::xxcc(QWidget *const parent) : ui.setupUi(this); QScroller::grabGesture(ui.conversations_list, QScroller::TouchGesture); QScroller::grabGesture(ui.messages, QScroller::TouchGesture); - setupDatabases(pairs); connectAccounts(pairs); retrieveConversations(); connect(ui.accounts, &QPushButton::released, this, @@ -39,16 +38,20 @@ xxcc::xxcc(QWidget *const parent) : connect(ui.contacts, &QPushButton::released, this, [this] { - Contacts c(databases, this); + Contacts c(clients, this); connect(&c, &Contacts::startChat, this, &xxcc::startChat); - for (const auto db : databases) + for (const auto cl : clients) + { + const auto db = &cl->database(); + c.connect(db, &JidDb::addedToRoster, &c, [&c, db] (const QString jid) { c.add(db->jid, jid); }); + } c.exec(); }); @@ -74,11 +77,11 @@ xxcc::xxcc(QWidget *const parent) : break; } - if (databases.contains(selected->jidBare())) + if (selected) { - const auto db = databases[selected->jidBare()]; + const auto &db = selected->database(); static const auto n_messages = 20; - const auto messages = db->getMessages(conv->to, n_messages); + 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); @@ -97,9 +100,6 @@ xxcc::~xxcc() { for (const auto c : clients) delete c; - - for (const auto db : databases) - delete db; } void xxcc::connectAccounts(const QList<Credentials::Pair> &pairs) @@ -120,12 +120,6 @@ void xxcc::connectAccounts(const QList<Credentials::Pair> &pairs) } } -void xxcc::setupDatabases(const QList<Credentials::Pair> &pairs) -{ - for (const auto &p : pairs) - databases[p.first] = new JidDb(p.first); -} - void xxcc::startChat(const QString from, const QString to) { bool found = false; @@ -194,12 +188,7 @@ void xxcc::addAccount(Client *const c) roster->connect(roster, &QXmppRosterManager::rosterReceived, c, [this, c, roster] { - if (databases.contains(c->jidBare())) - { - const auto db = databases[c->jidBare()]; - - db->addToRoster(roster->getRosterBareJids()); - } + c->database().addToRoster(roster->getRosterBareJids()); }); else throw std::runtime_error("Expected non-null QXmppRosterManager"); @@ -239,23 +228,30 @@ void xxcc::storeMessage(const QXmppMessage &msg, const Direction dir) const break; } - if (databases.contains(jid)) + for (const auto c : clients) { - 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); + if (c->jidBare() == jid) + { + const auto &db = c->database(); + 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 db : databases) - for (const auto &conv : db->getConversations()) - new Conversation(db->jid, conv.to, - ui.conversations_list, conv.last_msg, conv.dt); + for (const auto c : clients) + { + const auto &db = c->database(); + + for (const auto &conv : db.getConversations()) + new Conversation(db.jid, conv.to, + ui.conversations_list, conv.last_msg, conv.dt); + } } |
