/* * Copyright (c) 2021 Belledonne Communications SARL. * * This file is part of linphone-desktop * (see https://www.linphone.org). * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "ChatRoomInitializer.hpp" #include #include #include "components/core/CoreManager.hpp" #include "components/core/CoreHandlers.hpp" // ============================================================================= ChatRoomInitializer::ChatRoomInitializer(){} ChatRoomInitializer::~ChatRoomInitializer(){} void ChatRoomInitializer::onConferenceJoined(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) { qInfo() << "[ChatRoomInitializer] Conference has been set"; if(mAdmins.size() > 0){ setAdminsSync(chatRoom, mAdmins); } chatRoom->removeListener(mSelf); mSelf = nullptr; } void ChatRoomInitializer::setAdminsSync(const std::shared_ptr & chatRoom, QList< std::shared_ptr> admins){ std::list> chatRoomParticipants = chatRoom->getParticipants(); int count = 0; for(auto participant : chatRoomParticipants){ auto address = participant->getAddress(); auto isAdmin = std::find_if(admins.begin(), admins.end(), [address](std::shared_ptr addr){ return addr->weakEqual(address); }); if( isAdmin != admins.end()){ ++count; chatRoom->setParticipantAdminStatus(participant, true); } } qInfo() << "[ChatRoomInitializer] '" << admins.size() << "' admin(s) specified in addition of Me, " << count << " set."; } void ChatRoomInitializer::setAdminsAsync(const std::string& subject, const linphone::ChatRoomBackend& backend, const bool& groupEnabled, QList< std::shared_ptr> admins){ QObject * context = new QObject(); QObject::connect(CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::chatRoomStateChanged, context,[context, admins, subject, backend, groupEnabled](const std::shared_ptr &chatRoomEvent,linphone::ChatRoom::State state){ auto params = chatRoomEvent->getCurrentParams(); if( subject == chatRoomEvent->getSubject() && backend == params->getBackend() && groupEnabled == params->groupEnabled()){ if( state == linphone::ChatRoom::State::Created){ std::shared_ptr init = std::make_shared(); init->mAdmins = admins; init->mSelf = init; chatRoomEvent->addListener(init); delete context; }else if( state > linphone::ChatRoom::State::Created){// The chat room could be completed. Delete the bind. delete context; } } }); }