From f047ea775baac83ccb0a1ae24cf45fa0f30cab50 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 19 Dec 2017 15:00:25 +0100 Subject: [PATCH] feat(MainDb): support fetch of participant devices --- src/db/main-db.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index cb640a685..d86a12a7e 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -2073,17 +2073,31 @@ static constexpr string &blobToString (string &in) { list> participants; const long long &dbChatRoomId = d->resolveId(row, 0); - static const string query = "SELECT sip_address.value, is_admin" + static const string query = "SELECT chat_room_participant.id, sip_address.value, is_admin" " FROM sip_address, chat_room, chat_room_participant" " WHERE chat_room.id = :chatRoomId" " AND sip_address.id = chat_room_participant.participant_sip_address_id" " AND chat_room_participant.chat_room_id = chat_room.id"; + // Fetch participants. soci::rowset rows = (session->prepare << query, soci::use(dbChatRoomId)); shared_ptr me; for (const auto &row : rows) { - shared_ptr participant = make_shared(IdentityAddress(row.get(0))); - participant->getPrivate()->setAdmin(!!row.get(1)); + shared_ptr participant = make_shared(IdentityAddress(row.get(1))); + ParticipantPrivate *dParticipant = participant->getPrivate(); + dParticipant->setAdmin(!!row.get(2)); + + // Fetch devices. + { + const long long &participantId = d->resolveId(row, 0); + static const string query = "SELECT sip_address.value FROM chat_room_participant_device, sip_address" + " WHERE chat_room_participant_id = :participantId" + " AND participant_device_sip_address_id = sip_address.id"; + + soci::rowset rows = (session->prepare << query, soci::use(participantId)); + for (const auto &row : rows) + dParticipant->addDevice(IdentityAddress(row.get(0))); + } if (participant->getAddress() == chatRoomId.getLocalAddress().getAddressWithoutGruu()) me = participant; @@ -2106,8 +2120,9 @@ static constexpr string &blobToString (string &in) { move(participants), lastNotifyId ); - chatRoom->getPrivate()->setState(LinphonePrivate::ChatRoom::State::Instantiated); - chatRoom->getPrivate()->setState(hasBeenLeft + AbstractChatRoomPrivate *dChatRoom = chatRoom->getPrivate(); + dChatRoom->setState(ChatRoom::State::Instantiated); + dChatRoom->setState(hasBeenLeft ? ChatRoom::State::Terminated : ChatRoom::State::Created ); @@ -2119,8 +2134,9 @@ static constexpr string &blobToString (string &in) { move(participants), lastNotifyId ); - chatRoom->getPrivate()->setState(LinphonePrivate::ChatRoom::State::Instantiated); - chatRoom->getPrivate()->setState(LinphonePrivate::ChatRoom::State::Created); + AbstractChatRoomPrivate *dChatRoom = chatRoom->getPrivate(); + dChatRoom->setState(ChatRoom::State::Instantiated); + dChatRoom->setState(ChatRoom::State::Created); } }