From 26748e101b59b5bc1ed0742d24a7b4ec97e082a1 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini <sylvain.berfini@belledonne-communications.com> Date: Tue, 12 Sep 2023 11:44:31 +0200 Subject: [PATCH] Started changes to support emoji reactions to chat messages in iOS shared core --- coreapi/linphonecore.c | 8 ++++++++ coreapi/private_functions.h | 5 +++++ coreapi/vtables.c | 9 +++++++++ .../linphone/api/c-chat-message-reaction.h | 7 +++++++ include/linphone/callbacks.h | 19 +++++++++++++++---- include/linphone/core.h | 1 + src/c-wrapper/api/c-chat-message-reaction.cpp | 4 ++++ .../chat-message/chat-message-reaction.cpp | 4 ++++ src/chat/chat-message/chat-message-reaction.h | 9 +++++++++ src/chat/chat-message/chat-message.cpp | 5 +++++ .../ios-shared-core-helpers.mm | 11 +++++++++++ tester/message_tester.c | 3 +++ 12 files changed, 81 insertions(+), 4 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 091b9e127e..04a85224c6 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -384,6 +384,14 @@ void linphone_core_cbs_set_reaction_removed(LinphoneCoreCbs *cbs, LinphoneCoreCb cbs->vtable->reaction_removed = cb; } +void linphone_core_cbs_set_reaction_removed_private(LinphoneCoreCbs *cbs, LinphoneCoreCbsReactionRemovedPrivateCb cb) { + cbs->vtable->reaction_removed_private = cb; +} + +LinphoneCoreCbsReactionRemovedPrivateCb linphone_core_cbs_get_reaction_removed_private(LinphoneCoreCbs *cbs) { + return cbs->vtable->reaction_removed_private; +} + LinphoneCoreCbsMessagesReceivedCb linphone_core_cbs_get_messages_received(LinphoneCoreCbs *cbs) { return cbs->vtable->messages_received; } diff --git a/coreapi/private_functions.h b/coreapi/private_functions.h index 89e2d905b7..9b30402546 100644 --- a/coreapi/private_functions.h +++ b/coreapi/private_functions.h @@ -860,6 +860,11 @@ void linphone_core_notify_message_reaction_removed(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message, const LinphoneAddress *address); +void linphone_core_notify_message_reaction_removed_private(LinphoneCore *lc, + LinphoneChatRoom *room, + LinphoneChatMessage *message, + const LinphoneAddress *address, + const char *callId); void linphone_core_notify_messages_received(LinphoneCore *lc, LinphoneChatRoom *room, const bctbx_list_t *messages); void linphone_core_notify_message_sent(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message); void linphone_core_notify_message_received_unable_decrypt(LinphoneCore *lc, diff --git a/coreapi/vtables.c b/coreapi/vtables.c index 6247f3466c..f51b5798d0 100644 --- a/coreapi/vtables.c +++ b/coreapi/vtables.c @@ -260,6 +260,15 @@ void linphone_core_notify_message_reaction_removed(LinphoneCore *lc, cleanup_dead_vtable_refs(lc); } +void linphone_core_notify_message_reaction_removed_private(LinphoneCore *lc, + LinphoneChatRoom *room, + LinphoneChatMessage *message, + const LinphoneAddress *address, + const char *callId) { + NOTIFY_IF_EXIST(reaction_removed_private, lc, room, message, address, callId); + cleanup_dead_vtable_refs(lc); +} + void linphone_core_notify_messages_received(LinphoneCore *lc, LinphoneChatRoom *room, const bctbx_list_t *messages) { NOTIFY_IF_EXIST(messages_received, lc, room, messages); cleanup_dead_vtable_refs(lc); diff --git a/include/linphone/api/c-chat-message-reaction.h b/include/linphone/api/c-chat-message-reaction.h index 3c6865e392..1ceb3e258a 100644 --- a/include/linphone/api/c-chat-message-reaction.h +++ b/include/linphone/api/c-chat-message-reaction.h @@ -66,6 +66,13 @@ LINPHONE_PUBLIC void linphone_chat_message_reaction_unref(LinphoneChatMessageRea */ LINPHONE_PUBLIC void linphone_chat_message_reaction_send(LinphoneChatMessageReaction *reaction); +/** + * Allows to get the Call ID associated with a #LinphoneChatMessageReaction. + * @param reaction the #LinphoneChatMessageReaction. @notnil + * @return the Call ID associated with this reaction. + */ +LINPHONE_PUBLIC const char *linphone_chat_message_reaction_get_call_id(const LinphoneChatMessageReaction *reaction); + /** * @} */ diff --git a/include/linphone/callbacks.h b/include/linphone/callbacks.h index e9bddaa609..bc16c28f67 100644 --- a/include/linphone/callbacks.h +++ b/include/linphone/callbacks.h @@ -963,6 +963,21 @@ typedef void (*LinphoneCoreCbsChatRoomExhumedCb)(LinphoneCore *core, LinphoneCha **/ typedef void (*LinphonePlayerCbsEofReachedCb)(LinphonePlayer *player); +/** + * @} + **/ + +/************ */ +/* PRIVATE */ +/* ********** */ + +// Private: do not document or wrap +typedef void (*LinphoneCoreCbsReactionRemovedPrivateCb)(LinphoneCore *core, + LinphoneChatRoom *chat_room, + LinphoneChatMessage *message, + const LinphoneAddress *address, + const char *callId); + /************ */ /* DEPRECATED */ /* ********** */ @@ -996,8 +1011,4 @@ typedef void (*LinphoneCoreAuthInfoRequestedCb)(LinphoneCore *core, const char *username, const char *domain); -/** - * @} - **/ - #endif /* LINPHONE_CALLBACKS_H_ */ diff --git a/include/linphone/core.h b/include/linphone/core.h index 0cb1880079..a25af79f56 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -303,6 +303,7 @@ typedef struct _LinphoneCoreVTable { LinphoneCoreCbsPreviewDisplayErrorOccurredCb preview_display_error_occurred; LinphoneCoreCbsNewMessageReactionCb new_message_reaction; LinphoneCoreCbsReactionRemovedCb reaction_removed; + LinphoneCoreCbsReactionRemovedPrivateCb reaction_removed_private; void *user_data; /**<User data associated with the above callbacks */ } LinphoneCoreVTable; diff --git a/src/c-wrapper/api/c-chat-message-reaction.cpp b/src/c-wrapper/api/c-chat-message-reaction.cpp index 2b456cf4c4..6eb3c8aa55 100644 --- a/src/c-wrapper/api/c-chat-message-reaction.cpp +++ b/src/c-wrapper/api/c-chat-message-reaction.cpp @@ -48,4 +48,8 @@ void linphone_chat_message_reaction_unref(LinphoneChatMessageReaction *reaction) void linphone_chat_message_reaction_send(LinphoneChatMessageReaction *reaction) { ChatMessageReaction::toCpp(reaction)->send(); +} + +const char *linphone_chat_message_reaction_get_call_id(const LinphoneChatMessageReaction *reaction) { + return L_STRING_TO_C(ChatMessageReaction::toCpp(reaction)->getCallId()); } \ No newline at end of file diff --git a/src/chat/chat-message/chat-message-reaction.cpp b/src/chat/chat-message/chat-message-reaction.cpp index 9322fb72bd..e2407c5da9 100644 --- a/src/chat/chat-message/chat-message-reaction.cpp +++ b/src/chat/chat-message/chat-message-reaction.cpp @@ -72,6 +72,8 @@ void ChatMessageReaction::onChatMessageStateChanged(const shared_ptr<ChatMessage return; } + setCallId(message->getPrivate()->getCallId()); + LinphoneChatMessage *msg = L_GET_C_BACK_PTR(originalMessage); const string &messageId = originalMessage->getImdnMessageId(); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(message->getChatRoom()); @@ -85,6 +87,8 @@ void ChatMessageReaction::onChatMessageStateChanged(const shared_ptr<ChatMessage _linphone_chat_message_notify_reaction_removed(msg, address); linphone_core_notify_message_reaction_removed(message->getCore()->getCCore(), cr, msg, address); + linphone_core_notify_message_reaction_removed_private(message->getCore()->getCCore(), cr, msg, address, + message->getPrivate()->getCallId().c_str()); } else { LinphoneChatMessageReaction *reaction = getSharedFromThis()->toC(); _linphone_chat_message_notify_new_message_reaction(msg, reaction); diff --git a/src/chat/chat-message/chat-message-reaction.h b/src/chat/chat-message/chat-message-reaction.h index 79fa9d8705..7893c6a53c 100644 --- a/src/chat/chat-message/chat-message-reaction.h +++ b/src/chat/chat-message/chat-message-reaction.h @@ -55,6 +55,14 @@ public: std::shared_ptr<const Address> getFromAddress() const; void send(); + void setCallId(const std::string &id) { + callId = id; + } + + const std::string &getCallId() const { + return callId; + } + void setChatRoom(std::shared_ptr<AbstractChatRoom> cr) { chatRoom = cr; } @@ -65,6 +73,7 @@ public: private: std::string messageId; std::string reaction; + std::string callId; std::shared_ptr<const Address> fromAddress; std::shared_ptr<ChatMessage> reactionMessage; std::shared_ptr<AbstractChatRoom> chatRoom; diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index 25a448ce31..0a7cba237d 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -951,6 +951,9 @@ LinphoneReason ChatMessagePrivate::receive() { _linphone_chat_message_notify_reaction_removed(msg, address); linphone_core_notify_message_reaction_removed(q->getCore()->getCCore(), cr, msg, address); + const char *call_id = getCallId().c_str(); + linphone_core_notify_message_reaction_removed_private(q->getCore()->getCCore(), cr, msg, address, call_id); + return reason; } @@ -958,6 +961,8 @@ LinphoneReason ChatMessagePrivate::receive() { LinphoneChatMessageReaction *reaction = ChatMessageReaction::createCObject(messageId, getUtf8Text(), q->getFromAddress()); + ChatMessageReaction::toCpp(reaction)->setCallId(getCallId().c_str()); + _linphone_chat_message_notify_new_message_reaction(msg, reaction); linphone_core_notify_new_message_reaction(q->getCore()->getCCore(), cr, msg, reaction); diff --git a/src/core/shared-core-helpers/ios-shared-core-helpers.mm b/src/core/shared-core-helpers/ios-shared-core-helpers.mm index c822071527..062d0e3dc3 100644 --- a/src/core/shared-core-helpers/ios-shared-core-helpers.mm +++ b/src/core/shared-core-helpers/ios-shared-core-helpers.mm @@ -211,11 +211,22 @@ static void on_push_notification_message_received(LinphoneCore *lc, LinphoneChat } } +static void on_push_notification_reaction_to_message_received(LinphoneChatMessage *msg, const LinphoneChatMessageReaction *reaction) { + const char *callId = linphone_chat_message_reaction_get_call_id(reaction); + // TODO: do like in putMsgInUserDefaults +} + +static void on_push_notification_reaction_to_message_removed(LinphoneChatMessage *message, const LinphoneAddress *address, const char *callId) { + // TODO: don't wait for chat message to arrive +} + void IosSharedCoreHelpers::registerSharedCoreMsgCallback() { if (isCoreShared()) { lInfo() << "[push] register shared core msg callback"; LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(linphone_factory_get()); linphone_core_cbs_set_message_received(cbs, on_push_notification_message_received); + linphone_chat_message_cbs_set_new_message_reaction(cbs, on_push_notification_reaction_to_message_received); + linphone_chat_message_cbs_set_reaction_removed_private(cbs, on_push_notification_reaction_to_message_removed); linphone_core_add_callbacks(getCore()->getCCore(), cbs); linphone_core_cbs_unref(cbs); } diff --git a/tester/message_tester.c b/tester/message_tester.c index 786b5bf2d2..f45dee002b 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -438,6 +438,9 @@ void check_reactions(LinphoneChatMessage *message, const char *reaction_body = linphone_chat_message_reaction_get_body(reaction); BC_ASSERT_STRING_EQUAL(reaction_body, expected_reaction); + const char *reaction_call_id = linphone_chat_message_get_call_id(reaction); + BC_ASSERT_PTR_NOT_NULL(reaction_call_id); + const LinphoneAddress *from = linphone_chat_message_reaction_get_from_address(reaction); BC_ASSERT_STRING_EQUAL(linphone_address_as_string_uri_only(from), expected_reaction_from); } -- GitLab