diff --git a/include/linphone/api/c-chat-room.h b/include/linphone/api/c-chat-room.h index 392bce10f..b3f40bc6f 100644 --- a/include/linphone/api/c-chat-room.h +++ b/include/linphone/api/c-chat-room.h @@ -179,6 +179,23 @@ LINPHONE_PUBLIC bctbx_list_t *linphone_chat_room_get_history (LinphoneChatRoom * */ LINPHONE_PUBLIC bctbx_list_t *linphone_chat_room_get_history_range(LinphoneChatRoom *cr, int begin, int end); +/** + * Gets nb_events most recent chat message events from cr chat room, sorted from oldest to most recent. + * @param[in] cr The #LinphoneChatRoom object corresponding to the conversation for which events should be retrieved + * @param[in] nb_events Number of events to retrieve. 0 means everything. + * @return \bctbx_list{LinphoneEventLog} + */ +LINPHONE_PUBLIC bctbx_list_t *linphone_chat_room_get_history_message_events (LinphoneChatRoom *cr, int nb_events); + +/** + * Gets the partial list of chat message events in the given range, sorted from oldest to most recent. + * @param[in] cr The #LinphoneChatRoom object corresponding to the conversation for which events should be retrieved + * @param[in] begin The first event of the range to be retrieved. History most recent event has index 0. + * @param[in] end The last event of the range to be retrieved. History oldest event has index of history size - 1 + * @return \bctbx_list{LinphoneEventLog} + */ +LINPHONE_PUBLIC bctbx_list_t *linphone_chat_room_get_history_range_message_events (LinphoneChatRoom *cr, int begin, int end); + /** * Gets nb_events most recent events from cr chat room, sorted from oldest to most recent. * @param[in] cr The #LinphoneChatRoom object corresponding to the conversation for which events should be retrieved diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index 72fad5d60..99d9d2d46 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -204,9 +204,8 @@ void linphone_chat_room_delete_history (LinphoneChatRoom *cr) { bctbx_list_t *linphone_chat_room_get_history_range (LinphoneChatRoom *cr, int startm, int 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()); + for (auto &event : L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getMessageHistoryRange(startm, endm)) + chatMessages.push_back(static_pointer_cast(event)->getChatMessage()); return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(chatMessages); } @@ -215,6 +214,14 @@ bctbx_list_t *linphone_chat_room_get_history (LinphoneChatRoom *cr, int nb_messa return linphone_chat_room_get_history_range(cr, 0, nb_message); } +bctbx_list_t *linphone_chat_room_get_history_range_message_events (LinphoneChatRoom *cr, int startm, int endm) { + return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getMessageHistoryRange(startm, endm)); +} + +bctbx_list_t *linphone_chat_room_get_history_message_events (LinphoneChatRoom *cr, int nb_events) { + return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getMessageHistory(nb_events)); +} + 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_CPP_PTR_FROM_C_OBJECT(cr)->getHistory(nb_events)); } diff --git a/src/chat/chat-room/abstract-chat-room.h b/src/chat/chat-room/abstract-chat-room.h index 46f5aec29..9662f89b9 100644 --- a/src/chat/chat-room/abstract-chat-room.h +++ b/src/chat/chat-room/abstract-chat-room.h @@ -68,6 +68,8 @@ public: virtual State getState () const = 0; virtual bool hasBeenLeft () const = 0; + virtual std::list> getMessageHistory (int nLast) const = 0; + virtual std::list> getMessageHistoryRange (int begin, int end) const = 0; virtual std::list> getHistory (int nLast) const = 0; virtual std::list> getHistoryRange (int begin, int end) const = 0; virtual int getHistorySize () const = 0; diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 14e92cf85..cd7314757 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -321,6 +321,14 @@ ChatRoom::State ChatRoom::getState () const { // ----------------------------------------------------------------------------- +list> ChatRoom::getMessageHistory (int nLast) const { + return getCore()->getPrivate()->mainDb->getHistory(getChatRoomId(), nLast, MainDb::Filter::ConferenceChatMessageFilter); +} + +list> ChatRoom::getMessageHistoryRange (int begin, int end) const { + return getCore()->getPrivate()->mainDb->getHistoryRange(getChatRoomId(), begin, end, MainDb::Filter::ConferenceChatMessageFilter); +} + list> ChatRoom::getHistory (int nLast) const { return getCore()->getPrivate()->mainDb->getHistory(getChatRoomId(), nLast); } diff --git a/src/chat/chat-room/chat-room.h b/src/chat/chat-room/chat-room.h index 35d887e59..e5a270a97 100644 --- a/src/chat/chat-room/chat-room.h +++ b/src/chat/chat-room/chat-room.h @@ -42,6 +42,8 @@ public: State getState () const override; + std::list> getMessageHistory (int nLast) const override; + std::list> getMessageHistoryRange (int begin, int end) const override; std::list> getHistory (int nLast) const override; std::list> getHistoryRange (int begin, int end) const override; int getHistorySize () const override; diff --git a/src/chat/chat-room/proxy-chat-room.cpp b/src/chat/chat-room/proxy-chat-room.cpp index bf984d2a1..547317551 100644 --- a/src/chat/chat-room/proxy-chat-room.cpp +++ b/src/chat/chat-room/proxy-chat-room.cpp @@ -195,6 +195,16 @@ bool ProxyChatRoom::hasBeenLeft () const { // ----------------------------------------------------------------------------- +list> ProxyChatRoom::getMessageHistory (int nLast) const { + L_D(); + return d->chatRoom->getMessageHistory(nLast); +} + +list> ProxyChatRoom::getMessageHistoryRange (int begin, int end) const { + L_D(); + return d->chatRoom->getMessageHistoryRange(begin, end); +} + list> ProxyChatRoom::getHistory (int nLast) const { L_D(); return d->chatRoom->getHistory(nLast); diff --git a/src/chat/chat-room/proxy-chat-room.h b/src/chat/chat-room/proxy-chat-room.h index 16a5c49aa..4f162e8ad 100644 --- a/src/chat/chat-room/proxy-chat-room.h +++ b/src/chat/chat-room/proxy-chat-room.h @@ -43,6 +43,8 @@ public: State getState () const override; bool hasBeenLeft () const override; + std::list> getMessageHistory (int nLast) const override; + std::list> getMessageHistoryRange (int begin, int end) const override; std::list> getHistory (int nLast) const override; std::list> getHistoryRange (int begin, int end) const override; int getHistorySize () const override;