Commit a0e041ec authored by Ronan's avatar Ronan
Browse files

feat(MainDb): basix fetch of chatrooms

parent 639792b0
......@@ -41,9 +41,10 @@ public:
std::string getDataPath() const;
std::string getConfigPath() const;
const std::list<std::shared_ptr<ChatRoom>> &getChatRooms () const;
std::shared_ptr<ChatRoom> createClientGroupChatRoom (const std::string &subject);
std::shared_ptr<ChatRoom> getOrCreateChatRoom (const std::string &peerAddress, bool isRtt = false) const;
const std::list<std::shared_ptr<ChatRoom>> &getChatRooms () const;
private:
L_DECLARE_PRIVATE(Core);
......
......@@ -1004,37 +1004,51 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
// -----------------------------------------------------------------------------
list<shared_ptr<ChatRoom>> MainDb::getChatRooms () const {
list<shared_ptr<ChatRoom>> chatRooms;
// TODO.
return chatRooms;
}
static const string query = "SELECT value, creation_date, last_update_date, capabilities, subject, last_notify_id"
" FROM chat_room, sip_address"
" WHERE peer_sip_address_id = id";
shared_ptr<ChatRoom> MainDb::findChatRoom (const string &peerAddress) const {
L_D();
// TODO: Use core cache.
list<shared_ptr<ChatRoom>> chatRooms;
L_BEGIN_LOG_EXCEPTION
soci::session *session = d->dbSession.getBackendSession<soci::session>();
tm creationDate;
tm lastUpdateDate;
int capabilities;
string subject;
*session << "SELECT creation_date, last_update_date, capabilities, subject "
" FROM chat_room"
" WHERE peer_sip_address_id = ("
" SELECT id from sip_address WHERE value = :peerAddress"
" )", soci::use(peerAddress), soci::into(creationDate), soci::into(lastUpdateDate),
soci::use(capabilities), soci::use(subject);
soci::rowset<soci::row> rows = (session->prepare << query);
for (const auto &row : rows) {
string sipAddress = row.get<string>(0);
tm creationDate = row.get<tm>(1);
tm lastUpdateDate = row.get<tm>(2);
int capabilities = row.get<int>(3);
string subject = row.get<string>(4);
unsigned int lastNotifyId = row.get<unsigned int>(5);
(void)sipAddress;
(void)creationDate;
(void)lastUpdateDate;
(void)capabilities;
(void)subject;
(void)lastNotifyId;
if (capabilities & static_cast<int>(ChatRoom::Capabilities::Basic)) {
if (capabilities & static_cast<int>(ChatRoom::Capabilities::RealTimeText)) {
// TODO.
continue;
}
// TODO.
continue;
}
// TODO.
if (capabilities & static_cast<int>(ChatRoom::Capabilities::Conference)) {
// TODO.
}
}
L_END_LOG_EXCEPTION
return shared_ptr<ChatRoom>();
return chatRooms;
}
// -----------------------------------------------------------------------------
......@@ -1228,10 +1242,6 @@ shared_ptr<ChatRoom> MainDb::findChatRoom (const string &peerAddress) const {
void MainDb::cleanHistory (const string &, FilterMask) {}
shared_ptr<ChatRoom> MainDb::findChatRoom (const string &) const {
return nullptr;
}
bool MainDb::import (Backend, const string &) {
return false;
}
......
......@@ -71,7 +71,6 @@ public:
// ChatRooms.
std::list<std::shared_ptr<ChatRoom>> getChatRooms () const;
std::shared_ptr<ChatRoom> findChatRoom (const std::string &peerAddress) const;
// Import legacy messages from old db.
bool import (Backend backend, const std::string &parameters) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment