/*
* 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 "ParticipantImdnStateListModel.hpp"
#include "ParticipantImdnStateModel.hpp"
#include
#include "app/App.hpp"
#include "utils/Utils.hpp"
#include "components/Components.hpp"
// =============================================================================
ParticipantImdnStateListModel::ParticipantImdnStateListModel (std::shared_ptr message, QObject *parent) : ProxyListModel(parent) {
QVector states;
states.push_back(linphone::ChatMessage::State::Delivered);
states.push_back(linphone::ChatMessage::State::DeliveredToUser);
states.push_back(linphone::ChatMessage::State::Displayed);
states.push_back(linphone::ChatMessage::State::NotDelivered);
states.push_back(linphone::ChatMessage::State::Idle);
states.push_back(linphone::ChatMessage::State::InProgress);
states.push_back(linphone::ChatMessage::State::FileTransferError);
states.push_back(linphone::ChatMessage::State::FileTransferDone);
states.push_back(linphone::ChatMessage::State::FileTransferInProgress);
for(int i = 0 ; i < states.size() ; ++i){
std::list> imdns = message->getParticipantsByImdnState(states[i]);
for(auto imdn : imdns){
if(imdn->getParticipant()){
auto deviceModel = QSharedPointer::create(imdn);
mList << deviceModel;
}
}
}
}
//--------------------------------------------------------------------------------
QSharedPointer ParticipantImdnStateListModel::getImdnState(const std::shared_ptr & state){
QSharedPointer imdn;
auto participant = state->getParticipant();
auto it = mList.begin();
if( participant){
auto imdnAddress = state->getParticipant()->getAddress();
while(it != mList.end() && !it->objectCast()->getAddress()->equal(imdnAddress))
++it;
}else
it = mList.end();
if(it != mList.end())
imdn = it->objectCast();
else{// Create the new one
imdn = QSharedPointer::create(state);
add(imdn);
}
return imdn;
}
//--------------------------------------------------------------------------------
void ParticipantImdnStateListModel::updateState(const std::shared_ptr & state){
if(state->getParticipant()) {
auto imdn = getImdnState(state);
auto oldState = imdn->getState();
getImdnState(state)->update(state);
if( oldState == LinphoneEnums::ChatMessageState::ChatMessageStateIdle && oldState != imdn->getState())
emit stateChangedFromIdle();
}
}
//--------------------------------------------------------------------------------
void ParticipantImdnStateListModel::onParticipantImdnStateChanged(const std::shared_ptr & message, const std::shared_ptr & state){
updateState(state);
}