Commit 531e3d1b authored by Ronan's avatar Ronan
Browse files

feat(ChatRoom): add a capabilities getter

parent ff02fcd2
......@@ -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_
......@@ -36,6 +36,10 @@ BasicChatRoom::BasicChatRoom (LinphoneCore *core, const Address &peerAddress) :
// -----------------------------------------------------------------------------
int BasicChatRoom::getCapabilities () const {
return static_cast<int>(Capabilities::Basic);
}
void BasicChatRoom::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) {
lError() << "addParticipant() is not allowed on a BasicChatRoom";
}
......
......@@ -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<Address> &addresses, const CallSessionParams *params, bool hasMedia) override;
......
......@@ -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<ChatMessage> createFileTransferMessage (const LinphoneContent *initialContent);
std::shared_ptr<ChatMessage> createMessage (const std::string &msg);
......
......@@ -67,7 +67,9 @@ ClientGroupChatRoom::ClientGroupChatRoom (LinphoneCore *core, const Address &me,
this->subject = subject;
}
// -----------------------------------------------------------------------------
int ClientGroupChatRoom::getCapabilities () const {
return static_cast<int>(Capabilities::Conference);
}
void ClientGroupChatRoom::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) {
list<Address> addresses;
......
......@@ -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<Address> &addresses, const CallSessionParams *params, bool hasMedia) override;
......
......@@ -111,7 +111,9 @@ void RealTimeTextChatRoomPrivate::sendMessage (const std::shared_ptr<ChatMessage
RealTimeTextChatRoom::RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress) : ChatRoom(*new RealTimeTextChatRoomPrivate(core, peerAddress)) {}
// -----------------------------------------------------------------------------
int RealTimeTextChatRoom::getCapabilities () const {
return static_cast<int>(Capabilities::Basic) | static_cast<int>(Capabilities::RealTimeText);
}
uint32_t RealTimeTextChatRoom::getChar () const {
L_D();
......
......@@ -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;
......
......@@ -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<soci::session>();
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<string>(LEGACY_MESSAGE_COL_LOCAL_ADDRESS));
references.remoteSipAddressId = insertSipAddress(message.get<string>(LEGACY_MESSAGE_COL_REMOTE_ADDRESS));
references.chatRoomId = insertChatRoom(references.remoteSipAddressId, date);
references.chatRoomId = insertChatRoom(
references.remoteSipAddressId,
static_cast<int>(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<int>(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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment