From 531e3d1b8cd4ef2d156c29ec8f591f573b045ea7 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 12 Oct 2017 10:54:15 +0200 Subject: [PATCH] feat(ChatRoom): add a capabilities getter --- include/linphone/enums/chat-room-enums.h | 5 +++++ src/chat/chat-room/basic-chat-room.cpp | 4 ++++ src/chat/chat-room/basic-chat-room.h | 2 ++ src/chat/chat-room/chat-room.h | 6 +++++- src/chat/chat-room/client-group-chat-room.cpp | 4 +++- src/chat/chat-room/client-group-chat-room.h | 3 ++- .../chat-room/real-time-text-chat-room.cpp | 4 +++- src/chat/chat-room/real-time-text-chat-room.h | 2 ++ src/db/events-db.cpp | 21 +++++++++++++------ 9 files changed, 41 insertions(+), 10 deletions(-) diff --git a/include/linphone/enums/chat-room-enums.h b/include/linphone/enums/chat-room-enums.h index 8a4318aa8..11e1f8fa9 100644 --- a/include/linphone/enums/chat-room-enums.h +++ b/include/linphone/enums/chat-room-enums.h @@ -31,4 +31,9 @@ F(Terminated) \ F(CreationFailed) +#define L_ENUM_VALUES_CHAT_ROOM_CAPABILITIES(F) \ + F(Basic, 1 << 0) \ + F(RealTimeText, 1 << 1) \ + F(Conference, 1 << 2) + #endif // ifndef _CHAT_ROOM_ENUMS_H_ diff --git a/src/chat/chat-room/basic-chat-room.cpp b/src/chat/chat-room/basic-chat-room.cpp index ae59ffd01..2814a253d 100644 --- a/src/chat/chat-room/basic-chat-room.cpp +++ b/src/chat/chat-room/basic-chat-room.cpp @@ -36,6 +36,10 @@ BasicChatRoom::BasicChatRoom (LinphoneCore *core, const Address &peerAddress) : // ----------------------------------------------------------------------------- +int BasicChatRoom::getCapabilities () const { + return static_cast(Capabilities::Basic); +} + void BasicChatRoom::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) { lError() << "addParticipant() is not allowed on a BasicChatRoom"; } diff --git a/src/chat/chat-room/basic-chat-room.h b/src/chat/chat-room/basic-chat-room.h index 11f6eed79..d6b64d9a6 100644 --- a/src/chat/chat-room/basic-chat-room.h +++ b/src/chat/chat-room/basic-chat-room.h @@ -33,6 +33,8 @@ public: BasicChatRoom (LinphoneCore *core, const Address &peerAddress); virtual ~BasicChatRoom () = default; + int getCapabilities () const override; + /* ConferenceInterface. */ void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override; void addParticipants (const std::list
&addresses, const CallSessionParams *params, bool hasMedia) override; diff --git a/src/chat/chat-room/chat-room.h b/src/chat/chat-room/chat-room.h index 2e4b6beac..84c48911d 100644 --- a/src/chat/chat-room/chat-room.h +++ b/src/chat/chat-room/chat-room.h @@ -44,12 +44,16 @@ class LINPHONE_PUBLIC ChatRoom : public Object, public ConferenceInterface { friend class ChatMessagePrivate; public: - L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_ROOM_STATE); 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); + ChatRoom (LinphoneCore *core); virtual ~ChatRoom () = default; + virtual int getCapabilities () const = 0; + void compose (); std::shared_ptr createFileTransferMessage (const LinphoneContent *initialContent); std::shared_ptr createMessage (const std::string &msg); diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index fb7270231..a32d9b094 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -67,7 +67,9 @@ ClientGroupChatRoom::ClientGroupChatRoom (LinphoneCore *core, const Address &me, this->subject = subject; } -// ----------------------------------------------------------------------------- +int ClientGroupChatRoom::getCapabilities () const { + return static_cast(Capabilities::Conference); +} void ClientGroupChatRoom::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) { list
addresses; diff --git a/src/chat/chat-room/client-group-chat-room.h b/src/chat/chat-room/client-group-chat-room.h index 77121c01d..5801d3ffb 100644 --- a/src/chat/chat-room/client-group-chat-room.h +++ b/src/chat/chat-room/client-group-chat-room.h @@ -40,7 +40,8 @@ public: ClientGroupChatRoom (LinphoneCore *core, const Address &me, const std::string &uri, const std::string &subject); virtual ~ClientGroupChatRoom () = default; -public: + int getCapabilities () const override; + /* ConferenceInterface */ void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override; void addParticipants (const std::list
&addresses, const CallSessionParams *params, bool hasMedia) override; 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 08da5812e..212fc9d19 100644 --- a/src/chat/chat-room/real-time-text-chat-room.cpp +++ b/src/chat/chat-room/real-time-text-chat-room.cpp @@ -111,7 +111,9 @@ void RealTimeTextChatRoomPrivate::sendMessage (const std::shared_ptr(Capabilities::Basic) | static_cast(Capabilities::RealTimeText); +} uint32_t RealTimeTextChatRoom::getChar () const { L_D(); diff --git a/src/chat/chat-room/real-time-text-chat-room.h b/src/chat/chat-room/real-time-text-chat-room.h index dcc06c7d7..0dc3f6482 100644 --- a/src/chat/chat-room/real-time-text-chat-room.h +++ b/src/chat/chat-room/real-time-text-chat-room.h @@ -38,6 +38,8 @@ public: RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress); virtual ~RealTimeTextChatRoom () = default; + int getCapabilities () const override; + uint32_t getChar () const; LinphoneCall *getCall () const; diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index c385aca21..b3c50d45c 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -28,6 +28,7 @@ #include "abstract/abstract-db-p.h" #include "chat/chat-message/chat-message.h" +#include "chat/chat-room/chat-room.h" #include "conference/participant.h" #include "content/content-type.h" #include "content/content.h" @@ -61,7 +62,7 @@ public: void insertContent (long messageEventId, const Content &content); long insertContentType (const string &contentType); long insertEvent (EventLog::Type type, const tm &date); - long insertChatRoom (long sipAddressId, const tm &date); + long insertChatRoom (long sipAddressId, int capabilities, const tm &date); void insertChatRoomParticipant (long chatRoomId, long sipAddressId, bool isAdmin); long insertMessageEvent ( @@ -201,15 +202,16 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} return q->getLastInsertId(); } - long EventsDbPrivate::insertChatRoom (long sipAddressId, const tm &date) { + long EventsDbPrivate::insertChatRoom (long sipAddressId, int capabilities, const tm &date) { soci::session *session = dbSession.getBackendSession(); long id; *session << "SELECT peer_sip_address_id FROM chat_room WHERE peer_sip_address_id = :sipAddressId", soci::use(sipAddressId), soci::into(id); if (!session->got_data()) - *session << "INSERT INTO chat_room (peer_sip_address_id, creation_date, last_update_date, subject) VALUES" - " (:sipAddressId, :creationDate, :lastUpdateDate, '')", soci::use(sipAddressId), soci::use(date), soci::use(date); + *session << "INSERT INTO chat_room (peer_sip_address_id, creation_date, last_update_date, capabilities, subject) VALUES" + " (:sipAddressId, :creationDate, :lastUpdateDate, :capabilities, '')", + soci::use(sipAddressId), soci::use(date), soci::use(date), soci::use(capabilities); else *session << "UPDATE chat_room SET last_update_date = :lastUpdateDate WHERE peer_sip_address_id = :sipAddressId", soci::use(date), soci::use(sipAddressId); @@ -367,7 +369,11 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} references.eventId = insertEvent(EventLog::Type::ChatMessage, date); references.localSipAddressId = insertSipAddress(message.get(LEGACY_MESSAGE_COL_LOCAL_ADDRESS)); references.remoteSipAddressId = insertSipAddress(message.get(LEGACY_MESSAGE_COL_REMOTE_ADDRESS)); - references.chatRoomId = insertChatRoom(references.remoteSipAddressId, date); + references.chatRoomId = insertChatRoom( + references.remoteSipAddressId, + static_cast(ChatRoom::Capabilities::Basic), + date + ); insertChatRoomParticipant(references.chatRoomId, references.remoteSipAddressId, false); @@ -423,6 +429,9 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} // Last event date (call, message...). " last_update_date DATE NOT NULL," + // ConferenceChatRoom, BasicChatRoom, RTT... + "capabilities TINYINT UNSIGNED," + // Chatroom subject. " subject VARCHAR(255)," @@ -531,7 +540,7 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} // Trigger to delete participant_message cache entries. string displayedId = Utils::toString(static_cast(ChatMessage::State::Displayed)); string participantMessageDeleter = - "CREATE TRIGGER IF NOT EXISTS message_participant_deleter" + "CREATE TRIGGER IF NOT EXISTS message_participant_deleter" " AFTER UPDATE OF state ON message_participant FOR EACH ROW" " WHEN NEW.state = "; participantMessageDeleter += displayedId;