From 47cf1d436cdfff29a7b3cb0a4cbfc3a758d78240 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 1 Dec 2017 15:13:45 +0100 Subject: [PATCH] fix(c-chat-room): repair get history function --- src/c-wrapper/api/c-chat-room.cpp | 24 +++++++++--------------- src/chat/chat-room/chat-room.cpp | 13 ++++++------- src/chat/chat-room/chat-room.h | 8 +++++--- src/db/main-db.cpp | 14 +++++++------- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index e4622b267..61cbd97e4 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -196,30 +196,24 @@ void linphone_chat_room_delete_history (LinphoneChatRoom *cr) { } bctbx_list_t *linphone_chat_room_get_history_range (LinphoneChatRoom *cr, int startm, int endm) { - return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistoryRange(startm, endm)); + list> chatMessages; + for (auto &event : L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistoryRange(startm, endm)) + if (event->getType() == LinphonePrivate::EventLog::Type::ConferenceChatMessage) + chatMessages.push_back(static_pointer_cast(event)->getChatMessage()); + + return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(chatMessages); } bctbx_list_t *linphone_chat_room_get_history (LinphoneChatRoom *cr, int nb_message) { - return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistory(nb_message)); + return linphone_chat_room_get_history_range(cr, 0, nb_message); } bctbx_list_t *linphone_chat_room_get_history_events (LinphoneChatRoom *cr, int nb_events) { - return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST( - L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore())->mainDb->getHistory( - L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getChatRoomId(), - nb_events - ) - ); + return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistory(nb_events)); } bctbx_list_t *linphone_chat_room_get_history_range_events (LinphoneChatRoom *cr, int begin, int end) { - return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST( - L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore())->mainDb->getHistory( - L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getChatRoomId(), - begin, - end - ) - ); + return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistoryRange(begin, end)); } LinphoneChatMessage *linphone_chat_room_get_last_message_in_history(LinphoneChatRoom *cr) { diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index c70159a27..cf2ca6664 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -406,19 +406,18 @@ shared_ptr ChatRoom::findMessageWithDirection (const string &messag return ret; } -list > ChatRoom::getHistory (int nbMessages) { - return getHistoryRange(0, nbMessages - 1); +list> ChatRoom::getHistory (int nLast) { + return getCore()->getPrivate()->mainDb->getHistory(getChatRoomId(), nLast); +} + +list> ChatRoom::getHistoryRange (int begin, int end) { + return getCore()->getPrivate()->mainDb->getHistoryRange(getChatRoomId(), begin, end); } int ChatRoom::getHistorySize () { return getCore()->getPrivate()->mainDb->getChatMessagesCount(getChatRoomId()); } -list > ChatRoom::getHistoryRange (int startm, int endm) { - // TODO: history. - return list>(); -} - shared_ptr ChatRoom::getLastMessageInHistory() const { return getCore()->getPrivate()->mainDb->getLastChatMessage(getChatRoomId()); } diff --git a/src/chat/chat-room/chat-room.h b/src/chat/chat-room/chat-room.h index f1dd42157..62c387c52 100644 --- a/src/chat/chat-room/chat-room.h +++ b/src/chat/chat-room/chat-room.h @@ -29,6 +29,7 @@ LINPHONE_BEGIN_NAMESPACE class ChatRoomPrivate; +class EventLog; class LINPHONE_PUBLIC ChatRoom : public Object, public CoreAccessor, public ConferenceInterface { friend class ChatMessage; @@ -59,6 +60,10 @@ public: virtual CapabilitiesMask getCapabilities () const = 0; virtual bool hasBeenLeft () const = 0; + std::list> getHistory (int nLast); + std::list> getHistoryRange (int begin, int end); + int getHistorySize (); + std::shared_ptr getLastMessageInHistory () const; // TODO: Remove useless functions. @@ -69,9 +74,6 @@ public: void deleteHistory (); std::shared_ptr findMessage (const std::string &messageId); std::shared_ptr findMessageWithDirection (const std::string &messageId, ChatMessage::Direction direction); - std::list> getHistory (int nbMessages); - int getHistorySize (); - std::list> getHistoryRange (int startm, int endm); int getUnreadChatMessagesCount (); bool isRemoteComposing () const; std::list
getComposingAddresses () const; diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 8df459b1b..98615f710 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -1566,14 +1566,14 @@ MainDb::MainDb (const shared_ptr &core) : AbstractDb(*new MainDbPrivate), } string query = "SELECT id, creation_time FROM event WHERE" - " id IN (" - " SELECT conference_event.event_id FROM conference_event, conference_chat_message_event" - " WHERE"; + " id IN (" + " SELECT conference_event.event_id FROM conference_event, conference_chat_message_event" + " WHERE"; if (chatRoomId.isValid()) - query += " chat_room_id = :chatRoomId AND "; - query += " conference_event.event_id = conference_chat_message_event.event_id" - " AND direction = " + Utils::toString(static_cast(ChatMessage::Direction::Incoming)) + - " AND state <> " + Utils::toString(static_cast(ChatMessage::State::Displayed)) + + query += " chat_room_id = :chatRoomId AND "; + query += " conference_event.event_id = conference_chat_message_event.event_id" + " AND direction = " + Utils::toString(static_cast(ChatMessage::Direction::Incoming)) + + " AND state <> " + Utils::toString(static_cast(ChatMessage::State::Displayed)) + ")"; DurationLogger durationLogger(