Commit 36ae94cb authored by Ronan's avatar Ronan

feat(MainDb): supports participant device insertion

parent cac63d00
...@@ -55,8 +55,10 @@ private: ...@@ -55,8 +55,10 @@ private:
IdentityAddress mGruu; IdentityAddress mGruu;
std::shared_ptr<CallSession> mSession; std::shared_ptr<CallSession> mSession;
LinphoneEvent *mConferenceSubscribeEvent = nullptr; LinphoneEvent *mConferenceSubscribeEvent = nullptr;
L_DISABLE_COPY(ParticipantDevice);
}; };
LINPHONE_END_NAMESPACE LINPHONE_END_NAMESPACE
#endif // ifndef _PARTICIPANT_DEVICE_H_ #endif // ifndef _PARTICIPANT_DEVICE_H_
\ No newline at end of file
...@@ -46,6 +46,7 @@ class Participant : public Object { ...@@ -46,6 +46,7 @@ class Participant : public Object {
friend class LocalConferenceEventHandler; friend class LocalConferenceEventHandler;
friend class LocalConferenceEventHandlerPrivate; friend class LocalConferenceEventHandlerPrivate;
friend class MainDb; friend class MainDb;
friend class MainDbPrivate;
friend class MediaSessionPrivate; friend class MediaSessionPrivate;
friend class RemoteConference; friend class RemoteConference;
friend class RemoteConferenceCall; friend class RemoteConferenceCall;
......
...@@ -61,7 +61,8 @@ private: ...@@ -61,7 +61,8 @@ private:
const tm &creationTime const tm &creationTime
); );
long long insertChatRoom (const std::shared_ptr<ChatRoom> &chatRoom); long long insertChatRoom (const std::shared_ptr<ChatRoom> &chatRoom);
void insertChatRoomParticipant (long long chatRoomId, long long sipAddressId, bool isAdmin); long long insertChatRoomParticipant (long long chatRoomId, long long sipAddressId, bool isAdmin);
void insertChatRoomParticipantDevice (long long participantId, long long sipAddressId);
void insertChatMessageParticipant (long long messageEventId, long long sipAddressId, int state); void insertChatMessageParticipant (long long messageEventId, long long sipAddressId, int state);
long long selectSipAddressId (const std::string &sipAddress) const; long long selectSipAddressId (const std::string &sipAddress) const;
......
...@@ -278,28 +278,58 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate), ...@@ -278,28 +278,58 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
insertChatRoomParticipant(id, insertSipAddress(me->getAddress().asString()), me->isAdmin()); insertChatRoomParticipant(id, insertSipAddress(me->getAddress().asString()), me->isAdmin());
} }
for (const auto &participant : chatRoom->getParticipants()) for (const auto &participant : chatRoom->getParticipants()) {
insertChatRoomParticipant(id, insertSipAddress(participant->getAddress().asString()), participant->isAdmin()); long long participantId = insertChatRoomParticipant(
id,
insertSipAddress(participant->getAddress().asString()),
participant->isAdmin()
);
for (const auto &device : participant->getPrivate()->getDevices())
insertChatRoomParticipantDevice(participantId, insertSipAddress(device->getAddress().asString()));
}
return id; return id;
} }
void MainDbPrivate::insertChatRoomParticipant (long long chatRoomId, long long sipAddressId, bool isAdmin) { long long MainDbPrivate::insertChatRoomParticipant (long long chatRoomId, long long sipAddressId, bool isAdmin) {
// See: https://stackoverflow.com/a/15299655 (cast to reference) L_Q();
long long id = -1;
soci::session *session = dbSession.getBackendSession<soci::session>(); soci::session *session = dbSession.getBackendSession<soci::session>();
soci::statement statement = ( *session << "SELECT id from chat_room_participant"
session->prepare << "UPDATE chat_room_participant SET is_admin = :isAdmin" " WHERE chat_room_id = :chatRoomId AND participant_sip_address_id = :sipAddressId",
" WHERE chat_room_id = :chatRoomId AND participant_sip_address_id = :sipAddressId", soci::into(id), soci::use(chatRoomId), soci::use(sipAddressId);
soci::use(static_cast<const int &>(isAdmin)), soci::use(chatRoomId), soci::use(sipAddressId)
); if (id >= 0) {
statement.execute(true); // See: https://stackoverflow.com/a/15299655 (cast to reference)
if (statement.get_affected_rows() == 0) { *session << "UPDATE chat_room_participant SET is_admin = :isAdmin"
lInfo() << "Insert new chat room participant in database: `" << sipAddressId << "` (isAdmin=" << isAdmin << ")."; " WHERE id = :id",
*session << "INSERT INTO chat_room_participant (chat_room_id, participant_sip_address_id, is_admin)" soci::use(static_cast<const int &>(isAdmin)), soci::use(id);
" VALUES (:chatRoomId, :sipAddressId, :isAdmin)", return id;
soci::use(chatRoomId), soci::use(sipAddressId), soci::use(static_cast<const int &>(isAdmin));
} }
lInfo() << "Insert new chat room participant in database: `" << sipAddressId << "` (isAdmin=" << isAdmin << ").";
*session << "INSERT INTO chat_room_participant (chat_room_id, participant_sip_address_id, is_admin)"
" VALUES (:chatRoomId, :sipAddressId, :isAdmin)",
soci::use(chatRoomId), soci::use(sipAddressId), soci::use(static_cast<const int &>(isAdmin));
return q->getLastInsertId();
}
void MainDbPrivate::insertChatRoomParticipantDevice (long long participantId, long long sipAddressId) {
soci::session *session = dbSession.getBackendSession<soci::session>();
long long count;
*session << "SELECT COUNT(*) FROM chat_room_participant_device"
" WHERE chat_room_participant_id = :participantId"
" AND participant_device_sip_address_id = :sipAddressId",
soci::into(count), soci::use(participantId), soci::use(sipAddressId);
if (count)
return;
lInfo() << "Insert new chat room participant device in database: `" << sipAddressId << "`.";
*session << "INSERT INTO chat_room_participant_device (chat_room_participant_id, participant_device_sip_address_id)"
" VALUES (:participantId, :sipAddressId)",
soci::use(participantId), soci::use(sipAddressId);
} }
void MainDbPrivate::insertChatMessageParticipant (long long eventId, long long sipAddressId, int state) { void MainDbPrivate::insertChatMessageParticipant (long long eventId, long long sipAddressId, int state) {
......
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