Commit 13a87319 authored by Ronan's avatar Ronan
Browse files

feat(MainDb): add get unread chat messages impl

parent e5e123ea
......@@ -443,15 +443,9 @@ void ChatRoom::markAsRead () {
if (getUnreadChatMessagesCount() == 0)
return;
shared_ptr<Core> core = getCore();
if (!core)
return;
CorePrivate *dCore = core->getPrivate();
CorePrivate *dCore = getCore()->getPrivate();
const string peerAddress = getPeerAddress().asString();
list<shared_ptr<ChatMessage>> chatMessages = dCore->mainDb->getUnreadChatMessages(d->chatRoomId);
for (auto &chatMessage : chatMessages)
for (auto &chatMessage : dCore->mainDb->getUnreadChatMessages(d->chatRoomId))
chatMessage->sendDisplayNotification();
dCore->mainDb->markChatMessagesAsRead(d->chatRoomId);
......
......@@ -1548,13 +1548,56 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
}
list<shared_ptr<ChatMessage>> MainDb::getUnreadChatMessages (const ChatRoomId &chatRoomId) const {
L_D();
list<shared_ptr<ChatMessage>> chatMessages;
string query = "SELECT event_id, creation_time FROM conference_chat_message_event WHERE";
if (chatRoomId.isValid())
query += " event_id IN ("
" SELECT event_id FROM conference_event WHERE chat_room_id = :chatRoomId"
") AND";
query += " direction = " + Utils::toString(static_cast<int>(ChatMessage::Direction::Incoming)) +
+ " AND state <> " + Utils::toString(static_cast<int>(ChatMessage::State::Displayed));
DurationLogger durationLogger(
"Get unread chat messages: (peer=" + chatRoomId.getPeerAddress().asString() +
", local=" + chatRoomId.getLocalAddress().asString() + ")."
);
// TODO.
return list<shared_ptr<ChatMessage>>();
L_BEGIN_LOG_EXCEPTION
soci::session *session = d->dbSession.getBackendSession<soci::session>();
soci::transaction tr(*session);
long long dbChatRoomId;
if (chatRoomId.isValid())
dbChatRoomId = d->selectChatRoomId(chatRoomId);
soci::rowset<soci::row> rows = chatRoomId.isValid()
? (session->prepare << query, soci::use(dbChatRoomId))
: (session->prepare << query);
for (const auto &row : rows) {
long long eventId = d->resolveId(row, 0);
shared_ptr<EventLog> event = d->getEventFromCache(eventId);
if (!event)
event = d->selectGenericConferenceEvent(
eventId,
EventLog::Type::ConferenceChatMessage,
Utils::getTmAsTimeT(row.get<tm>(1)),
chatRoomId
);
if (event)
chatMessages.push_back(static_pointer_cast<ConferenceChatMessageEvent>(event)->getChatMessage());
}
L_END_LOG_EXCEPTION
return chatMessages;
}
shared_ptr<ChatMessage> MainDb::getLastChatMessage (const ChatRoomId &chatRoomId) const {
......
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