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); } }