From 71757bbce75ec86708bf8da2d6ade003b50be2a3 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 30 Nov 2017 14:15:35 +0100 Subject: [PATCH] feat(MainDb): save chat room read only state --- src/chat/chat-room/basic-chat-room.cpp | 4 ++++ src/chat/chat-room/basic-chat-room.h | 1 + src/chat/chat-room/chat-room.h | 1 + src/chat/chat-room/client-group-chat-room.cpp | 9 +++++++-- src/chat/chat-room/client-group-chat-room.h | 4 +++- src/chat/chat-room/server-group-chat-room-stub.cpp | 4 ++++ src/chat/chat-room/server-group-chat-room.h | 1 + src/db/main-db.cpp | 13 +++++++++---- 8 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/chat/chat-room/basic-chat-room.cpp b/src/chat/chat-room/basic-chat-room.cpp index edaef84c1..5e9d70d8a 100644 --- a/src/chat/chat-room/basic-chat-room.cpp +++ b/src/chat/chat-room/basic-chat-room.cpp @@ -51,6 +51,10 @@ BasicChatRoom::CapabilitiesMask BasicChatRoom::getCapabilities () const { return static_cast(Capabilities::Basic); } +bool BasicChatRoom::isReadOnly () const { + return false; +} + bool BasicChatRoom::canHandleParticipants () const { return false; } diff --git a/src/chat/chat-room/basic-chat-room.h b/src/chat/chat-room/basic-chat-room.h index bf777e4c8..c546f35d1 100644 --- a/src/chat/chat-room/basic-chat-room.h +++ b/src/chat/chat-room/basic-chat-room.h @@ -33,6 +33,7 @@ class LINPHONE_PUBLIC BasicChatRoom : public ChatRoom { public: CapabilitiesMask getCapabilities () const override; + bool isReadOnly () const override; const IdentityAddress &getConferenceAddress () const override; diff --git a/src/chat/chat-room/chat-room.h b/src/chat/chat-room/chat-room.h index 6c988a583..f71ee7f84 100644 --- a/src/chat/chat-room/chat-room.h +++ b/src/chat/chat-room/chat-room.h @@ -57,6 +57,7 @@ public: time_t getLastUpdateTime () const; virtual CapabilitiesMask getCapabilities () const = 0; + virtual bool isReadOnly () const = 0; std::shared_ptr getLastMessageInHistory () const; diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index 1d8660966..ffbca8196 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -103,7 +103,8 @@ ClientGroupChatRoom::ClientGroupChatRoom ( shared_ptr &me, const string &subject, list> &&participants, - unsigned int lastNotifyId + unsigned int lastNotifyId, + bool isReadOnly ) : ChatRoom(*new ClientGroupChatRoomPrivate, core, ChatRoomId(peerAddress, me->getAddress())), RemoteConference(core, me->getAddress(), nullptr) { L_D(); @@ -114,7 +115,7 @@ RemoteConference(core, me->getAddress(), nullptr) { dConference->subject = subject; dConference->participants = move(participants); - d->state = ChatRoom::State::Created; + d->state = isReadOnly ? ChatRoom::State::Created : ChatRoom::State::Terminated; getMe()->getPrivate()->setAdmin(me->isAdmin()); @@ -130,6 +131,10 @@ ClientGroupChatRoom::CapabilitiesMask ClientGroupChatRoom::getCapabilities () co return static_cast(Capabilities::Conference); } +bool ClientGroupChatRoom::isReadOnly () const { + return getState() == State::Created; +} + bool ClientGroupChatRoom::canHandleParticipants () const { return RemoteConference::canHandleParticipants(); } diff --git a/src/chat/chat-room/client-group-chat-room.h b/src/chat/chat-room/client-group-chat-room.h index 042d7a59f..481b04377 100644 --- a/src/chat/chat-room/client-group-chat-room.h +++ b/src/chat/chat-room/client-group-chat-room.h @@ -45,12 +45,14 @@ public: std::shared_ptr &me, const std::string &subject, std::list> &&participants, - unsigned int lastNotifyId + unsigned int lastNotifyId, + bool isReadOnly ); std::shared_ptr getCore () const; CapabilitiesMask getCapabilities () const override; + bool isReadOnly () const override; const IdentityAddress &getConferenceAddress () const override; 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 5abf436d2..c0bfb39f1 100644 --- a/src/chat/chat-room/server-group-chat-room-stub.cpp +++ b/src/chat/chat-room/server-group-chat-room-stub.cpp @@ -85,6 +85,10 @@ int ServerGroupChatRoom::getCapabilities () const { return 0; } +bool ServerGroupChatRoom::isReadOnly () const { + return true; +} + bool ServerGroupChatRoom::canHandleParticipants () const { return false; } diff --git a/src/chat/chat-room/server-group-chat-room.h b/src/chat/chat-room/server-group-chat-room.h index 9c8fc9d8a..0f68deef5 100644 --- a/src/chat/chat-room/server-group-chat-room.h +++ b/src/chat/chat-room/server-group-chat-room.h @@ -40,6 +40,7 @@ public: ServerGroupChatRoom (const std::shared_ptr &core, SalCallOp *op); CapabilitiesMask getCapabilities () const override; + bool isReadOnly () const override; const IdentityAddress &getConferenceAddress () const override; diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 013e26474..a73b10b9a 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -247,11 +247,12 @@ MainDb::MainDb (const shared_ptr &core) : AbstractDb(*new MainDbPrivate), const tm &creationTime = Utils::getTimeTAsTm(chatRoom->getCreationTime()); const int &capabilities = static_cast(chatRoom->getCapabilities()); const string &subject = chatRoom->getSubject(); + const int &flags = chatRoom->isReadOnly(); *session << "INSERT INTO chat_room (" " peer_sip_address_id, local_sip_address_id, creation_time, last_update_time, capabilities, subject" - ") VALUES (:peerSipAddressId, :localSipAddressId, :creationTime, :lastUpdateTime, :capabilities, :subject)", + ") VALUES (:peerSipAddressId, :localSipAddressId, :creationTime, :lastUpdateTime, :capabilities, :subject, :flags)", soci::use(peerSipAddressId), soci::use(localSipAddressId), soci::use(creationTime), soci::use(creationTime), - soci::use(capabilities), soci::use(subject); + soci::use(capabilities), soci::use(subject), soci::use(flags); id = q->getLastInsertId(); @@ -898,6 +899,8 @@ MainDb::MainDb (const shared_ptr &core) : AbstractDb(*new MainDbPrivate), " last_notify_id INT UNSIGNED," + " flags INT UNSIGNED DEFAULT 0," + " UNIQUE (peer_sip_address_id, local_sip_address_id)," " FOREIGN KEY (peer_sip_address_id)" @@ -1718,7 +1721,8 @@ MainDb::MainDb (const shared_ptr &core) : AbstractDb(*new MainDbPrivate), // ----------------------------------------------------------------------------- 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" + 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" " WHERE chat_room.peer_sip_address_id = peer_sip_address.id AND chat_room.local_sip_address_id = local_sip_address.id" " ORDER BY last_update_time DESC"; @@ -1797,7 +1801,8 @@ MainDb::MainDb (const shared_ptr &core) : AbstractDb(*new MainDbPrivate), me, subject, move(participants), - lastNotifyId + lastNotifyId, + !!row.get(8, 0) ); }