From 231f0e3983f209476b7678030c16ad1fa00c212c Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Tue, 3 Oct 2017 09:23:59 +0200 Subject: [PATCH] Add callback on chat room subject change. --- include/linphone/api/c-callbacks.h | 7 +++++++ include/linphone/api/c-chat-room-cbs.h | 14 ++++++++++++++ src/c-wrapper/api/c-chat-room-cbs.cpp | 9 +++++++++ src/chat/client-group-chat-room.cpp | 9 +++++++++ src/chat/client-group-chat-room.h | 1 + src/conference/conference-listener.h | 1 + src/conference/remote-conference.cpp | 2 ++ src/conference/remote-conference.h | 1 + 8 files changed, 44 insertions(+) diff --git a/include/linphone/api/c-callbacks.h b/include/linphone/api/c-callbacks.h index 347f03552..a6f6f0084 100644 --- a/include/linphone/api/c-callbacks.h +++ b/include/linphone/api/c-callbacks.h @@ -183,6 +183,13 @@ typedef void (*LinphoneChatRoomCbsParticipantAdminStatusChangedCb) (LinphoneChat */ typedef void (*LinphoneChatRoomCbsStateChangedCb) (LinphoneChatRoom *cr, LinphoneChatRoomState newState); +/** + * Callback used to notify that the subject of a chat room has changed. + * @param[in] cr #LinphoneChatRoom object + * @param[in] subject The new subject of the chat room + */ +typedef void (*LinphoneChatRoomCbsSubjectChangedCb) (LinphoneChatRoom *cr, const char *subject); + /** * Callback used to notify a chat room that a message has been received but we were unable to decrypt it * @param cr #LinphoneChatRoom involved in this conversation diff --git a/include/linphone/api/c-chat-room-cbs.h b/include/linphone/api/c-chat-room-cbs.h index aca42d1b2..62ffae9c7 100644 --- a/include/linphone/api/c-chat-room-cbs.h +++ b/include/linphone/api/c-chat-room-cbs.h @@ -144,6 +144,20 @@ LINPHONE_PUBLIC LinphoneChatRoomCbsStateChangedCb linphone_chat_room_cbs_get_sta */ LINPHONE_PUBLIC void linphone_chat_room_cbs_set_state_changed (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsStateChangedCb cb); +/** + * Get the subject changed callback. + * @param[in] cbs LinphoneChatRoomCbs object. + * @return The current subject changed callback. + */ +LINPHONE_PUBLIC LinphoneChatRoomCbsSubjectChangedCb linphone_chat_room_cbs_get_subject_changed (const LinphoneChatRoomCbs *cbs); + +/** + * Set the subject changed callback. + * @param[in] cbs LinphoneChatRoomCbs object. + * @param[in] cb The subject changed callback to be used. + */ +LINPHONE_PUBLIC void linphone_chat_room_cbs_set_subject_changed (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsSubjectChangedCb cb); + /** * Get the undecryptable message received callback. * @param[in] cbs LinphoneChatRoomCbs object. diff --git a/src/c-wrapper/api/c-chat-room-cbs.cpp b/src/c-wrapper/api/c-chat-room-cbs.cpp index 34b78e27e..760ce31dc 100644 --- a/src/c-wrapper/api/c-chat-room-cbs.cpp +++ b/src/c-wrapper/api/c-chat-room-cbs.cpp @@ -31,6 +31,7 @@ struct _LinphoneChatRoomCbs { LinphoneChatRoomCbsParticipantRemovedCb participantRemovedCb; LinphoneChatRoomCbsParticipantAdminStatusChangedCb participantAdminStatusChangedCb; LinphoneChatRoomCbsStateChangedCb stateChangedCb; + LinphoneChatRoomCbsSubjectChangedCb subjectChangedCb; LinphoneChatRoomCbsUndecryptableMessageReceivedCb undecryptableMessageReceivedCb; }; @@ -116,6 +117,14 @@ void linphone_chat_room_cbs_set_state_changed (LinphoneChatRoomCbs *cbs, Linphon cbs->stateChangedCb = cb; } +LinphoneChatRoomCbsSubjectChangedCb linphone_chat_room_cbs_get_subject_changed (const LinphoneChatRoomCbs *cbs) { + return cbs->subjectChangedCb; +} + +void linphone_chat_room_cbs_set_subject_changed (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsSubjectChangedCb cb) { + cbs->subjectChangedCb = cb; +} + LinphoneChatRoomCbsUndecryptableMessageReceivedCb linphone_chat_room_cbs_get_undecryptable_message_received (const LinphoneChatRoomCbs *cbs) { return cbs->undecryptableMessageReceivedCb; } diff --git a/src/chat/client-group-chat-room.cpp b/src/chat/client-group-chat-room.cpp index fb21ca9cc..3e9302005 100644 --- a/src/chat/client-group-chat-room.cpp +++ b/src/chat/client-group-chat-room.cpp @@ -184,6 +184,15 @@ void ClientGroupChatRoom::onParticipantSetAdmin (const Address &addr, bool isAdm cb(cr, L_GET_C_BACK_PTR(participant), isAdmin); } +void ClientGroupChatRoom::onSubjectChanged (const std::string &subject) { + this->subject = subject; + LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); + LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); + LinphoneChatRoomCbsSubjectChangedCb cb = linphone_chat_room_cbs_get_subject_changed(cbs); + if (cb) + cb(cr, subject.c_str()); +} + // ----------------------------------------------------------------------------- void ClientGroupChatRoom::onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const string &message) { diff --git a/src/chat/client-group-chat-room.h b/src/chat/client-group-chat-room.h index 05ba772f7..064cc27de 100644 --- a/src/chat/client-group-chat-room.h +++ b/src/chat/client-group-chat-room.h @@ -59,6 +59,7 @@ private: void onParticipantAdded (const Address &addr) override; void onParticipantRemoved (const Address &addr) override; void onParticipantSetAdmin (const Address &addr, bool isAdmin) override; + void onSubjectChanged (const std::string &subject) override; private: /* CallSessionListener */ diff --git a/src/conference/conference-listener.h b/src/conference/conference-listener.h index 713b3456f..fc67cf34e 100644 --- a/src/conference/conference-listener.h +++ b/src/conference/conference-listener.h @@ -32,6 +32,7 @@ public: virtual void onParticipantAdded (const Address &addr) = 0; virtual void onParticipantRemoved (const Address &addr) = 0; virtual void onParticipantSetAdmin (const Address &addr, bool isAdmin) = 0; + virtual void onSubjectChanged (const std::string &subject) = 0; }; LINPHONE_END_NAMESPACE diff --git a/src/conference/remote-conference.cpp b/src/conference/remote-conference.cpp index f83f10e67..1f38c4d13 100644 --- a/src/conference/remote-conference.cpp +++ b/src/conference/remote-conference.cpp @@ -92,4 +92,6 @@ void RemoteConference::onParticipantRemoved (const Address &addr) {} void RemoteConference::onParticipantSetAdmin (const Address &addr, bool isAdmin) {} +void RemoteConference::onSubjectChanged (const std::string &subject) {} + LINPHONE_END_NAMESPACE diff --git a/src/conference/remote-conference.h b/src/conference/remote-conference.h index 8ae6c2f1f..cf2956fed 100644 --- a/src/conference/remote-conference.h +++ b/src/conference/remote-conference.h @@ -48,6 +48,7 @@ protected: void onParticipantAdded (const Address &addr) override; void onParticipantRemoved (const Address &addr) override; void onParticipantSetAdmin (const Address &addr, bool isAdmin) override; + void onSubjectChanged (const std::string &subject) override; protected: RemoteConferenceEventHandler *eventHandler = nullptr;