From dbb43562f775d40e236ff099b30b1b2a7f8882a1 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 12 Dec 2017 16:07:45 +0100 Subject: [PATCH] feat(ChatRoom): add BasicToClientGroupChatRoom impl (todo: migration algorithm) --- src/chat/chat-room/abstract-chat-room.h | 1 + .../basic-to-client-group-chat-room.cpp | 209 ++++++++++++++++++ .../basic-to-client-group-chat-room.h | 82 +++++++ src/chat/chat-room/chat-room.cpp | 4 +- 4 files changed, 294 insertions(+), 2 deletions(-) diff --git a/src/chat/chat-room/abstract-chat-room.h b/src/chat/chat-room/abstract-chat-room.h index c91ca0171..b44b12db1 100644 --- a/src/chat/chat-room/abstract-chat-room.h +++ b/src/chat/chat-room/abstract-chat-room.h @@ -33,6 +33,7 @@ class ChatRoomId; class EventLog; class LINPHONE_PUBLIC AbstractChatRoom : public Object, public CoreAccessor, public ConferenceInterface { + friend class BasicToClientGroupChatRoomPrivate; friend class ChatMessage; friend class ChatMessagePrivate; friend class CorePrivate; 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 index e69de29bb..4dfe8d88b 100644 --- a/src/chat/chat-room/basic-to-client-group-chat-room.cpp +++ b/src/chat/chat-room/basic-to-client-group-chat-room.cpp @@ -0,0 +1,209 @@ +/* + * basic-to-client-group-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" +#include "basic-to-client-group-chat-room.h" +#include "chat-room.h" + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +// ----------------------------------------------------------------------------- + +class BasicToClientGroupChatRoomPrivate : public AbstractChatRoomPrivate { +public: + shared_ptr chatRoom; + +private: + inline void setCreationTime (time_t creationTime) override { + chatRoom->getPrivate()->setCreationTime(creationTime); + } + + inline void setLastUpdateTime (time_t lastUpdateTime) override { + chatRoom->getPrivate()->setLastUpdateTime(lastUpdateTime); + } + + inline void setState (BasicToClientGroupChatRoom::State state) override { + chatRoom->getPrivate()->setState(state); + } + + inline void sendChatMessage (const shared_ptr &chatMessage) override { + chatRoom->getPrivate()->sendChatMessage(chatMessage); + } + + inline void addTransientEvent (const shared_ptr &eventLog) override { + chatRoom->getPrivate()->addTransientEvent(eventLog); + } + + inline void removeTransientEvent (const shared_ptr &eventLog) override { + chatRoom->getPrivate()->removeTransientEvent(eventLog); + } + + inline void notifyUndecryptableChatMessageReceived (const shared_ptr &chatMessage) override { + chatRoom->getPrivate()->notifyUndecryptableChatMessageReceived(chatMessage); + } + + inline LinphoneReason onSipMessageReceived (SalOp *op, const SalMessage *message) override { + return chatRoom->getPrivate()->onSipMessageReceived(op, message); + } + + inline void onChatMessageReceived (const shared_ptr &chatMessage) override { + chatRoom->getPrivate()->onChatMessageReceived(chatMessage); + } +}; + +// ============================================================================= + +BasicToClientGroupChatRoom::BasicToClientGroupChatRoom (const shared_ptr &chatRoom) : + AbstractChatRoom(*new BasicToClientGroupChatRoomPrivate, chatRoom->getCore()) { + L_D(); + d->chatRoom = chatRoom; +} + +// ----------------------------------------------------------------------------- + +const ChatRoomId &BasicToClientGroupChatRoom::getChatRoomId () const { + L_D(); + return d->chatRoom->getChatRoomId(); +} + +const IdentityAddress &BasicToClientGroupChatRoom::getPeerAddress () const { + L_D(); + return d->chatRoom->getPeerAddress(); +} + +const IdentityAddress &BasicToClientGroupChatRoom::getLocalAddress () const { + L_D(); + return d->chatRoom->getLocalAddress(); +} + +// ----------------------------------------------------------------------------- + +time_t BasicToClientGroupChatRoom::getCreationTime () const { + L_D(); + return d->chatRoom->getCreationTime(); +} + +time_t BasicToClientGroupChatRoom::getLastUpdateTime () const { + L_D(); + return d->chatRoom->getLastUpdateTime(); +} + +// ----------------------------------------------------------------------------- + +BasicToClientGroupChatRoom::State BasicToClientGroupChatRoom::getState () const { + L_D(); + return d->chatRoom->getState(); +} + +// ----------------------------------------------------------------------------- + +list> BasicToClientGroupChatRoom::getHistory (int nLast) const { + L_D(); + return d->chatRoom->getHistory(nLast); +} + +list> BasicToClientGroupChatRoom::getHistoryRange (int begin, int end) const { + L_D(); + return d->chatRoom->getHistoryRange(begin, end); +} + +int BasicToClientGroupChatRoom::getHistorySize () const { + L_D(); + return d->chatRoom->getHistorySize(); +} + +void BasicToClientGroupChatRoom::deleteHistory () { + L_D(); + d->chatRoom->deleteHistory(); +} + +shared_ptr BasicToClientGroupChatRoom::getLastChatMessageInHistory () const { + L_D(); + return d->chatRoom->getLastChatMessageInHistory(); +} + +int BasicToClientGroupChatRoom::getChatMessageCount () const { + L_D(); + return d->chatRoom->getChatMessageCount(); +} + +int BasicToClientGroupChatRoom::getUnreadChatMessageCount () const { + L_D(); + return d->chatRoom->getUnreadChatMessageCount(); +} + +// ----------------------------------------------------------------------------- + +void BasicToClientGroupChatRoom::compose () { + L_D(); + return d->chatRoom->compose(); +} + +bool BasicToClientGroupChatRoom::isRemoteComposing () const { + L_D(); + return d->chatRoom->isRemoteComposing(); +} + +list BasicToClientGroupChatRoom::getComposingAddresses () const { + L_D(); + return d->chatRoom->getComposingAddresses(); +} + +// ----------------------------------------------------------------------------- + +shared_ptr BasicToClientGroupChatRoom::createChatMessage () { + L_D(); + return d->chatRoom->createChatMessage(); +} + +shared_ptr BasicToClientGroupChatRoom::createChatMessage (const string &text) { + L_D(); + return d->chatRoom->createChatMessage(text); +} + +shared_ptr BasicToClientGroupChatRoom::createFileTransferMessage (const LinphoneContent *initialContent) { + L_D(); + return d->chatRoom->createFileTransferMessage(initialContent); +} + +// ----------------------------------------------------------------------------- + +shared_ptr BasicToClientGroupChatRoom::findChatMessage (const string &messageId) const { + L_D(); + return d->chatRoom->findChatMessage(messageId); +} + +shared_ptr BasicToClientGroupChatRoom::findChatMessage ( + const string &messageId, + ChatMessage::Direction direction +) const { + L_D(); + return d->chatRoom->findChatMessage(messageId, direction); +} + +void BasicToClientGroupChatRoom::markAsRead () { + L_D(); + d->chatRoom->markAsRead(); +} + +LINPHONE_END_NAMESPACE 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 index e69de29bb..d4d11b546 100644 --- a/src/chat/chat-room/basic-to-client-group-chat-room.h +++ b/src/chat/chat-room/basic-to-client-group-chat-room.h @@ -0,0 +1,82 @@ +/* + * basic-to-client-group-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 _BASIC_TO_CLIENT_GROUP_CHAT_ROOM_H_ +#define _BASIC_TO_CLIENT_GROUP_CHAT_ROOM_H_ + +#include "abstract-chat-room.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class BasicToClientGroupChatRoomPrivate; +class ChatRoom; + +class LINPHONE_PUBLIC BasicToClientGroupChatRoom : public AbstractChatRoom { +public: + BasicToClientGroupChatRoom (const std::shared_ptr &chatRoom); + + const ChatRoomId &getChatRoomId () const override; + + const IdentityAddress &getPeerAddress () const override; + const IdentityAddress &getLocalAddress () const override; + + time_t getCreationTime () const override; + time_t getLastUpdateTime () const override; + + State getState () const override; + + std::list> getHistory (int nLast) const override; + std::list> getHistoryRange (int begin, int end) const override; + int getHistorySize () const override; + + void deleteHistory () override; + + std::shared_ptr getLastChatMessageInHistory () const override; + + int getChatMessageCount () const override; + int getUnreadChatMessageCount () const override; + + void compose () override; + bool isRemoteComposing () const override; + std::list getComposingAddresses () const override; + + std::shared_ptr createChatMessage () override; + std::shared_ptr createChatMessage (const std::string &text) override; + + // TODO: Remove LinphoneContent by LinphonePrivate::Content. + std::shared_ptr createFileTransferMessage (const LinphoneContent *initialContent) override; + + std::shared_ptr findChatMessage (const std::string &messageId) const override; + std::shared_ptr findChatMessage ( + const std::string &messageId, + ChatMessage::Direction direction + ) const override; + + void markAsRead () override; + +private: + L_DECLARE_PRIVATE(BasicToClientGroupChatRoom); + L_DISABLE_COPY(BasicToClientGroupChatRoom); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _BASIC_TO_CLIENT_GROUP_CHAT_ROOM_H_ diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 24ccccac7..bd379c156 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -350,7 +350,7 @@ void ChatRoom::deleteHistory () { getCore()->getPrivate()->mainDb->cleanHistory(getChatRoomId()); } -shared_ptr ChatRoom::getLastChatMessageInHistory() const { +shared_ptr ChatRoom::getLastChatMessageInHistory () const { return getCore()->getPrivate()->mainDb->getLastChatMessage(getChatRoomId()); } @@ -379,7 +379,7 @@ bool ChatRoom::isRemoteComposing () const { return !d->remoteIsComposing.empty(); } -std::list ChatRoom::getComposingAddresses () const { +list ChatRoom::getComposingAddresses () const { L_D(); return d->remoteIsComposing; }