2019-08-23 09:51:33 +00:00
|
|
|
/*
|
|
|
|
* Squawk messenger.
|
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "chat.h"
|
2023-03-17 23:50:04 +00:00
|
|
|
#include "ui_conversation.h"
|
2019-08-23 09:51:33 +00:00
|
|
|
|
2019-12-20 15:41:20 +00:00
|
|
|
Chat::Chat(Models::Account* acc, Models::Contact* p_contact, QWidget* parent):
|
2020-08-12 16:55:01 +00:00
|
|
|
Conversation(false, acc, p_contact, p_contact->getJid(), "", parent),
|
2019-08-23 09:51:33 +00:00
|
|
|
contact(p_contact)
|
|
|
|
{
|
|
|
|
setName(p_contact->getContactName());
|
|
|
|
updateState();
|
|
|
|
setStatus(p_contact->getStatus());
|
2019-12-23 06:28:23 +00:00
|
|
|
setAvatar(p_contact->getAvatarPath());
|
2019-08-23 09:51:33 +00:00
|
|
|
|
2019-11-03 18:46:40 +00:00
|
|
|
connect(contact, &Models::Contact::childChanged, this, &Chat::onContactChanged);
|
2023-03-17 23:50:04 +00:00
|
|
|
if (p_contact->hasKeys(Shared::EncryptionProtocol::omemo2))
|
|
|
|
m_ui->encryptionButton->setVisible(true);
|
2019-08-23 09:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Chat::~Chat()
|
2023-03-17 23:50:04 +00:00
|
|
|
{}
|
2019-08-23 09:51:33 +00:00
|
|
|
|
2023-03-17 23:50:04 +00:00
|
|
|
void Chat::onContactChanged(Models::Item* item, int row, int col) {
|
2019-08-23 09:51:33 +00:00
|
|
|
if (item == contact) {
|
|
|
|
switch (col) {
|
|
|
|
case 0:
|
|
|
|
setName(contact->getContactName());
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
updateState();
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
setStatus(contact->getStatus());
|
|
|
|
break;
|
2019-12-23 06:28:23 +00:00
|
|
|
case 7:
|
|
|
|
setAvatar(contact->getAvatarPath());
|
|
|
|
break;
|
2023-03-17 23:50:04 +00:00
|
|
|
case 8:
|
|
|
|
m_ui->encryptionButton->setVisible(contact->hasKeys(Shared::EncryptionProtocol::omemo2));
|
|
|
|
break;
|
2019-08-23 09:51:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-17 23:50:04 +00:00
|
|
|
void Chat::updateState() {
|
2019-08-23 09:51:33 +00:00
|
|
|
Shared::Availability av = contact->getAvailability();
|
|
|
|
statusIcon->setPixmap(Shared::availabilityIcon(av, true).pixmap(40));
|
2020-04-03 22:28:15 +00:00
|
|
|
statusIcon->setToolTip(Shared::Global::getName(av));
|
2019-08-23 09:51:33 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 23:50:04 +00:00
|
|
|
Shared::Message Chat::createMessage() const {
|
2020-04-15 13:48:49 +00:00
|
|
|
Shared::Message msg = Conversation::createMessage();
|
|
|
|
msg.setType(Shared::Message::chat);
|
2019-12-20 15:41:20 +00:00
|
|
|
msg.setFrom(account->getFullJid());
|
2019-08-28 11:40:55 +00:00
|
|
|
msg.setToJid(palJid);
|
|
|
|
msg.setToResource(activePalResource);
|
2020-04-15 13:48:49 +00:00
|
|
|
return msg;
|
2019-08-28 11:40:55 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 23:50:04 +00:00
|
|
|
void Chat::onMessage(const Shared::Message& data){
|
2021-04-27 19:29:15 +00:00
|
|
|
Conversation::onMessage(data);
|
|
|
|
|
|
|
|
if (!data.getOutgoing()) {
|
|
|
|
const QString& res = data.getPenPalResource();
|
2023-03-17 23:50:04 +00:00
|
|
|
if (res.size() > 0)
|
2021-04-27 19:29:15 +00:00
|
|
|
setPalResource(res);
|
|
|
|
}
|
|
|
|
}
|