From caacc7a87f58f6729026cd56d384c6366493746b Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 27 Nov 2017 10:55:29 +0100 Subject: [PATCH] Started ChatRoom getLastChatMessage --- include/linphone/api/c-chat-room.h | 7 +++++++ src/c-wrapper/api/c-chat-room.cpp | 4 ++++ src/chat/chat-room/chat-room.cpp | 4 ++++ src/chat/chat-room/chat-room.h | 2 ++ src/db/main-db.cpp | 5 +++++ src/db/main-db.h | 1 + 6 files changed, 23 insertions(+) diff --git a/include/linphone/api/c-chat-room.h b/include/linphone/api/c-chat-room.h index d4e0d65b9..966f36896 100644 --- a/include/linphone/api/c-chat-room.h +++ b/include/linphone/api/c-chat-room.h @@ -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 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 + * @return the latest #LinphoneChatMessage + */ +LINPHONE_PUBLIC LinphoneChatMessage *linphone_chat_room_get_last_message_in_history(LinphoneChatRoom *cr); + LINPHONE_PUBLIC LinphoneChatMessage * linphone_chat_room_find_message(LinphoneChatRoom *cr, const char *message_id); /** diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index 76aca9c08..90ffa6a66 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -217,6 +217,10 @@ bctbx_list_t *linphone_chat_room_get_history_range_events (LinphoneChatRoom *cr, ); } +LinphoneChatMessage *linphone_chat_room_get_last_message_in_history(LinphoneChatRoom *cr) { + return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getLastMessageInHistory()); +} + LinphoneChatMessage *linphone_chat_room_find_message (LinphoneChatRoom *cr, const char *message_id) { return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->findMessage(message_id)); } diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 1cda16c65..3578537a6 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -447,6 +447,10 @@ list > ChatRoom::getHistoryRange (int startm, int endm) return list>(); } +shared_ptr ChatRoom::getLastMessageInHistory() const { + return getCore()->getPrivate()->mainDb->getLastChatMessage(getChatRoomId()); +} + int ChatRoom::getUnreadChatMessagesCount () { return getCore()->getPrivate()->mainDb->getUnreadChatMessagesCount(getChatRoomId()); } diff --git a/src/chat/chat-room/chat-room.h b/src/chat/chat-room/chat-room.h index b7e557353..4e6bc3d9a 100644 --- a/src/chat/chat-room/chat-room.h +++ b/src/chat/chat-room/chat-room.h @@ -58,6 +58,8 @@ public: virtual CapabilitiesMask getCapabilities () const = 0; + std::shared_ptr getLastMessageInHistory() const; + // TODO: Remove useless functions. void compose (); std::shared_ptr createFileTransferMessage (const LinphoneContent *initialContent); diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index e6e22caaa..41969d42c 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -1389,6 +1389,11 @@ MainDb::MainDb (const shared_ptr &core) : AbstractDb(*new MainDbPrivate), return list>(); } + shared_ptr MainDb::getLastChatMessage(const ChatRoomId &chatRoomId) const { + // TODO. + return nullptr; + } + list> MainDb::getHistory (const ChatRoomId &chatRoomId, int nLast, FilterMask mask) const { return getHistoryRange(chatRoomId, 0, nLast - 1, mask); } diff --git a/src/db/main-db.h b/src/db/main-db.h index 6c2975efa..28e09437e 100644 --- a/src/db/main-db.h +++ b/src/db/main-db.h @@ -77,6 +77,7 @@ public: int getUnreadChatMessagesCount (const ChatRoomId &chatRoomId = ChatRoomId()) const; void markChatMessagesAsRead (const ChatRoomId &chatRoomId = ChatRoomId()) const; std::list> getUnreadChatMessages (const ChatRoomId &chatRoomId = ChatRoomId()) const; + std::shared_ptr getLastChatMessage(const ChatRoomId &chatRoomId = ChatRoomId()) const; // --------------------------------------------------------------------------- // Conference events.