From 9258c5f14589c5f2d8c36309bad09e9234d64948 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 12 Dec 2017 10:47:23 +0100 Subject: [PATCH] feat(ChatRoom): provide an abstract chat room for chat room migration proxy --- coreapi/callbacks.c | 4 +- coreapi/chat.c | 6 +- coreapi/linphonecore.c | 4 +- coreapi/private_functions.h | 1 - include/linphone/api/c-chat-room.h | 13 --- src/CMakeLists.txt | 5 + src/c-wrapper/api/c-chat-room.cpp | 33 ++---- src/c-wrapper/c-wrapper.h | 12 +- src/chat/chat-message/chat-message-p.h | 2 +- src/chat/chat-message/chat-message.cpp | 33 +++--- src/chat/chat-message/chat-message.h | 6 +- src/chat/chat-room/abstract-chat-room-p.h | 54 +++++++++ src/chat/chat-room/abstract-chat-room.cpp | 35 ++++++ src/chat/chat-room/abstract-chat-room.h | 98 ++++++++++++++++ src/chat/chat-room/basic-chat-room-p.h | 2 - src/chat/chat-room/basic-chat-room.cpp | 4 - .../basic-to-client-group-chat-room.cpp | 0 .../basic-to-client-group-chat-room.h | 0 src/chat/chat-room/chat-room-p.h | 43 +++---- src/chat/chat-room/chat-room.cpp | 106 +++++++++--------- src/chat/chat-room/chat-room.h | 67 +++++------ src/chat/chat-room/client-group-chat-room-p.h | 2 - src/chat/chat-room/client-group-chat-room.cpp | 4 - .../chat-room/real-time-text-chat-room-p.h | 2 +- .../chat-room/real-time-text-chat-room.cpp | 8 +- src/chat/chat-room/server-group-chat-room-p.h | 4 +- .../chat-room/server-group-chat-room-stub.cpp | 6 +- .../encryption-chat-message-modifier.cpp | 6 +- src/chat/notification/imdn.cpp | 2 +- src/core/core-chat-room.cpp | 52 +++++---- src/core/core-p.h | 10 +- src/core/core.h | 25 +++-- src/db/main-db-p.h | 2 +- src/db/main-db.cpp | 33 +++--- src/db/main-db.h | 6 +- tester/cpim-tester.cpp | 4 +- tester/multipart-tester.cpp | 4 +- tools/python/apixml2python.py | 1 - 38 files changed, 417 insertions(+), 282 deletions(-) create mode 100644 src/chat/chat-room/abstract-chat-room-p.h create mode 100644 src/chat/chat-room/abstract-chat-room.cpp create mode 100644 src/chat/chat-room/abstract-chat-room.h create mode 100644 src/chat/chat-room/basic-to-client-group-chat-room.cpp create mode 100644 src/chat/chat-room/basic-to-client-group-chat-room.h diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index b32680f48..5d07c148b 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -87,7 +87,7 @@ static void call_received(SalCallOp *h) { linphone_address_unref(fromAddr); return; } else if (sal_address_has_param(h->get_remote_contact_address(), "text")) { - shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom( + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom( ChatRoomId(IdentityAddress(h->get_to()), IdentityAddress(h->get_to())) ); if (chatRoom) { @@ -681,7 +681,7 @@ static void refer_received(SalOp *op, const SalAddress *refer_to){ if (addr.hasUriParam("method") && (addr.getUriParamValue("method") == "BYE")) { if (linphone_core_conference_server_enabled(lc)) { // Removal of a participant at the server side - shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom( + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom( ChatRoomId(IdentityAddress(op->get_to()), IdentityAddress(op->get_to())) ); if (chatRoom) { diff --git a/coreapi/chat.c b/coreapi/chat.c index 3dc067c80..c07993bae 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -137,18 +137,18 @@ int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, localAddress = op->get_to(); } - shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom( + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom( LinphonePrivate::ChatRoomId(LinphonePrivate::IdentityAddress(peerAddress), LinphonePrivate::IdentityAddress(localAddress)) ); if (chatRoom) - reason = L_GET_PRIVATE(chatRoom)->messageReceived(op, sal_msg); + reason = L_GET_PRIVATE(chatRoom)->onSipMessageReceived(op, sal_msg); else { LinphoneAddress *addr = linphone_address_new(sal_msg->from); linphone_address_clean(addr); LinphoneChatRoom *cr = linphone_core_get_chat_room(lc, addr); if (cr) - reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->messageReceived(op, sal_msg); + reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->onSipMessageReceived(op, sal_msg); linphone_address_unref(addr); } return reason; diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 9d0c9b723..0f887b101 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2134,7 +2134,7 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve const LinphoneAddress *resource = linphone_event_get_resource(lev); const LinphoneAddress *from = linphone_event_get_from(lev); - shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId( + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId( IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)), IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(from)) )); @@ -2164,7 +2164,7 @@ static void _linphone_core_conference_subscription_state_changed(LinphoneCore *l state == LinphoneSubscriptionIncomingReceived ) { const LinphoneAddress *resource = linphone_event_get_resource(lev); - shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId( + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId( IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)), IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)) )); diff --git a/coreapi/private_functions.h b/coreapi/private_functions.h index fcedefcf2..0abfff37d 100644 --- a/coreapi/private_functions.h +++ b/coreapi/private_functions.h @@ -274,7 +274,6 @@ void _linphone_proxy_config_release_ops(LinphoneProxyConfig *obj); /*chat*/ LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, const char *uri, const char *subject); LinphoneChatRoom *_linphone_server_group_chat_room_new (LinphoneCore *core, LinphonePrivate::SalCallOp *op); -void linphone_chat_room_release(LinphoneChatRoom *cr); void linphone_chat_room_set_call(LinphoneChatRoom *cr, LinphoneCall *call); LinphoneChatRoomCbs * linphone_chat_room_cbs_new (void); /**/ diff --git a/include/linphone/api/c-chat-room.h b/include/linphone/api/c-chat-room.h index aa12b800a..77c87cf64 100644 --- a/include/linphone/api/c-chat-room.h +++ b/include/linphone/api/c-chat-room.h @@ -116,19 +116,6 @@ LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_room_get_local_address(Linp */ LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg); -/** - * Send a message to peer member of this chat room. - * @param cr #LinphoneChatRoom object - * @param msg #LinphoneChatMessage message to be sent - * @param status_cb LinphoneChatMessageStateChangeCb status callback invoked when message is delivered or could not be delivered. May be NULL - * @param ud user data for the status cb. - * @deprecated Use linphone_chat_message_send() instead. - * @note The LinphoneChatMessage must not be destroyed until the the callback is called. - * The LinphoneChatMessage reference is transfered to the function and thus doesn't need to be unref'd by the application. - * @donotwrap - */ -LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangedCb status_cb,void* ud); - /** * Send a message to peer member of this chat room. * @param[in] cr LinphoneChatRoom object diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b47ec9dc..e87a09ea7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,8 +36,11 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES call/remote-conference-call.h chat/chat-message/chat-message-p.h chat/chat-message/chat-message.h + chat/chat-room/abstract-chat-room-p.h + chat/chat-room/abstract-chat-room.h chat/chat-room/basic-chat-room-p.h chat/chat-room/basic-chat-room.h + chat/chat-room/basic-to-client-group-chat-room.h chat/chat-room/chat-room-id.h chat/chat-room/chat-room-p.h chat/chat-room/chat-room.h @@ -168,7 +171,9 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES call/local-conference-call.cpp call/remote-conference-call.cpp chat/chat-message/chat-message.cpp + chat/chat-room/abstract-chat-room.cpp chat/chat-room/basic-chat-room.cpp + chat/chat-room/basic-to-client-group-chat-room.cpp chat/chat-room/chat-room-id.cpp chat/chat-room/chat-room.cpp chat/chat-room/client-group-chat-room.cpp diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index 046f8b1e1..f75dbe66b 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -68,12 +68,8 @@ static void _linphone_chat_room_destructor (LinphoneChatRoom *cr) { // Public functions. // ============================================================================= -void linphone_chat_room_release (LinphoneChatRoom *cr) { - L_GET_PRIVATE_FROM_C_OBJECT(cr)->release(); -} - void linphone_chat_room_send_message (LinphoneChatRoom *cr, const char *msg) { - L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(msg)); + L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createChatMessage(msg)->send(); } bool_t linphone_chat_room_is_remote_composing (const LinphoneChatRoom *cr) { @@ -107,7 +103,7 @@ const LinphoneAddress *linphone_chat_room_get_local_address (LinphoneChatRoom *c } LinphoneChatMessage *linphone_chat_room_create_message (LinphoneChatRoom *cr, const char *message) { - shared_ptr cppPtr = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(L_C_TO_STRING(message)); + shared_ptr cppPtr = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createChatMessage(L_C_TO_STRING(message)); LinphoneChatMessage *object = L_INIT(ChatMessage); L_SET_CPP_PTR_FROM_C_OBJECT(object, cppPtr); return object; @@ -130,24 +126,13 @@ LinphoneChatMessage *linphone_chat_room_create_message_2 ( return msg; } -void linphone_chat_room_send_message2 ( - LinphoneChatRoom *cr, - LinphoneChatMessage *msg, - LinphoneChatMessageStateChangedCb status_cb, - void *ud -) { - linphone_chat_message_set_message_state_changed_cb(msg, status_cb); - linphone_chat_message_set_message_state_changed_cb_user_data(msg, ud); - L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg)); -} - void linphone_chat_room_send_chat_message_2 (LinphoneChatRoom *cr, LinphoneChatMessage *msg) { linphone_chat_message_ref(msg); - L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg)); + L_GET_CPP_PTR_FROM_C_OBJECT(msg)->send(); } void linphone_chat_room_send_chat_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) { - L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg)); + L_GET_CPP_PTR_FROM_C_OBJECT(msg)->send(); } void linphone_chat_room_receive_chat_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) { @@ -235,7 +220,7 @@ LinphoneChatMessage *linphone_chat_room_get_last_message_in_history(LinphoneChat } 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)); + return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->findChatMessage(message_id)); } LinphoneChatRoomCbs *linphone_chat_room_get_callbacks (const LinphoneChatRoom *cr) { @@ -323,8 +308,10 @@ void linphone_chat_room_set_subject (LinphoneChatRoom *cr, const char *subject) L_GET_CPP_PTR_FROM_C_OBJECT(cr)->setSubject(L_C_TO_STRING(subject)); } -const bctbx_list_t * linphone_chat_room_get_composing_addresses(LinphoneChatRoom *cr) { - return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getComposingAddresses()); +const bctbx_list_t *linphone_chat_room_get_composing_addresses (LinphoneChatRoom *cr) { + // FIXME + // return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getComposingAddresses()); + return nullptr; } LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, const LinphoneContent *initial_content) { @@ -389,7 +376,7 @@ LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, cons L_SET_CPP_PTR_FROM_C_OBJECT(cr, make_shared( L_GET_CPP_PTR_FROM_C_OBJECT(core), L_C_TO_STRING(uri), me, L_C_TO_STRING(subject)) ); - L_GET_PRIVATE_FROM_C_OBJECT(cr)->setState(LinphonePrivate::ChatRoom::State::Instantiated); + L_GET_PRIVATE_FROM_C_OBJECT(cr, ChatRoom)->setState(LinphonePrivate::ChatRoom::State::Instantiated); return cr; } diff --git a/src/c-wrapper/c-wrapper.h b/src/c-wrapper/c-wrapper.h index 86045002e..f2e076aab 100644 --- a/src/c-wrapper/c-wrapper.h +++ b/src/c-wrapper/c-wrapper.h @@ -35,7 +35,7 @@ F(Address, Address) \ F(Call, Call) \ F(ChatMessage, ChatMessage) \ - F(ChatRoom, ChatRoom) \ + F(AbstractChatRoom, ChatRoom) \ F(Core, Core) \ F(DialPlan, DialPlan) \ F(EventLog, EventLog) \ @@ -43,12 +43,14 @@ F(Participant, Participant) #define L_REGISTER_SUBTYPES(F) \ + F(AbstractChatRoom, BasicChatRoom) \ + F(AbstractChatRoom, BasicToClientGroupChatRoom) \ + F(AbstractChatRoom, ChatRoom) \ + F(AbstractChatRoom, ClientGroupChatRoom) \ + F(AbstractChatRoom, RealTimeTextChatRoom) \ + F(AbstractChatRoom, ServerGroupChatRoom) \ F(Call, LocalConferenceCall) \ F(Call, RemoteConferenceCall) \ - F(ChatRoom, BasicChatRoom) \ - F(ChatRoom, ClientGroupChatRoom) \ - F(ChatRoom, RealTimeTextChatRoom) \ - F(ChatRoom, ServerGroupChatRoom) \ F(EventLog, ConferenceCallEvent) \ F(EventLog, ConferenceChatMessageEvent) \ F(EventLog, ConferenceEvent) \ diff --git a/src/chat/chat-message/chat-message-p.h b/src/chat/chat-message/chat-message-p.h index c805eb935..15839f9db 100644 --- a/src/chat/chat-message/chat-message-p.h +++ b/src/chat/chat-message/chat-message-p.h @@ -156,7 +156,7 @@ public: mutable MainDbChatMessageKey dbKey; private: - std::weak_ptr chatRoom; + std::weak_ptr chatRoom; ChatRoomId chatRoomId; IdentityAddress fromAddress; IdentityAddress toAddress; diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index b820e9466..2de641c73 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -67,7 +67,7 @@ void ChatMessagePrivate::setState (ChatMessage::State s, bool force) { if (force) state = s; - if (s == state || !q->getChatRoom()) + if (s == state) return; if ( @@ -316,7 +316,7 @@ void ChatMessagePrivate::loadFileTransferUrlFromBodyToContent() { void ChatMessagePrivate::sendImdn (Imdn::Type imdnType, LinphoneReason reason) { L_Q(); - shared_ptr msg = q->getChatRoom()->createMessage(); + shared_ptr msg = q->getChatRoom()->createChatMessage(); Content *content = new Content(); content->setContentType("message/imdn+xml"); @@ -332,7 +332,7 @@ LinphoneReason ChatMessagePrivate::receive () { LinphoneReason reason = LinphoneReasonNone; shared_ptr core = q->getCore(); - shared_ptr chatRoom = q->getChatRoom(); + shared_ptr chatRoom = q->getChatRoom(); setState(ChatMessage::State::Delivered); @@ -357,8 +357,7 @@ LinphoneReason ChatMessagePrivate::receive () { ChatMessageModifier::Result result = ecmm.decode(q->getSharedFromThis(), errorCode); if (result == ChatMessageModifier::Result::Error) { /* Unable to decrypt message */ - if (chatRoom) - chatRoom->getPrivate()->notifyUndecryptableMessageReceived(q->getSharedFromThis()); + chatRoom->getPrivate()->notifyUndecryptableMessageReceived(q->getSharedFromThis()); reason = linphone_error_code_to_reason(errorCode); q->sendDeliveryNotification(reason); return reason; @@ -416,7 +415,7 @@ LinphoneReason ChatMessagePrivate::receive () { setDirection(ChatMessage::Direction::Outgoing); // Check if this is a duplicate message. - if (chatRoom && chatRoom->findMessageWithDirection(imdnId, direction)) + if (chatRoom->findChatMessage(imdnId, direction)) return core->getCCore()->chat_deny_code; if (errorCode > 0) { @@ -632,9 +631,8 @@ void ChatMessagePrivate::store() { // ----------------------------------------------------------------------------- -ChatMessage::ChatMessage (const shared_ptr &chatRoom, ChatMessage::Direction direction) : +ChatMessage::ChatMessage (const shared_ptr &chatRoom, ChatMessage::Direction direction) : Object(*new ChatMessagePrivate), CoreAccessor(chatRoom->getCore()) { - L_ASSERT(chatRoom); L_D(); d->chatRoom = chatRoom; @@ -658,12 +656,17 @@ ChatMessage::~ChatMessage () { d->salOp->release(); } -shared_ptr ChatMessage::getChatRoom () const { +shared_ptr ChatMessage::getChatRoom () const { L_D(); - shared_ptr chatRoom = d->chatRoom.lock(); - if (!chatRoom) + shared_ptr chatRoom = d->chatRoom.lock(); + if (!chatRoom) { chatRoom = getCore()->getOrCreateBasicChatRoom(d->chatRoomId); + if (!chatRoom) { + lError() << "Unable to get valid chat room instance."; + throw logic_error("Unable to get chat room of chat message."); + } + } return chatRoom; } @@ -813,9 +816,7 @@ void ChatMessage::send () { return; } - shared_ptr chatRoom = getChatRoom(); - if (chatRoom) - chatRoom->getPrivate()->sendMessage(getSharedFromThis()); + getChatRoom()->getPrivate()->sendChatMessage(getSharedFromThis()); } void ChatMessage::sendDeliveryNotification (LinphoneReason reason) { @@ -860,9 +861,7 @@ int ChatMessage::putCharacter (uint32_t character) { static const uint32_t crlf = 0x0D0A; static const uint32_t lf = 0x0A; - shared_ptr chatRoom = getChatRoom(); - if (!chatRoom) - return -1; + shared_ptr chatRoom = getChatRoom(); shared_ptr rttcr = static_pointer_cast(chatRoom); diff --git a/src/chat/chat-message/chat-message.h b/src/chat/chat-message/chat-message.h index 8cb4a09d8..625ca702d 100644 --- a/src/chat/chat-message/chat-message.h +++ b/src/chat/chat-message/chat-message.h @@ -35,7 +35,7 @@ LINPHONE_BEGIN_NAMESPACE -class ChatRoom; +class AbstractChatRoom; class Content; class FileTransferContent; class ChatMessagePrivate; @@ -67,7 +67,7 @@ public: void setIsSecured (bool isSecured); // ----- TODO: Remove me. - std::shared_ptr getChatRoom () const; + std::shared_ptr getChatRoom () const; void send (); @@ -102,7 +102,7 @@ public: bool downloadFile (FileTransferContent &content); private: - ChatMessage (const std::shared_ptr &chatRoom, ChatMessage::Direction direction); + ChatMessage (const std::shared_ptr &chatRoom, ChatMessage::Direction direction); L_DECLARE_PRIVATE(ChatMessage); L_DISABLE_COPY(ChatMessage); diff --git a/src/chat/chat-room/abstract-chat-room-p.h b/src/chat/chat-room/abstract-chat-room-p.h new file mode 100644 index 000000000..1ed5a37ee --- /dev/null +++ b/src/chat/chat-room/abstract-chat-room-p.h @@ -0,0 +1,54 @@ +/* + * abstract-chat-room-p.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _ABSTRACT_CHAT_ROOM_P_H_ +#define _ABSTRACT_CHAT_ROOM_P_H_ + +#include "abstract-chat-room.h" +#include "object/object-p.h" + +// ============================================================================= + +L_DECL_C_STRUCT_PREFIX_LESS(SalMessage); + +LINPHONE_BEGIN_NAMESPACE + +class SalOp; + +class AbstractChatRoomPrivate : public ObjectPrivate { +public: + virtual void setCreationTime (time_t creationTime) = 0; + virtual void setLastUpdateTime (time_t lastUpdateTime) = 0; + + virtual void setState (AbstractChatRoom::State state) = 0; + + virtual void sendChatMessage (const std::shared_ptr &chatMessage) = 0; + + virtual void addTransientEvent (const std::shared_ptr &eventLog) = 0; + virtual void removeTransientEvent (const std::shared_ptr &eventLog) = 0; + + virtual void notifyUndecryptableMessageReceived (const std::shared_ptr &chatMessage) = 0; + + virtual void onChatMessageReceived (const std::shared_ptr &chatMessage) = 0; + virtual LinphoneReason onSipMessageReceived (SalOp *op, const SalMessage *message) = 0; +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _ABSTRACT_CHAT_ROOM_P_H_ diff --git a/src/chat/chat-room/abstract-chat-room.cpp b/src/chat/chat-room/abstract-chat-room.cpp new file mode 100644 index 000000000..3f3769214 --- /dev/null +++ b/src/chat/chat-room/abstract-chat-room.cpp @@ -0,0 +1,35 @@ +/* + * abstract-chat-room.cpp + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "abstract-chat-room-p.h" + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +// ----------------------------------------------------------------------------- + +AbstractChatRoom::AbstractChatRoom ( + AbstractChatRoomPrivate &p, + const shared_ptr &core +) : Object(p), CoreAccessor(core) {} + +LINPHONE_END_NAMESPACE diff --git a/src/chat/chat-room/abstract-chat-room.h b/src/chat/chat-room/abstract-chat-room.h new file mode 100644 index 000000000..c91ca0171 --- /dev/null +++ b/src/chat/chat-room/abstract-chat-room.h @@ -0,0 +1,98 @@ +/* + * abstract-chat-room.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _ABSTRACT_CHAT_ROOM_H_ +#define _ABSTRACT_CHAT_ROOM_H_ + +#include "chat/chat-message/chat-message.h" +#include "conference/conference-interface.h" +#include "core/core-accessor.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class AbstractChatRoomPrivate; +class ChatRoomId; +class EventLog; + +class LINPHONE_PUBLIC AbstractChatRoom : public Object, public CoreAccessor, public ConferenceInterface { + friend class ChatMessage; + friend class ChatMessagePrivate; + friend class CorePrivate; + friend class MainDb; + +public: + L_DECLARE_ENUM(Capabilities, L_ENUM_VALUES_CHAT_ROOM_CAPABILITIES); + L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_ROOM_STATE); + + typedef int CapabilitiesMask; + + virtual const ChatRoomId &getChatRoomId () const = 0; + + virtual const IdentityAddress &getPeerAddress () const = 0; + virtual const IdentityAddress &getLocalAddress () const = 0; + + virtual time_t getCreationTime () const = 0; + virtual time_t getLastUpdateTime () const = 0; + + virtual CapabilitiesMask getCapabilities () const = 0; + virtual State getState () const = 0; + virtual bool hasBeenLeft () 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; + + virtual void deleteHistory () = 0; + + virtual std::shared_ptr getLastChatMessageInHistory () const = 0; + + virtual int getChatMessageCount () const = 0; + virtual int getUnreadChatMessageCount () const = 0; + + virtual void compose () = 0; + virtual bool isRemoteComposing () const = 0; + virtual std::list getComposingAddresses () const = 0; + + virtual std::shared_ptr createChatMessage () = 0; + virtual std::shared_ptr createChatMessage (const std::string &text) = 0; + + // TODO: Remove LinphoneContent by LinphonePrivate::Content. + virtual std::shared_ptr createFileTransferMessage (const LinphoneContent *initialContent) = 0; + + virtual std::shared_ptr findChatMessage (const std::string &messageId) const = 0; + virtual std::shared_ptr findChatMessage ( + const std::string &messageId, + ChatMessage::Direction direction + ) const = 0; + + virtual void markAsRead () = 0; + +protected: + explicit AbstractChatRoom (AbstractChatRoomPrivate &p, const std::shared_ptr &core); + +private: + L_DECLARE_PRIVATE(AbstractChatRoom); + L_DISABLE_COPY(AbstractChatRoom); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _ABSTRACT_CHAT_ROOM_H_ diff --git a/src/chat/chat-room/basic-chat-room-p.h b/src/chat/chat-room/basic-chat-room-p.h index a87164730..e31863b6c 100644 --- a/src/chat/chat-room/basic-chat-room-p.h +++ b/src/chat/chat-room/basic-chat-room-p.h @@ -32,8 +32,6 @@ public: BasicChatRoomPrivate () = default; private: - void onChatMessageReceived (const std::shared_ptr &chatMessage) override; - std::string subject; std::list> participants; diff --git a/src/chat/chat-room/basic-chat-room.cpp b/src/chat/chat-room/basic-chat-room.cpp index 3ee9aca79..ae171bdb6 100644 --- a/src/chat/chat-room/basic-chat-room.cpp +++ b/src/chat/chat-room/basic-chat-room.cpp @@ -31,10 +31,6 @@ LINPHONE_BEGIN_NAMESPACE // ----------------------------------------------------------------------------- -void BasicChatRoomPrivate::onChatMessageReceived (const shared_ptr &) {} - -// ----------------------------------------------------------------------------- - BasicChatRoom::BasicChatRoom (const shared_ptr &core, const ChatRoomId &chatRoomId) : ChatRoom(*new BasicChatRoomPrivate, core, chatRoomId) {} diff --git a/src/chat/chat-room/basic-to-client-group-chat-room.cpp b/src/chat/chat-room/basic-to-client-group-chat-room.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/src/chat/chat-room/basic-to-client-group-chat-room.h b/src/chat/chat-room/basic-to-client-group-chat-room.h new file mode 100644 index 000000000..e69de29bb diff --git a/src/chat/chat-room/chat-room-p.h b/src/chat/chat-room/chat-room-p.h index 4ba48402b..f91c1e947 100644 --- a/src/chat/chat-room/chat-room-p.h +++ b/src/chat/chat-room/chat-room-p.h @@ -20,46 +20,50 @@ #ifndef _CHAT_ROOM_P_H_ #define _CHAT_ROOM_P_H_ -#include - -#include "chat/notification/is-composing.h" +#include "abstract-chat-room-p.h" +#include "chat-room-id.h" #include "chat-room.h" -#include "object/object-p.h" +#include "chat/notification/is-composing.h" #include "event-log/event-log.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE -// TODO: clean and order methods! -class ChatRoomPrivate : public ObjectPrivate, public IsComposingListener { +class ChatRoomPrivate : public AbstractChatRoomPrivate, public IsComposingListener { public: - ChatRoomPrivate () = default; + void setCreationTime (time_t creationTime) override { + this->creationTime = creationTime; + } - void addTransientEvent (const std::shared_ptr &log); - void removeTransientEvent (const std::shared_ptr &log); + void setLastUpdateTime (time_t lastUpdateTime) override { + this->lastUpdateTime = lastUpdateTime; + } - void release (); + void setState (ChatRoom::State state) override; - void setState (ChatRoom::State newState); + void sendChatMessage (const std::shared_ptr &chatMessage) override; - virtual void sendMessage (const std::shared_ptr &msg); + void addTransientEvent (const std::shared_ptr &eventLog) override; + void removeTransientEvent (const std::shared_ptr &eventLog) override; + + void notifyUndecryptableMessageReceived (const std::shared_ptr &chatMessage) override; + + void onChatMessageReceived (const std::shared_ptr &chatMessage) override; + LinphoneReason onSipMessageReceived (SalOp *op, const SalMessage *message) override; + + // TODO: After this point clean and order methods (AND set members private if possible)!!! void sendIsComposingNotification (); std::list> findMessages (const std::string &messageId) const; - virtual LinphoneReason messageReceived (SalOp *op, const SalMessage *msg); - void realtimeTextReceived (uint32_t character, LinphoneCall *call); - - void chatMessageReceived (const std::shared_ptr &msg); void imdnReceived (const std::string &text); void isComposingReceived (const Address &remoteAddr, const std::string &text); void notifyChatMessageReceived (const std::shared_ptr &msg); void notifyIsComposingReceived (const Address &remoteAddr, bool isComposing); void notifyStateChanged (); - void notifyUndecryptableMessageReceived (const std::shared_ptr &msg); /* IsComposingListener */ void onIsComposingStateChanged (bool isComposing) override; @@ -70,7 +74,7 @@ public: LinphoneCall *call = nullptr; bool isComposing = false; - std::list
remoteIsComposing; + std::list remoteIsComposing; std::list> transientEvents; // TODO: Remove me. Must be present only in rtt chat room. @@ -83,9 +87,6 @@ public: ChatRoom::State state = ChatRoom::State::None; -public: - virtual void onChatMessageReceived (const std::shared_ptr &chatMessage) = 0; - ChatRoomId chatRoomId; time_t creationTime = std::time(nullptr); diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 194c02626..309431ad2 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -50,12 +50,6 @@ void ChatRoomPrivate::removeTransientEvent (const shared_ptr &log) { // ----------------------------------------------------------------------------- -void ChatRoomPrivate::release () { - isComposingHandler->stopTimers(); -} - -// ----------------------------------------------------------------------------- - void ChatRoomPrivate::setState (ChatRoom::State newState) { if (newState != state) { state = newState; @@ -93,7 +87,7 @@ list > ChatRoomPrivate::findMessages (const string &mess return q->getCore()->getPrivate()->mainDb->findChatMessages(q->getChatRoomId(), messageId); } -void ChatRoomPrivate::sendMessage (const shared_ptr &msg) { +void ChatRoomPrivate::sendChatMessage (const shared_ptr &msg) { L_Q(); // TODO: Check direction. @@ -125,7 +119,7 @@ void ChatRoomPrivate::sendMessage (const shared_ptr &msg) { // ----------------------------------------------------------------------------- -LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *salMsg) { +LinphoneReason ChatRoomPrivate::onSipMessageReceived (SalOp *op, const SalMessage *message) { L_Q(); bool increaseMsgCount = true; @@ -142,11 +136,11 @@ LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *sa ); Content content; - content.setContentType(salMsg->content_type); - content.setBody(salMsg->text ? salMsg->text : ""); + content.setContentType(message->content_type); + content.setBody(message->text ? message->text : ""); msg->setInternalContent(content); - msg->getPrivate()->setTime(salMsg->time); + msg->getPrivate()->setTime(message->time); msg->getPrivate()->setImdnMessageId(op->get_call_id()); const SalCustomHeader *ch = op->get_recv_custom_header(); @@ -182,7 +176,7 @@ LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *sa pendingMessage = msg; } - chatMessageReceived(msg); + onChatMessageReceived(msg); pendingMessage = nullptr; @@ -192,7 +186,7 @@ end: // ----------------------------------------------------------------------------- -void ChatRoomPrivate::chatMessageReceived (const shared_ptr &msg) { +void ChatRoomPrivate::onChatMessageReceived (const shared_ptr &msg) { L_Q(); if ((msg->getPrivate()->getContentType() != ContentType::Imdn) && (msg->getPrivate()->getContentType() != ContentType::ImIsComposing)) { @@ -305,7 +299,7 @@ void ChatRoomPrivate::onIsComposingRefreshNeeded () { // ============================================================================= ChatRoom::ChatRoom (ChatRoomPrivate &p, const shared_ptr &core, const ChatRoomId &chatRoomId) : - Object(p), CoreAccessor(core) { + AbstractChatRoom(p, core) { L_D(); d->chatRoomId = chatRoomId; @@ -343,31 +337,38 @@ time_t ChatRoom::getLastUpdateTime () const { // ----------------------------------------------------------------------------- -list> ChatRoom::getHistory (int nLast) { +ChatRoom::State ChatRoom::getState () const { + L_D(); + return d->state; +} + +// ----------------------------------------------------------------------------- + +list> ChatRoom::getHistory (int nLast) const { return getCore()->getPrivate()->mainDb->getHistory(getChatRoomId(), nLast); } -list> ChatRoom::getHistoryRange (int begin, int end) { +list> ChatRoom::getHistoryRange (int begin, int end) const { return getCore()->getPrivate()->mainDb->getHistoryRange(getChatRoomId(), begin, end); } -int ChatRoom::getHistorySize () { +int ChatRoom::getHistorySize () const { return getCore()->getPrivate()->mainDb->getHistorySize(getChatRoomId()); } -shared_ptr ChatRoom::getLastChatMessageInHistory() const { - return getCore()->getPrivate()->mainDb->getLastChatMessage(getChatRoomId()); -} - void ChatRoom::deleteHistory () { getCore()->getPrivate()->mainDb->cleanHistory(getChatRoomId()); } -int ChatRoom::getChatMessageCount () { +shared_ptr ChatRoom::getLastChatMessageInHistory() const { + return getCore()->getPrivate()->mainDb->getLastChatMessage(getChatRoomId()); +} + +int ChatRoom::getChatMessageCount () const { return getCore()->getPrivate()->mainDb->getChatMessageCount(getChatRoomId()); } -int ChatRoom::getUnreadChatMessageCount () { +int ChatRoom::getUnreadChatMessageCount () const { return getCore()->getPrivate()->mainDb->getUnreadChatMessageCount(getChatRoomId()); } @@ -383,27 +384,41 @@ void ChatRoom::compose () { d->isComposingHandler->startIdleTimer(); } -shared_ptr ChatRoom::createFileTransferMessage (const LinphoneContent *initialContent) { - shared_ptr chatMessage = createMessage(); - chatMessage->getPrivate()->setFileTransferInformation(initialContent); - return chatMessage; +bool ChatRoom::isRemoteComposing () const { + L_D(); + return !d->remoteIsComposing.empty(); } -shared_ptr ChatRoom::createMessage (const string &message) { - shared_ptr chatMessage = createMessage(); - Content *content = new Content(); - content->setContentType(ContentType::PlainText); - content->setBody(message); - chatMessage->addContent(*content); - return chatMessage; +std::list ChatRoom::getComposingAddresses () const { + L_D(); + return d->remoteIsComposing; } -shared_ptr ChatRoom::createMessage () { +// ----------------------------------------------------------------------------- + +shared_ptr ChatRoom::createChatMessage () { L_D(); return d->createChatMessage(ChatMessage::Direction::Outgoing); } -shared_ptr ChatRoom::findMessage (const string &messageId) { +shared_ptr ChatRoom::createChatMessage (const string &text) { + shared_ptr chatMessage = createChatMessage(); + Content *content = new Content(); + content->setContentType(ContentType::PlainText); + content->setBody(text); + chatMessage->addContent(*content); + return chatMessage; +} + +shared_ptr ChatRoom::createFileTransferMessage (const LinphoneContent *initialContent) { + shared_ptr chatMessage = createChatMessage(); + chatMessage->getPrivate()->setFileTransferInformation(initialContent); + return chatMessage; +} + +// ----------------------------------------------------------------------------- + +shared_ptr ChatRoom::findChatMessage (const string &messageId) const { L_D(); shared_ptr cm = nullptr; list > l = d->findMessages(messageId); @@ -413,7 +428,7 @@ shared_ptr ChatRoom::findMessage (const string &messageId) { return cm; } -shared_ptr ChatRoom::findMessageWithDirection (const string &messageId, ChatMessage::Direction direction) { +shared_ptr ChatRoom::findChatMessage (const string &messageId, ChatMessage::Direction direction) const { L_D(); shared_ptr ret = nullptr; list > l = d->findMessages(messageId); @@ -426,16 +441,6 @@ shared_ptr ChatRoom::findMessageWithDirection (const string &messag return ret; } -bool ChatRoom::isRemoteComposing () const { - L_D(); - return d->remoteIsComposing.size() > 0; -} - -std::list
ChatRoom::getComposingAddresses () const { - L_D(); - return d->remoteIsComposing; -} - void ChatRoom::markAsRead () { L_D(); @@ -455,11 +460,4 @@ void ChatRoom::markAsRead () { } } -// ----------------------------------------------------------------------------- - -ChatRoom::State ChatRoom::getState () const { - L_D(); - return d->state; -} - LINPHONE_END_NAMESPACE diff --git a/src/chat/chat-room/chat-room.h b/src/chat/chat-room/chat-room.h index b276c83c3..e8fd16d4d 100644 --- a/src/chat/chat-room/chat-room.h +++ b/src/chat/chat-room/chat-room.h @@ -20,70 +20,59 @@ #ifndef _CHAT_ROOM_H_ #define _CHAT_ROOM_H_ -#include "chat/chat-message/chat-message.h" -#include "chat/chat-room/chat-room-id.h" -#include "conference/conference-interface.h" +#include "abstract-chat-room.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE class ChatRoomPrivate; -class EventLog; -class LINPHONE_PUBLIC ChatRoom : public Object, public CoreAccessor, public ConferenceInterface { - friend class ChatMessage; - friend class ChatMessagePrivate; +class LINPHONE_PUBLIC ChatRoom : public AbstractChatRoom { friend class Core; - friend class CorePrivate; friend class FileTransferChatMessageModifier; - friend class MainDb; public: L_OVERRIDE_SHARED_FROM_THIS(ChatRoom); - L_DECLARE_ENUM(Capabilities, L_ENUM_VALUES_CHAT_ROOM_CAPABILITIES); - L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_ROOM_STATE); + const ChatRoomId &getChatRoomId () const override; - typedef int CapabilitiesMask; + const IdentityAddress &getPeerAddress () const override; + const IdentityAddress &getLocalAddress () const override; - virtual ~ChatRoom () = default; + time_t getCreationTime () const override; + time_t getLastUpdateTime () const override; - const ChatRoomId &getChatRoomId () const; + State getState () const override; - const IdentityAddress &getPeerAddress () const; - const IdentityAddress &getLocalAddress () const; + std::list> getHistory (int nLast) const override; + std::list> getHistoryRange (int begin, int end) const override; + int getHistorySize () const override; - time_t getCreationTime () const; - time_t getLastUpdateTime () const; + void deleteHistory () override; - virtual CapabilitiesMask getCapabilities () const = 0; - virtual bool hasBeenLeft () const = 0; + std::shared_ptr getLastChatMessageInHistory () const override; - std::list> getHistory (int nLast); - std::list> getHistoryRange (int begin, int end); - int getHistorySize (); + int getChatMessageCount () const override; + int getUnreadChatMessageCount () const override; - std::shared_ptr getLastChatMessageInHistory () const; + void compose () override; + bool isRemoteComposing () const override; + std::list getComposingAddresses () const override; - void deleteHistory (); + std::shared_ptr createChatMessage () override; + std::shared_ptr createChatMessage (const std::string &text) override; - int getChatMessageCount (); - int getUnreadChatMessageCount (); + // TODO: Remove LinphoneContent by LinphonePrivate::Content. + std::shared_ptr createFileTransferMessage (const LinphoneContent *initialContent) override; - // TODO: Remove useless functions. - void compose (); - std::shared_ptr createFileTransferMessage (const LinphoneContent *initialContent); - std::shared_ptr createMessage (const std::string &msg); - std::shared_ptr createMessage (); - std::shared_ptr findMessage (const std::string &messageId); - std::shared_ptr findMessageWithDirection (const std::string &messageId, ChatMessage::Direction direction); - bool isRemoteComposing () const; - std::list
getComposingAddresses () const; + std::shared_ptr findChatMessage (const std::string &messageId) const override; + std::shared_ptr findChatMessage ( + const std::string &messageId, + ChatMessage::Direction direction + ) const override; - virtual void markAsRead (); - - State getState () const; + void markAsRead () override; protected: explicit ChatRoom (ChatRoomPrivate &p, const std::shared_ptr &core, const ChatRoomId &chatRoomId); diff --git a/src/chat/chat-room/client-group-chat-room-p.h b/src/chat/chat-room/client-group-chat-room-p.h index a1f32ac56..de830bdd6 100644 --- a/src/chat/chat-room/client-group-chat-room-p.h +++ b/src/chat/chat-room/client-group-chat-room-p.h @@ -42,8 +42,6 @@ private: void onCallSessionSetReleased (const std::shared_ptr &session) override; void onCallSessionStateChanged (const std::shared_ptr &session, LinphoneCallState state, const std::string &message) override; - void onChatMessageReceived (const std::shared_ptr &chatMessage) override; - L_DECLARE_PUBLIC(ClientGroupChatRoom); }; diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index 309782419..05e0c7433 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -114,10 +114,6 @@ void ClientGroupChatRoomPrivate::onCallSessionStateChanged ( } } -// ----------------------------------------------------------------------------- - -void ClientGroupChatRoomPrivate::onChatMessageReceived (const shared_ptr &) {} - // ============================================================================= ClientGroupChatRoom::ClientGroupChatRoom ( diff --git a/src/chat/chat-room/real-time-text-chat-room-p.h b/src/chat/chat-room/real-time-text-chat-room-p.h index c07697a38..4e1142340 100644 --- a/src/chat/chat-room/real-time-text-chat-room-p.h +++ b/src/chat/chat-room/real-time-text-chat-room-p.h @@ -33,7 +33,7 @@ public: ~RealTimeTextChatRoomPrivate (); void realtimeTextReceived (uint32_t character, LinphoneCall *call); - void sendMessage (const std::shared_ptr &msg) override; + void sendChatMessage (const std::shared_ptr &chatMessage) override; LinphoneCall *call = nullptr; std::list receivedRttCharacters; diff --git a/src/chat/chat-room/real-time-text-chat-room.cpp b/src/chat/chat-room/real-time-text-chat-room.cpp index 1a8dde51d..4e9ef0f9f 100644 --- a/src/chat/chat-room/real-time-text-chat-room.cpp +++ b/src/chat/chat-room/real-time-text-chat-room.cpp @@ -52,7 +52,7 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp LinphoneChatMessageCharacter *cmc = bctbx_new0(LinphoneChatMessageCharacter, 1); if (!pendingMessage) - pendingMessage = q->createMessage(""); + pendingMessage = q->createChatMessage(""); cmc->value = character; cmc->has_been_read = FALSE; @@ -79,7 +79,7 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp if (lp_config_get_int(linphone_core_get_config(cCore), "misc", "store_rtt_messages", 1) == 1) pendingMessage->getPrivate()->store(); - chatMessageReceived(pendingMessage); + onChatMessageReceived(pendingMessage); pendingMessage = nullptr; for (auto &rttChars : receivedRttCharacters) ms_free(rttChars); @@ -94,10 +94,10 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp } } -void RealTimeTextChatRoomPrivate::sendMessage (const shared_ptr &msg) { +void RealTimeTextChatRoomPrivate::sendChatMessage (const shared_ptr &chatMessage) { if (call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(call))) { uint32_t new_line = 0x2028; - msg->putCharacter(new_line); + chatMessage->putCharacter(new_line); } } diff --git a/src/chat/chat-room/server-group-chat-room-p.h b/src/chat/chat-room/server-group-chat-room-p.h index 6565b4157..be7dd87f7 100644 --- a/src/chat/chat-room/server-group-chat-room-p.h +++ b/src/chat/chat-room/server-group-chat-room-p.h @@ -48,7 +48,7 @@ public: void update (SalCallOp *op); void dispatchMessage (const IdentityAddress &fromAddr, const Content &content); - LinphoneReason messageReceived (SalOp *op, const SalMessage *msg) override; + LinphoneReason onSipMessageReceived (SalOp *op, const SalMessage *message) override; void setConferenceAddress (const IdentityAddress &confAddr); private: @@ -59,8 +59,6 @@ private: // CallSessionListener void onCallSessionStateChanged (const std::shared_ptr &session, LinphoneCallState state, const std::string &message) override; - void onChatMessageReceived (const std::shared_ptr &) override; - std::list> removedParticipants; L_DECLARE_PUBLIC(ServerGroupChatRoom); diff --git a/src/chat/chat-room/server-group-chat-room-stub.cpp b/src/chat/chat-room/server-group-chat-room-stub.cpp index 44606273c..8a5fa5ceb 100644 --- a/src/chat/chat-room/server-group-chat-room-stub.cpp +++ b/src/chat/chat-room/server-group-chat-room-stub.cpp @@ -57,7 +57,7 @@ void ServerGroupChatRoomPrivate::update (SalCallOp *) {} void ServerGroupChatRoomPrivate::dispatchMessage (const IdentityAddress &, const Content &) {} -LinphoneReason ServerGroupChatRoomPrivate::messageReceived (SalOp *, const SalMessage *) { +LinphoneReason ServerGroupChatRoomPrivate::onSipMessageReceived (SalOp *, const SalMessage *) { return LinphoneReasonNone; } @@ -81,10 +81,6 @@ void ServerGroupChatRoomPrivate::onCallSessionStateChanged ( const string & ) {} -// ----------------------------------------------------------------------------- - -void ServerGroupChatRoomPrivate::onChatMessageReceived(const shared_ptr &) {} - // ============================================================================= ServerGroupChatRoom::ServerGroupChatRoom (const shared_ptr &core, SalCallOp *op) : diff --git a/src/chat/modifier/encryption-chat-message-modifier.cpp b/src/chat/modifier/encryption-chat-message-modifier.cpp index e9e408376..dc7763c8b 100644 --- a/src/chat/modifier/encryption-chat-message-modifier.cpp +++ b/src/chat/modifier/encryption-chat-message-modifier.cpp @@ -37,7 +37,7 @@ ChatMessageModifier::Result EncryptionChatMessageModifier::encode ( const shared_ptr &message, int &errorCode ) { - shared_ptr chatRoom = message->getChatRoom(); + shared_ptr chatRoom = message->getChatRoom(); LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(chatRoom->getCore()->getCCore()); if (!imee) return ChatMessageModifier::Result::Skipped; @@ -70,7 +70,7 @@ ChatMessageModifier::Result EncryptionChatMessageModifier::decode ( const shared_ptr &message, int &errorCode ) { - shared_ptr chatRoom = message->getChatRoom(); + shared_ptr chatRoom = message->getChatRoom(); LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(chatRoom->getCore()->getCCore()); if (!imee) return ChatMessageModifier::Result::Skipped; @@ -95,7 +95,7 @@ ChatMessageModifier::Result EncryptionChatMessageModifier::decode ( message->setIsSecured(true); if (retval == 1) return ChatMessageModifier::Result::Suspended; - + return ChatMessageModifier::Result::Done; } diff --git a/src/chat/notification/imdn.cpp b/src/chat/notification/imdn.cpp index 39081659c..dfa5bfdfb 100644 --- a/src/chat/notification/imdn.cpp +++ b/src/chat/notification/imdn.cpp @@ -163,7 +163,7 @@ void Imdn::parse (ChatRoom &cr, xmlparsing_context_t *xmlCtx) { } if (messageIdStr && datetimeStr) { - shared_ptr cm = cr.findMessageWithDirection(messageIdStr, ChatMessage::Direction::Outgoing); + shared_ptr cm = cr.findChatMessage(messageIdStr, ChatMessage::Direction::Outgoing); if (!cm) { lWarning() << "Received IMDN for unknown message " << messageIdStr; } else { diff --git a/src/core/core-chat-room.cpp b/src/core/core-chat-room.cpp index 94e3d9df7..3c92d662a 100644 --- a/src/core/core-chat-room.cpp +++ b/src/core/core-chat-room.cpp @@ -61,28 +61,27 @@ static IdentityAddress getDefaultLocalAddress (const shared_ptr &core, con // ----------------------------------------------------------------------------- -shared_ptr CorePrivate::createBasicChatRoom (const ChatRoomId &chatRoomId, bool isRtt, bool notifyCreation) { +shared_ptr CorePrivate::createBasicChatRoom ( + const ChatRoomId &chatRoomId, + bool isRtt +) { L_Q(); - shared_ptr chatRoom; + shared_ptr chatRoom; if (isRtt) chatRoom.reset(new RealTimeTextChatRoom(q->getSharedFromThis(), chatRoomId)); else chatRoom.reset(new BasicChatRoom(q->getSharedFromThis(), chatRoomId)); - ChatRoomPrivate *dChatRoom = chatRoom->getPrivate(); - - if (notifyCreation) { - dChatRoom->setState(ChatRoom::State::Instantiated); - dChatRoom->setState(ChatRoom::State::Created); - } else - dChatRoom->state = ChatRoom::State::Created; + AbstractChatRoomPrivate *dChatRoom = chatRoom->getPrivate(); + dChatRoom->setState(ChatRoom::State::Instantiated); + dChatRoom->setState(ChatRoom::State::Created); return chatRoom; } -void CorePrivate::insertChatRoom (const shared_ptr &chatRoom) { +void CorePrivate::insertChatRoom (const shared_ptr &chatRoom) { L_ASSERT(chatRoom); L_Q(); @@ -91,19 +90,19 @@ void CorePrivate::insertChatRoom (const shared_ptr &chatRoom) { chatRoomsById[chatRoom->getChatRoomId()] = chatRoom; } -void CorePrivate::insertChatRoomWithDb (const shared_ptr &chatRoom) { +void CorePrivate::insertChatRoomWithDb (const shared_ptr &chatRoom) { L_ASSERT(chatRoom->getState() == ChatRoom::State::Created); mainDb->insertChatRoom(chatRoom); } // ----------------------------------------------------------------------------- -const list> &Core::getChatRooms () const { +const list> &Core::getChatRooms () const { L_D(); return d->chatRooms; } -shared_ptr Core::findChatRoom (const ChatRoomId &chatRoomId) const { +shared_ptr Core::findChatRoom (const ChatRoomId &chatRoomId) const { L_D(); auto it = d->chatRoomsById.find(chatRoomId); @@ -116,14 +115,13 @@ shared_ptr Core::findChatRoom (const ChatRoomId &chatRoomId) const { return shared_ptr(); } -list> Core::findChatRooms (const IdentityAddress &peerAddress) const { +list> Core::findChatRooms (const IdentityAddress &peerAddress) const { L_D(); - // TODO: Improve performance if necessary. - list> output; + list> output; copy_if( d->chatRooms.begin(), d->chatRooms.end(), - back_inserter(output), [&peerAddress](const shared_ptr &chatRoom) { + back_inserter(output), [&peerAddress](const shared_ptr &chatRoom) { return chatRoom->getPeerAddress() == peerAddress; } ); @@ -131,7 +129,7 @@ list> Core::findChatRooms (const IdentityAddress &peerAddre return output; } -shared_ptr Core::findOneToOneChatRoom ( +shared_ptr Core::findOneToOneChatRoom ( const IdentityAddress &localAddress, const IdentityAddress &participantAddress ) const { @@ -147,7 +145,7 @@ shared_ptr Core::findOneToOneChatRoom ( return nullptr; } -shared_ptr Core::createClientGroupChatRoom (const string &subject) { +shared_ptr Core::createClientGroupChatRoom (const string &subject) { return L_GET_CPP_PTR_FROM_C_OBJECT( _linphone_client_group_chat_room_new( getCCore(), @@ -157,10 +155,10 @@ shared_ptr Core::createClientGroupChatRoom (const string &subject) { ); } -shared_ptr Core::getOrCreateBasicChatRoom (const ChatRoomId &chatRoomId, bool isRtt) { +shared_ptr Core::getOrCreateBasicChatRoom (const ChatRoomId &chatRoomId, bool isRtt) { L_D(); - shared_ptr chatRoom = findChatRoom(chatRoomId); + shared_ptr chatRoom = findChatRoom(chatRoomId); if (chatRoom) return chatRoom; @@ -171,14 +169,14 @@ shared_ptr Core::getOrCreateBasicChatRoom (const ChatRoomId &chatRoomI return chatRoom; } -shared_ptr Core::getOrCreateBasicChatRoom (const IdentityAddress &peerAddress, bool isRtt) { +shared_ptr Core::getOrCreateBasicChatRoom (const IdentityAddress &peerAddress, bool isRtt) { L_D(); - list> chatRooms = findChatRooms(peerAddress); + list> chatRooms = findChatRooms(peerAddress); if (!chatRooms.empty()) return chatRooms.front(); - shared_ptr chatRoom = d->createBasicChatRoom( + shared_ptr chatRoom = d->createBasicChatRoom( ChatRoomId(peerAddress, getDefaultLocalAddress(getSharedFromThis(), peerAddress)), isRtt ); @@ -188,19 +186,19 @@ shared_ptr Core::getOrCreateBasicChatRoom (const IdentityAddress &peer return chatRoom; } -shared_ptr Core::getOrCreateBasicChatRoomFromUri (const string &peerAddress, bool isRtt) { +shared_ptr Core::getOrCreateBasicChatRoomFromUri (const string &peerAddress, bool isRtt) { LinphoneAddress *address = linphone_core_interpret_url(getCCore(), L_STRING_TO_C(peerAddress)); if (!address) { lError() << "Cannot make a valid address with: `" << peerAddress << "`."; return nullptr; } - shared_ptr chatRoom = getOrCreateBasicChatRoom(*L_GET_CPP_PTR_FROM_C_OBJECT(address), isRtt); + shared_ptr chatRoom = getOrCreateBasicChatRoom(*L_GET_CPP_PTR_FROM_C_OBJECT(address), isRtt); linphone_address_unref(address); return chatRoom; } -void Core::deleteChatRoom (const shared_ptr &chatRoom) { +void Core::deleteChatRoom (const shared_ptr &chatRoom) { CorePrivate *d = chatRoom->getCore()->getPrivate(); const ChatRoomId &chatRoomId = chatRoom->getChatRoomId(); diff --git a/src/core/core-p.h b/src/core/core-p.h index a887b7f47..d3aa6ad0a 100644 --- a/src/core/core-p.h +++ b/src/core/core-p.h @@ -52,9 +52,9 @@ public: void setCurrentCall (const std::shared_ptr &call) { currentCall = call; } void unsetVideoWindowId (bool preview, void *id); - void insertChatRoom (const std::shared_ptr &chatRoom); - void insertChatRoomWithDb (const std::shared_ptr &chatRoom); - std::shared_ptr createBasicChatRoom (const ChatRoomId &chatRoomId, bool isRtt, bool notifyCreation = true); + void insertChatRoom (const std::shared_ptr &chatRoom); + void insertChatRoomWithDb (const std::shared_ptr &chatRoom); + std::shared_ptr createBasicChatRoom (const ChatRoomId &chatRoomId, bool isRtt); std::unique_ptr mainDb; @@ -64,8 +64,8 @@ private: std::list> calls; std::shared_ptr currentCall; - std::list> chatRooms; - std::unordered_map> chatRoomsById; + std::list> chatRooms; + std::unordered_map> chatRoomsById; L_DECLARE_PUBLIC(Core); }; diff --git a/src/core/core.h b/src/core/core.h index 8002d1d88..a0e485295 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -34,10 +34,10 @@ LINPHONE_BEGIN_NAMESPACE class Address; class Call; -class ChatRoom; class ChatRoomId; class CorePrivate; class IdentityAddress; +class AbstractChatRoom; class LINPHONE_PUBLIC Core : public Object { friend class CallPrivate; @@ -86,25 +86,28 @@ public: // ChatRoom. // --------------------------------------------------------------------------- - const std::list> &getChatRooms () const; + const std::list> &getChatRooms () const; - std::shared_ptr findChatRoom (const ChatRoomId &chatRoomId) const; - std::list> findChatRooms (const IdentityAddress &peerAddress) const; + std::shared_ptr findChatRoom (const ChatRoomId &chatRoomId) const; + std::list> findChatRooms (const IdentityAddress &peerAddress) const; - std::shared_ptr findOneToOneChatRoom ( + std::shared_ptr findOneToOneChatRoom ( const IdentityAddress &localAddress, const IdentityAddress &participantAddress ) const; - std::shared_ptr createClientGroupChatRoom (const std::string &subject); - std::shared_ptr createClientGroupChatRoom (const std::string &subject, const IdentityAddress &localAddress); + std::shared_ptr createClientGroupChatRoom (const std::string &subject); + std::shared_ptr createClientGroupChatRoom ( + const std::string &subject, + const IdentityAddress &localAddress + ); - std::shared_ptr getOrCreateBasicChatRoom (const ChatRoomId &chatRoomId, bool isRtt = false); - std::shared_ptr getOrCreateBasicChatRoom (const IdentityAddress &peerAddress, bool isRtt = false); + std::shared_ptr getOrCreateBasicChatRoom (const ChatRoomId &chatRoomId, bool isRtt = false); + std::shared_ptr getOrCreateBasicChatRoom (const IdentityAddress &peerAddress, bool isRtt = false); - std::shared_ptr getOrCreateBasicChatRoomFromUri (const std::string &uri, bool isRtt = false); + std::shared_ptr getOrCreateBasicChatRoomFromUri (const std::string &uri, bool isRtt = false); - static void deleteChatRoom (const std::shared_ptr &chatRoom); + static void deleteChatRoom (const std::shared_ptr &chatRoom); // --------------------------------------------------------------------------- // Paths. diff --git a/src/db/main-db-p.h b/src/db/main-db-p.h index 29a681d58..4a0c2bc21 100644 --- a/src/db/main-db-p.h +++ b/src/db/main-db-p.h @@ -58,7 +58,7 @@ private: long long localSipAddressId, const tm &creationTime ); - long long insertChatRoom (const std::shared_ptr &chatRoom); + long long insertChatRoom (const std::shared_ptr &chatRoom); long long insertChatRoomParticipant (long long chatRoomId, long long participantSipAddressId, bool isAdmin); void insertChatRoomParticipantDevice (long long participantId, long long participantDeviceSipAddressId); void insertChatMessageParticipant (long long messageEventId, long long sipAddressId, int state); diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index ab399c0c7..c1925c8e7 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -234,7 +234,7 @@ static inline string blobToString (soci::blob &in) { return q->getLastInsertId(); } - long long MainDbPrivate::insertChatRoom (const shared_ptr &chatRoom) { + long long MainDbPrivate::insertChatRoom (const shared_ptr &chatRoom) { L_Q(); soci::session *session = dbSession.getBackendSession(); @@ -501,7 +501,7 @@ static inline string blobToString (soci::blob &in) { L_Q(); shared_ptr core = q->getCore(); - shared_ptr chatRoom = core->findChatRoom(chatRoomId); + shared_ptr chatRoom = core->findChatRoom(chatRoomId); if (!chatRoom) { lError() << "Unable to find chat room storage id of (peer=" + chatRoomId.getPeerAddress().asString() + @@ -756,7 +756,7 @@ static inline string blobToString (soci::blob &in) { long long MainDbPrivate::insertConferenceChatMessageEvent (const shared_ptr &eventLog) { shared_ptr chatMessage = static_pointer_cast(eventLog)->getChatMessage(); - shared_ptr chatRoom = chatMessage->getChatRoom(); + shared_ptr chatRoom = chatMessage->getChatRoom(); if (!chatRoom) { lError() << "Unable to get a valid chat room. It was removed from database."; return -1; @@ -794,7 +794,7 @@ static inline string blobToString (soci::blob &in) { void MainDbPrivate::updateConferenceChatMessageEvent (const shared_ptr &eventLog) { shared_ptr chatMessage = static_pointer_cast(eventLog)->getChatMessage(); - shared_ptr chatRoom = chatMessage->getChatRoom(); + shared_ptr chatRoom = chatMessage->getChatRoom(); if (!chatRoom) { lError() << "Unable to get a valid chat room. It was removed from database."; return; @@ -1972,7 +1972,7 @@ static inline string blobToString (soci::blob &in) { // ----------------------------------------------------------------------------- - list> MainDb::getChatRooms () const { + list> MainDb::getChatRooms () const { static const string query = "SELECT chat_room.id, peer_sip_address.value, local_sip_address.value, " "creation_time, last_update_time, capabilities, subject, last_notify_id, flags" " FROM chat_room, sip_address AS peer_sip_address, sip_address AS local_sip_address" @@ -1981,7 +1981,7 @@ static inline string blobToString (soci::blob &in) { L_D(); - list> chatRooms; + list> chatRooms; if (!isConnected()) { lWarning() << "Unable to get chat rooms. Not connected."; @@ -2002,7 +2002,7 @@ static inline string blobToString (soci::blob &in) { IdentityAddress(row.get(1)), IdentityAddress(row.get(2)) ); - shared_ptr chatRoom = core->findChatRoom(chatRoomId); + shared_ptr chatRoom = core->findChatRoom(chatRoomId); if (chatRoom) { chatRooms.push_back(chatRoom); continue; @@ -2019,8 +2019,7 @@ static inline string blobToString (soci::blob &in) { if (capabilities & static_cast(ChatRoom::Capabilities::Basic)) { chatRoom = core->getPrivate()->createBasicChatRoom( chatRoomId, - capabilities & static_cast(ChatRoom::Capabilities::RealTimeText), - false + capabilities & static_cast(ChatRoom::Capabilities::RealTimeText) ); chatRoom->setSubject(subject); } else if (capabilities & static_cast(ChatRoom::Capabilities::Conference)) { @@ -2081,9 +2080,9 @@ static inline string blobToString (soci::blob &in) { if (!chatRoom) continue; // Not fetched. - ChatRoomPrivate *dChatRoom = chatRoom->getPrivate(); - dChatRoom->creationTime = Utils::getTmAsTimeT(creationTime); - dChatRoom->lastUpdateTime = Utils::getTmAsTimeT(lastUpdateTime); + AbstractChatRoomPrivate *dChatRoom = chatRoom->getPrivate(); + dChatRoom->setCreationTime(Utils::getTmAsTimeT(creationTime)); + dChatRoom->setLastUpdateTime(Utils::getTmAsTimeT(lastUpdateTime)); lInfo() << "Found chat room in DB: (peer=" << chatRoomId.getPeerAddress().asString() << ", local=" << chatRoomId.getLocalAddress().asString() << ")."; @@ -2096,10 +2095,10 @@ static inline string blobToString (soci::blob &in) { L_END_LOG_EXCEPTION // Error. - return list>(); + return list>(); } - void MainDb::insertChatRoom (const shared_ptr &chatRoom) { + void MainDb::insertChatRoom (const shared_ptr &chatRoom) { L_D(); if (!isConnected()) { @@ -2379,11 +2378,11 @@ static inline string blobToString (soci::blob &in) { return 0; } - list> MainDb::getChatRooms () const { - return list>(); + list> MainDb::getChatRooms () const { + return list>(); } - void MainDb::insertChatRoom (const shared_ptr &) {} + void MainDb::insertChatRoom (const shared_ptr &) {} void MainDb::deleteChatRoom (const ChatRoomId &) {} diff --git a/src/db/main-db.h b/src/db/main-db.h index c3918d581..5a7f04540 100644 --- a/src/db/main-db.h +++ b/src/db/main-db.h @@ -30,8 +30,8 @@ LINPHONE_BEGIN_NAMESPACE +class AbstractChatRoom; class ChatMessage; -class ChatRoom; class Core; class EventLog; class MainDbKey; @@ -113,8 +113,8 @@ public: // Chat rooms. // --------------------------------------------------------------------------- - std::list> getChatRooms () const; - void insertChatRoom (const std::shared_ptr &chatRoom); + std::list> getChatRooms () const; + void insertChatRoom (const std::shared_ptr &chatRoom); void deleteChatRoom (const ChatRoomId &chatRoomId); // --------------------------------------------------------------------------- diff --git a/tester/cpim-tester.cpp b/tester/cpim-tester.cpp index 710289a12..ce36ef05a 100644 --- a/tester/cpim-tester.cpp +++ b/tester/cpim-tester.cpp @@ -396,9 +396,9 @@ static void cpim_chat_message_modifier_base(bool_t use_multipart) { lp_config_set_int(config, "sip", "use_cpim", 1); IdentityAddress paulineAddress(linphone_address_as_string_uri_only(pauline->identity)); - shared_ptr marieRoom = marie->lc->cppPtr->getOrCreateBasicChatRoom(paulineAddress); + shared_ptr marieRoom = marie->lc->cppPtr->getOrCreateBasicChatRoom(paulineAddress); - shared_ptr marieMessage = marieRoom->createMessage("Hello CPIM"); + shared_ptr marieMessage = marieRoom->createChatMessage("Hello CPIM"); if (use_multipart) { Content *content = new Content(); content->setContentType(ContentType::PlainText); diff --git a/tester/multipart-tester.cpp b/tester/multipart-tester.cpp index 840058540..0b790b9b6 100644 --- a/tester/multipart-tester.cpp +++ b/tester/multipart-tester.cpp @@ -41,9 +41,9 @@ static void chat_message_multipart_modifier_base(bool first_file_transfer, bool LinphoneCoreManager* pauline = linphone_core_manager_new("pauline_tcp_rc"); IdentityAddress paulineAddress(linphone_address_as_string_uri_only(pauline->identity)); - shared_ptr marieRoom = pauline->lc->cppPtr->getOrCreateBasicChatRoom(paulineAddress); + shared_ptr marieRoom = pauline->lc->cppPtr->getOrCreateBasicChatRoom(paulineAddress); - shared_ptr marieMessage = marieRoom->createMessage(); + shared_ptr marieMessage = marieRoom->createChatMessage(); if (first_file_transfer) { char *send_filepath = bc_tester_res("sounds/sintel_trailer_opus_h264.mkv"); FileContent *content = new FileContent(); diff --git a/tools/python/apixml2python.py b/tools/python/apixml2python.py index e998d5c65..2c27fb386 100755 --- a/tools/python/apixml2python.py +++ b/tools/python/apixml2python.py @@ -47,7 +47,6 @@ blacklisted_functions = [ 'linphone_chat_message_start_file_download', # callback function in parameter 'linphone_chat_message_state_to_string', # There is no use to wrap this function 'linphone_chat_room_send_chat_message', # Use linphone_chat_room_send_chat_message_2 instead - 'linphone_chat_room_send_message2', # callback function in parameter 'linphone_config_get_range', # to be handwritten because of result via arguments 'linphone_config_load_dict_to_section', # missing LinphoneDictionary 'linphone_config_section_to_dict', # missing LinphoneDictionary