Commit a57290db authored by Ronan's avatar Ronan

feat(c-chat-room): add new function to get events list size

parent fc610146
......@@ -202,6 +202,13 @@ LINPHONE_PUBLIC bctbx_list_t *linphone_chat_room_get_history_events (LinphoneCha
*/
LINPHONE_PUBLIC bctbx_list_t *linphone_chat_room_get_history_range_events (LinphoneChatRoom *cr, int begin, int end);
/**
* Gets the number of events in a chat room.
* @param[in] cr The #LinphoneChatRoom object corresponding to the conversation for which size has to be computed
* @return the number of events.
*/
LINPHONE_PUBLIC int linphone_chat_room_get_history_events_size(LinphoneChatRoom *cr);
/**
* Gets the last chat message sent or received in this chat room
* @param[in] cr The #LinphoneChatRoom object corresponding to the conversation for which last message should be retrieved
......
......@@ -180,7 +180,7 @@ int linphone_chat_room_get_unread_messages_count (LinphoneChatRoom *cr) {
}
int linphone_chat_room_get_history_size (LinphoneChatRoom *cr) {
return L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistorySize();
return L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getChatMessagesCount();
}
void linphone_chat_room_delete_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
......@@ -216,6 +216,10 @@ bctbx_list_t *linphone_chat_room_get_history_range_events (LinphoneChatRoom *cr,
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistoryRange(begin, end));
}
int linphone_chat_room_get_history_events_size(LinphoneChatRoom *cr) {
return L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistorySize();
}
LinphoneChatMessage *linphone_chat_room_get_last_message_in_history(LinphoneChatRoom *cr) {
shared_ptr<LinphonePrivate::ChatMessage> cppPtr = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getLastChatMessageInHistory();
if (!cppPtr)
......
......@@ -354,7 +354,7 @@ list<shared_ptr<EventLog>> ChatRoom::getHistoryRange (int begin, int end) {
}
int ChatRoom::getHistorySize () {
return getCore()->getPrivate()->mainDb->getChatMessagesCount(getChatRoomId());
return getCore()->getPrivate()->mainDb->getHistorySize(getChatRoomId());
}
shared_ptr<ChatMessage> ChatRoom::getLastChatMessageInHistory() const {
......@@ -365,6 +365,10 @@ void ChatRoom::deleteHistory () {
getCore()->getPrivate()->mainDb->cleanHistory(getChatRoomId());
}
int ChatRoom::getChatMessagesCount () {
return getCore()->getPrivate()->mainDb->getChatMessagesCount(getChatRoomId());
}
int ChatRoom::getUnreadChatMessagesCount () {
return getCore()->getPrivate()->mainDb->getUnreadChatMessagesCount(getChatRoomId());
}
......
......@@ -68,6 +68,7 @@ public:
void deleteHistory ();
int getChatMessagesCount ();
int getUnreadChatMessagesCount ();
// TODO: Remove useless functions.
......
......@@ -469,7 +469,8 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
// 2 - Fetch contents.
{
soci::session *session = dbSession.getBackendSession<soci::session>();
const string query = "SELECT chat_message_content.id, content_type.id, content_type.value, body FROM chat_message_content, content_type"
static const string query = "SELECT chat_message_content.id, content_type.id, content_type.value, body"
" FROM chat_message_content, content_type"
" WHERE event_id = :eventId AND content_type_id = content_type.id";
soci::rowset<soci::row> rows = (session->prepare << query, soci::use(eventId));
for (const auto &row : rows) {
......@@ -1314,7 +1315,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
return 0;
}
string query = "SELECT COUNT(*) FROM event" +
static string query = "SELECT COUNT(*) FROM event" +
buildSqlEventFilter({ ConferenceCallFilter, ConferenceChatMessageFilter, ConferenceInfoFilter }, mask);
int count = 0;
......@@ -1354,7 +1355,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
return event;
// TODO: Improve. Deal with all events in the future.
static string query = "SELECT peer_sip_address.value, local_sip_address.value, type, event.creation_time"
static const string query = "SELECT peer_sip_address.value, local_sip_address.value, type, event.creation_time"
" FROM event, conference_event, chat_room, sip_address AS peer_sip_address, sip_address as local_sip_address"
" WHERE event.id = :eventId"
" AND conference_event.event_id = event.id"
......@@ -1639,8 +1640,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
return chatMessages;
}
const long long &dbChatRoomId = d->selectChatRoomId(chatRoomId);
string query = "SELECT id, type, creation_time FROM event"
static const string query = "SELECT id, type, creation_time FROM event"
" WHERE id IN ("
" SELECT event_id FROM conference_event"
" WHERE event_id IN (SELECT event_id FROM conference_chat_message_event WHERE imdn_message_id = :imdnMessageId)"
......@@ -1657,6 +1657,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
soci::session *session = d->dbSession.getBackendSession<soci::session>();
soci::transaction tr(*session);
const long long &dbChatRoomId = d->selectChatRoomId(chatRoomId);
soci::rowset<soci::row> rows = (session->prepare << query, soci::use(imdnMessageId), soci::use(dbChatRoomId));
for (const auto &row : rows) {
long long eventId = d->resolveId(row, 0);
......@@ -1768,6 +1769,35 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
return list<shared_ptr<EventLog>>();
}
int MainDb::getHistorySize (const ChatRoomId &chatRoomId, FilterMask mask) const {
L_D();
if (!isConnected()) {
lWarning() << "Unable to get history size. Not connected.";
return 0;
}
int count = 0;
const string query = "SELECT COUNT(*) FROM event, conference_event"
" WHERE chat_room_id = :chatRoomId"
" AND event_id = event.id" +
buildSqlEventFilter({
ConferenceCallFilter, ConferenceChatMessageFilter, ConferenceInfoFilter
}, mask, "AND");
L_BEGIN_LOG_EXCEPTION
const long long &dbChatRoomId = d->selectChatRoomId(chatRoomId);
soci::session *session = d->dbSession.getBackendSession<soci::session>();
*session << query, soci::into(count), soci::use(dbChatRoomId);
L_END_LOG_EXCEPTION
return count;
}
void MainDb::cleanHistory (const ChatRoomId &chatRoomId, FilterMask mask) {
L_D();
......@@ -1776,7 +1806,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
return;
}
string query = "SELECT event_id FROM conference_event WHERE chat_room_id = :chatRoomId" +
const string query = "SELECT event_id FROM conference_event WHERE chat_room_id = :chatRoomId" +
buildSqlEventFilter({
ConferenceCallFilter, ConferenceChatMessageFilter, ConferenceInfoFilter
}, mask);
......@@ -1852,7 +1882,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
list<shared_ptr<Participant>> participants;
const long long &dbChatRoomId = d->resolveId(row, 0);
string query = "SELECT sip_address.value, is_admin"
static const string query = "SELECT sip_address.value, is_admin"
" FROM sip_address, chat_room, chat_room_participant"
" WHERE chat_room.id = :chatRoomId"
" AND sip_address.id = chat_room_participant.participant_sip_address_id"
......@@ -2193,6 +2223,10 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
return list<shared_ptr<EventLog>>();
}
int getHistorySize (const ChatRoomId &, FilterMask) const {
return 0;
}
list<shared_ptr<ChatRoom>> MainDb::getChatRooms () const {
return list<shared_ptr<ChatRoom>>();
}
......
......@@ -104,6 +104,9 @@ public:
int end,
FilterMask mask = NoFilter
) const;
int getHistorySize (const ChatRoomId &chatRoomId, FilterMask mask = NoFilter) const;
void cleanHistory (const ChatRoomId &chatRoomId, FilterMask mask = NoFilter);
// ---------------------------------------------------------------------------
......
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