From f983662df8068ac530c63ca68f24ca0e35fc5ac4 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Mon, 19 Mar 2018 10:25:38 +0100 Subject: [PATCH] set device event of a server chat room when receiving a list subscription --- src/chat/chat-room/client-group-chat-room.cpp | 1 + src/conference/conference.cpp | 1 + .../local-conference-event-handler.cpp | 1 + .../local-conference-list-event-handler.cpp | 44 ++++++++++++++++++- .../local-conference-list-event-handler.h | 5 ++- src/conference/participant.cpp | 1 + src/conference/participant.h | 2 +- src/db/main-db.cpp | 1 + 8 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index 0f11648e8..965293a3f 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -26,6 +26,7 @@ #include "conference/handlers/remote-conference-event-handler-p.h" #include "conference/handlers/remote-conference-list-event-handler.h" #include "conference/participant-p.h" +#include "conference/participant-device.h" #include "conference/remote-conference-p.h" #include "conference/session/call-session-p.h" #include "core/core-p.h" diff --git a/src/conference/conference.cpp b/src/conference/conference.cpp index 9e22d0207..e12559531 100644 --- a/src/conference/conference.cpp +++ b/src/conference/conference.cpp @@ -18,6 +18,7 @@ */ #include "conference-p.h" +#include "conference/participant-device.h" #include "conference/session/call-session-p.h" #include "logger/logger.h" #include "participant-p.h" diff --git a/src/conference/handlers/local-conference-event-handler.cpp b/src/conference/handlers/local-conference-event-handler.cpp index a77350a0d..e9ccd1a50 100644 --- a/src/conference/handlers/local-conference-event-handler.cpp +++ b/src/conference/handlers/local-conference-event-handler.cpp @@ -22,6 +22,7 @@ #include "linphone/utils/utils.h" #include "conference/local-conference.h" +#include "conference/participant-device.h" #include "conference/participant-p.h" #include "content/content-manager.h" #include "content/content-type.h" diff --git a/src/conference/handlers/local-conference-list-event-handler.cpp b/src/conference/handlers/local-conference-list-event-handler.cpp index d182bacd8..b08ea059a 100644 --- a/src/conference/handlers/local-conference-list-event-handler.cpp +++ b/src/conference/handlers/local-conference-list-event-handler.cpp @@ -19,13 +19,20 @@ #include "belle-sip/utils.h" #include "linphone/utils/utils.h" +#include "linphone/api/c-address.h" #include "address/address.h" +#include "c-wrapper/c-wrapper.h" +#include "chat/chat-room/abstract-chat-room.h" +#include "conference/participant-p.h" +#include "conference/participant-device.h" #include "content/content.h" #include "content/content-manager.h" #include "content/content-type.h" +#include "core/core.h" #include "local-conference-event-handler.h" #include "local-conference-list-event-handler.h" +#include "logger/logger.h" #include "xml/resource-lists.h" #include "xml/rlmi.h" @@ -41,7 +48,42 @@ namespace { // ----------------------------------------------------------------------------- -void LocalConferenceListEventHandler::subscribeReceived (const string &xmlBody) { +void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev) { + const LinphoneAddress *lAddr = linphone_event_get_from(lev); + char *addrStr = linphone_address_as_string(lAddr); + IdentityAddress participantAddr(addrStr); + bctbx_free(addrStr); + + const LinphoneAddress *lDeviceAddr = linphone_event_get_remote_contact(lev); + char *deviceAddrStr = linphone_address_as_string(lDeviceAddr); + IdentityAddress deviceAddr(deviceAddrStr); + bctbx_free(deviceAddrStr); + + for (const auto &handler : handlers) { + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(linphone_event_get_core(lev))->findChatRoom(handler->getChatRoomId()); + if (!chatRoom) { + lError() << "Received subscribe for unknown chat room: " << handler->getChatRoomId(); + continue; + } + + shared_ptr participant = chatRoom->findParticipant(participantAddr); + if (!participant) { + lError() << "Received subscribe for unknown participant: " << participantAddr << " for chat room: " << handler->getChatRoomId(); + continue; + } + + shared_ptr device = participant->getPrivate()->findDevice(deviceAddr); + if (!device) { + lError() << "Received subscribe for unknown device: " << deviceAddr << " for participant: " + << participantAddr << " for chat room: " << handler->getChatRoomId(); + return; + } + + device->setConferenceSubscribeEvent((linphone_event_get_subscription_state(lev) == LinphoneSubscriptionActive) ? lev : nullptr); + } +} + +void LocalConferenceListEventHandler::parseBody (const string &xmlBody) { list contents; Content rlmiContent; rlmiContent.setContentType(ContentType::Rlmi); diff --git a/src/conference/handlers/local-conference-list-event-handler.h b/src/conference/handlers/local-conference-list-event-handler.h index 3a5a46721..1e5c0ad7c 100644 --- a/src/conference/handlers/local-conference-list-event-handler.h +++ b/src/conference/handlers/local-conference-list-event-handler.h @@ -23,6 +23,8 @@ #include #include +#include "linphone/event.h" + #include "chat/chat-room/chat-room-id.h" #include "linphone/utils/general.h" @@ -34,7 +36,8 @@ class LocalConferenceEventHandler; class LocalConferenceListEventHandler { public: - void subscribeReceived (const std::string &xmlBody); + void subscribeReceived (LinphoneEvent *lev); + void parseBody (const std::string &xmlBody); void notify (); void addHandler (std::shared_ptr handler); std::shared_ptr findHandler (const ChatRoomId &chatRoomId) const; diff --git a/src/conference/participant.cpp b/src/conference/participant.cpp index 68d6e26f7..f72094c7f 100644 --- a/src/conference/participant.cpp +++ b/src/conference/participant.cpp @@ -20,6 +20,7 @@ #include #include "object/object-p.h" +#include "participant-device.h" #include "participant-p.h" #include "participant.h" diff --git a/src/conference/participant.h b/src/conference/participant.h index f3ac911a5..f1d9f1040 100644 --- a/src/conference/participant.h +++ b/src/conference/participant.h @@ -25,7 +25,6 @@ #include "address/identity-address.h" #include "object/object.h" #include "conference/params/call-session-params.h" -#include "conference/participant-device.h" // ============================================================================= @@ -45,6 +44,7 @@ class Participant : public Object { friend class LocalConferenceCallPrivate; friend class LocalConferenceEventHandler; friend class LocalConferenceEventHandlerPrivate; + friend class LocalConferenceListEventHandler; friend class MainDb; friend class MainDbPrivate; friend class MediaSessionPrivate; diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 983630099..a2aae26b2 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -26,6 +26,7 @@ #include "chat/chat-room/chat-room-p.h" #include "chat/chat-room/client-group-chat-room.h" #include "chat/chat-room/server-group-chat-room.h" +#include "conference/participant-device.h" #include "conference/participant-p.h" #include "core/core-p.h" #include "event-log/event-log-p.h"