squawk/core/handlers/rosterhandler.cpp

546 lines
21 KiB
C++
Raw Permalink Normal View History

2020-06-14 21:23:43 +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 "rosterhandler.h"
#include "core/account.h"
Core::RosterHandler::RosterHandler(Core::Account* account):
QObject(),
acc(account),
contacts(),
conferences(),
groups(),
queuedContacts(),
outOfRosterContacts() {}
void Core::RosterHandler::initialize() {
2020-06-14 21:23:43 +00:00
connect(acc->rm, &QXmppRosterManager::rosterReceived, this, &RosterHandler::onRosterReceived);
connect(acc->rm, &QXmppRosterManager::itemAdded, this, &RosterHandler::onRosterItemAdded);
connect(acc->rm, &QXmppRosterManager::itemRemoved, this, &RosterHandler::onRosterItemRemoved);
connect(acc->rm, &QXmppRosterManager::itemChanged, this, &RosterHandler::onRosterItemChanged);
2020-06-14 21:23:43 +00:00
connect(acc->mm, &QXmppMucManager::roomAdded, this, &RosterHandler::onMucRoomAdded);
connect(acc->bm, &QXmppBookmarkManager::bookmarksReceived, this, &RosterHandler::bookmarksReceived);
connect(acc, &Account::pepSupportChanged, this, &RosterHandler::onPepSupportedChanged);
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
connect(acc->th, &TrustHandler::trustLevelsChanged, this, &RosterHandler::onTrustChanged);
#endif
2020-06-14 21:23:43 +00:00
}
Core::RosterHandler::~RosterHandler() {
clear();
}
void Core::RosterHandler::clear() {
for (const std::pair<const QString, Contact*>& pair : contacts)
delete pair.second;
for (const std::pair<const QString, Conference*>& pair : conferences)
delete pair.second;
contacts.clear();
conferences.clear();
2020-06-14 21:23:43 +00:00
}
void Core::RosterHandler::onRosterReceived() {
2020-06-14 21:23:43 +00:00
QStringList bj = acc->rm->getRosterBareJids();
for (int i = 0; i < bj.size(); ++i) {
const QString& jid = bj[i];
2020-07-26 19:41:30 +00:00
addedAccount(jid.toLower());
2020-06-14 21:23:43 +00:00
}
}
void Core::RosterHandler::onRosterItemAdded(const QString& bareJid) {
2020-07-26 19:41:30 +00:00
QString lcJid = bareJid.toLower();
addedAccount(lcJid);
std::map<QString, QString>::const_iterator itr = queuedContacts.find(lcJid);
2020-06-14 21:23:43 +00:00
if (itr != queuedContacts.end()) {
2020-07-26 19:41:30 +00:00
acc->rm->subscribe(lcJid, itr->second);
2020-06-14 21:23:43 +00:00
queuedContacts.erase(itr);
}
}
void Core::RosterHandler::addedAccount(const QString& jid) {
2020-06-14 21:23:43 +00:00
std::map<QString, Contact*>::const_iterator itr = contacts.find(jid);
QXmppRosterIq::Item re = acc->rm->getRosterEntry(jid);
Contact* contact;
bool newContact = false;
if (itr == contacts.end()) {
newContact = true;
contact = new Contact(jid, acc->name);
contacts.insert(std::make_pair(jid, contact));
} else {
contact = itr->second;
}
QSet<QString> gr = re.groups();
Shared::SubscriptionState state = castSubscriptionState(re.subscriptionType());
contact->setGroups(gr);
contact->setSubscriptionState(state);
contact->setName(re.name());
if (newContact) {
handleNewContact(contact);
QMap<QString, QVariant> cData = contact->getInfo();
2023-03-17 20:59:51 +00:00
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
cData.insert("trust", QVariant::fromValue(acc->th->getSummary(jid)));
#endif
2020-06-14 21:23:43 +00:00
int grCount = 0;
for (const QString& groupName : gr) {
2020-06-14 21:23:43 +00:00
addToGroup(jid, groupName);
emit acc->addContact(jid, groupName, cData);
grCount++;
}
if (grCount == 0)
2020-06-14 21:23:43 +00:00
emit acc->addContact(jid, "", cData);
if (acc->pepSupport == Shared::Support::supported) {
acc->dm->requestInfo(jid);
//acc->dm->requestItems(jid);
}
2020-06-14 21:23:43 +00:00
}
}
void Core::RosterHandler::addNewRoom(const QString& jid, const QString& nick, const QString& roomName, bool autoJoin) {
2020-06-14 21:23:43 +00:00
QXmppMucRoom* room = acc->mm->addRoom(jid);
QString lNick = nick;
if (lNick.size() == 0)
2020-06-14 21:23:43 +00:00
lNick = acc->getName();
2020-06-14 21:23:43 +00:00
Conference* conf = new Conference(jid, acc->getName(), autoJoin, roomName, lNick, room);
conferences.insert(std::make_pair(jid, conf));
handleNewConference(conf);
QMap<QString, QVariant> cData = conf->getInfo();
2020-06-14 21:23:43 +00:00
emit acc->addRoom(jid, cData);
}
void Core::RosterHandler::addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups) {
2020-06-14 21:23:43 +00:00
if (acc->state == Shared::ConnectionState::connected) {
std::map<QString, QString>::const_iterator itr = queuedContacts.find(jid);
if (itr != queuedContacts.end()) {
qDebug() << "An attempt to add contact " << jid << " to account " << acc->name << " but the account is already queued for adding, skipping";
} else {
queuedContacts.insert(std::make_pair(jid, "")); //TODO need to add reason here;
acc->rm->addItem(jid, name, groups);
}
} else {
qDebug() << "An attempt to add contact " << jid << " to account " << acc->name << " but the account is not in the connected state, skipping";
}
}
void Core::RosterHandler::removeContactRequest(const QString& jid) {
2020-07-26 19:41:30 +00:00
QString lcJid = jid.toLower();
2020-06-14 21:23:43 +00:00
if (acc->state == Shared::ConnectionState::connected) {
2020-07-26 19:41:30 +00:00
std::set<QString>::const_iterator itr = outOfRosterContacts.find(lcJid);
2020-06-14 21:23:43 +00:00
if (itr != outOfRosterContacts.end()) {
outOfRosterContacts.erase(itr);
2020-07-26 19:41:30 +00:00
onRosterItemRemoved(lcJid);
2020-06-14 21:23:43 +00:00
} else {
2020-07-26 19:41:30 +00:00
acc->rm->removeItem(lcJid);
2020-06-14 21:23:43 +00:00
}
} else {
2020-07-26 19:41:30 +00:00
qDebug() << "An attempt to remove contact " << lcJid << " from account " << acc->name << " but the account is not in the connected state, skipping";
2020-06-14 21:23:43 +00:00
}
}
void Core::RosterHandler::handleNewRosterItem(Core::RosterItem* contact) {
2020-06-14 21:23:43 +00:00
connect(contact, &RosterItem::needHistory, this->acc, &Account::onContactNeedHistory);
connect(contact, &RosterItem::historyResponse, this->acc, &Account::onContactHistoryResponse);
2020-06-14 21:23:43 +00:00
connect(contact, &RosterItem::nameChanged, this, &RosterHandler::onContactNameChanged);
connect(contact, &RosterItem::avatarChanged, this, &RosterHandler::onContactAvatarChanged);
connect(contact, &RosterItem::encryptionChanged, this, &RosterHandler::onContactEncryptionChanged);
connect(contact, &RosterItem::requestVCard, acc->delay, &DelayManager::Manager::getVCard);
2020-06-14 21:23:43 +00:00
}
void Core::RosterHandler::handleNewContact(Core::Contact* contact) {
2020-06-14 21:23:43 +00:00
handleNewRosterItem(contact);
connect(contact, &Contact::groupAdded, this, &RosterHandler::onContactGroupAdded);
connect(contact, &Contact::groupRemoved, this, &RosterHandler::onContactGroupRemoved);
connect(contact, &Contact::subscriptionStateChanged, this, &RosterHandler::onContactSubscriptionStateChanged);
}
void Core::RosterHandler::handleNewConference(Core::Conference* contact) {
2020-06-14 21:23:43 +00:00
handleNewRosterItem(contact);
connect(contact, &Conference::nickChanged, this, &RosterHandler::onMucNickNameChanged);
connect(contact, &Conference::subjectChanged, this, &RosterHandler::onMucSubjectChanged);
connect(contact, &Conference::joinedChanged, this, &RosterHandler::onMucJoinedChanged);
connect(contact, &Conference::autoJoinChanged, this, &RosterHandler::onMucAutoJoinChanged);
connect(contact, &Conference::addParticipant, this, &RosterHandler::onMucAddParticipant);
connect(contact, &Conference::changeParticipant, this, &RosterHandler::onMucChangeParticipant);
connect(contact, &Conference::removeParticipant, this, &RosterHandler::onMucRemoveParticipant);
}
void Core::RosterHandler::onMucAddParticipant(const QString& nickName, const QMap<QString, QVariant>& data) {
2020-06-14 21:23:43 +00:00
Conference* room = static_cast<Conference*>(sender());
emit acc->addRoomParticipant(room->jid, nickName, data);
}
void Core::RosterHandler::onMucChangeParticipant(const QString& nickName, const QMap<QString, QVariant>& data) {
2020-06-14 21:23:43 +00:00
Conference* room = static_cast<Conference*>(sender());
emit acc->changeRoomParticipant(room->jid, nickName, data);
}
void Core::RosterHandler::onMucRemoveParticipant(const QString& nickName) {
2020-06-14 21:23:43 +00:00
Conference* room = static_cast<Conference*>(sender());
emit acc->removeRoomParticipant(room->jid, nickName);
}
void Core::RosterHandler::onMucSubjectChanged(const QString& subject) {
2020-06-14 21:23:43 +00:00
Conference* room = static_cast<Conference*>(sender());
emit acc->changeRoom(room->jid, {{"subject", subject}});
2020-06-14 21:23:43 +00:00
}
void Core::RosterHandler::onContactGroupAdded(const QString& group) {
2020-06-14 21:23:43 +00:00
Contact* contact = static_cast<Contact*>(sender());
if (contact->groupsCount() == 1) {
// not sure i need to handle it here, the situation with grouped and ungrouped contacts handled on the client anyway
}
2020-06-14 21:23:43 +00:00
QMap<QString, QVariant> cData({
{"name", contact->getName()},
{"state", QVariant::fromValue(contact->getSubscriptionState())},
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
{"trust", QVariant::fromValue(acc->th->getSummary(contact->jid))},
#endif
2023-11-05 01:12:15 +00:00
{"encryption", QVariant::fromValue(contact->encryption())}
2020-06-14 21:23:43 +00:00
});
addToGroup(contact->jid, group);
emit acc->addContact(contact->jid, group, cData);
}
void Core::RosterHandler::onContactGroupRemoved(const QString& group) {
2020-06-14 21:23:43 +00:00
Contact* contact = static_cast<Contact*>(sender());
if (contact->groupsCount() == 0) {
// not sure i need to handle it here, the situation with grouped and ungrouped contacts handled on the client anyway
}
2020-06-14 21:23:43 +00:00
emit acc->removeContact(contact->jid, group);
removeFromGroup(contact->jid, group);
}
void Core::RosterHandler::onContactNameChanged(const QString& cname) {
RosterItem* contact = static_cast<RosterItem*>(sender());
emit acc->changeContact(contact->jid, {{"name", cname}});
2020-06-14 21:23:43 +00:00
}
2023-11-05 01:12:15 +00:00
void Core::RosterHandler::onContactEncryptionChanged(Shared::EncryptionProtocol value) {
RosterItem* contact = static_cast<RosterItem*>(sender());
2023-11-05 01:12:15 +00:00
emit acc->changeContact(contact->jid, {{"encryption", QVariant::fromValue(value)}});
}
void Core::RosterHandler::onContactSubscriptionStateChanged(Shared::SubscriptionState cstate) {
2020-06-14 21:23:43 +00:00
Contact* contact = static_cast<Contact*>(sender());
emit acc->changeContact(contact->jid, {{"state", QVariant::fromValue(cstate)}});
}
void Core::RosterHandler::onTrustChanged(const QString& jid, const Shared::TrustSummary& trust) {
emit acc->changeContact(jid, {{"trust", QVariant::fromValue(trust)}});
2020-06-14 21:23:43 +00:00
}
void Core::RosterHandler::addToGroup(const QString& jid, const QString& group) {
2020-06-14 21:23:43 +00:00
std::map<QString, std::set<QString>>::iterator gItr = groups.find(group);
if (gItr == groups.end()) {
gItr = groups.insert(std::make_pair(group, std::set<QString>())).first;
emit acc->addGroup(group);
}
2020-07-26 19:41:30 +00:00
gItr->second.insert(jid.toLower());
2020-06-14 21:23:43 +00:00
}
void Core::RosterHandler::removeFromGroup(const QString& jid, const QString& group) {
2020-06-14 21:23:43 +00:00
QSet<QString> toRemove;
std::map<QString, std::set<QString>>::iterator itr = groups.find(group);
if (itr == groups.end()) {
qDebug() << "An attempt to remove contact" << jid << "of account" << acc->name << "from non existing group" << group << ", skipping";
return;
}
std::set<QString> contacts = itr->second;
2020-07-26 19:41:30 +00:00
std::set<QString>::const_iterator cItr = contacts.find(jid.toLower());
2020-06-14 21:23:43 +00:00
if (cItr != contacts.end()) {
contacts.erase(cItr);
if (contacts.size() == 0) {
emit acc->removeGroup(group);
groups.erase(group);
}
}
}
2023-11-14 23:23:39 +00:00
Core::RosterItem* Core::RosterHandler::getRosterItem(const QString& jid) {
RosterItem* item = nullptr;
2020-07-26 19:41:30 +00:00
QString lcJid = jid.toLower();
std::map<QString, Contact*>::const_iterator citr = contacts.find(lcJid);
2020-06-14 21:23:43 +00:00
if (citr != contacts.end()) {
item = citr->second;
} else {
2020-07-26 19:41:30 +00:00
std::map<QString, Conference*>::const_iterator coitr = conferences.find(lcJid);
if (coitr != conferences.end())
2020-06-14 21:23:43 +00:00
item = coitr->second;
}
return item;
}
2023-11-14 23:23:39 +00:00
Core::Conference* Core::RosterHandler::getConference(const QString& jid) {
2020-06-14 21:23:43 +00:00
Conference* item = 0;
2020-07-26 19:41:30 +00:00
std::map<QString, Conference*>::const_iterator coitr = conferences.find(jid.toLower());
if (coitr != conferences.end())
2020-06-14 21:23:43 +00:00
item = coitr->second;
2020-06-14 21:23:43 +00:00
return item;
}
2023-11-14 23:23:39 +00:00
Core::Contact* Core::RosterHandler::getContact(const QString& jid) {
2020-06-14 21:23:43 +00:00
Contact* item = 0;
2020-07-26 19:41:30 +00:00
std::map<QString, Contact*>::const_iterator citr = contacts.find(jid.toLower());
if (citr != contacts.end())
2020-06-14 21:23:43 +00:00
item = citr->second;
2020-06-14 21:23:43 +00:00
return item;
}
2023-11-14 23:23:39 +00:00
Core::Contact* Core::RosterHandler::addOutOfRosterContact(const QString& jid) {
2020-07-26 19:41:30 +00:00
QString lcJid = jid.toLower();
Contact* cnt = new Contact(lcJid, acc->name);
contacts.insert(std::make_pair(lcJid, cnt));
outOfRosterContacts.insert(lcJid);
2020-06-14 21:23:43 +00:00
cnt->setSubscriptionState(Shared::SubscriptionState::unknown);
2020-07-26 19:41:30 +00:00
emit acc->addContact(lcJid, "", QMap<QString, QVariant>({
{"state", QVariant::fromValue(Shared::SubscriptionState::unknown)},
2023-11-05 01:12:15 +00:00
{"encryption", QVariant::fromValue(Shared::EncryptionProtocol::none)}
2020-06-14 21:23:43 +00:00
}));
handleNewContact(cnt);
return cnt;
}
void Core::RosterHandler::onRosterItemChanged(const QString& bareJid) {
2020-07-26 19:41:30 +00:00
QString lcJid = bareJid.toLower();
std::map<QString, Contact*>::const_iterator itr = contacts.find(lcJid);
2020-06-14 21:23:43 +00:00
if (itr == contacts.end()) {
2020-07-26 19:41:30 +00:00
qDebug() << "An attempt to change non existing contact" << lcJid << "from account" << acc->name << ", skipping";
2020-06-14 21:23:43 +00:00
return;
}
Contact* contact = itr->second;
2020-07-26 19:41:30 +00:00
QXmppRosterIq::Item re = acc->rm->getRosterEntry(lcJid);
2020-06-14 21:23:43 +00:00
Shared::SubscriptionState state = castSubscriptionState(re.subscriptionType());
contact->setGroups(re.groups());
contact->setSubscriptionState(state);
contact->setName(re.name());
}
void Core::RosterHandler::onRosterItemRemoved(const QString& bareJid) {
2020-07-26 19:41:30 +00:00
QString lcJid = bareJid.toLower();
std::map<QString, Contact*>::const_iterator itr = contacts.find(lcJid);
2020-06-14 21:23:43 +00:00
if (itr == contacts.end()) {
2020-07-26 19:41:30 +00:00
qDebug() << "An attempt to remove non existing contact" << lcJid << "from account" << acc->name << ", skipping";
2020-06-14 21:23:43 +00:00
return;
}
Contact* contact = itr->second;
contacts.erase(itr);
QSet<QString> cGroups = contact->getGroups();
2023-11-05 01:12:15 +00:00
for (const QString& group : cGroups)
removeFromGroup(lcJid, group);
2020-07-26 19:41:30 +00:00
emit acc->removeContact(lcJid);
2020-06-14 21:23:43 +00:00
contact->deleteLater();
}
void Core::RosterHandler::onMucRoomAdded(QXmppMucRoom* room) {
2020-06-14 21:23:43 +00:00
qDebug() << "room" << room->jid() << "added with name" << room->name()
<< ", account" << acc->getName() << "joined:" << room->isJoined();
}
void Core::RosterHandler::bookmarksReceived(const QXmppBookmarkSet& bookmarks) {
2020-06-14 21:23:43 +00:00
QList<QXmppBookmarkConference> confs = bookmarks.conferences();
for (QList<QXmppBookmarkConference>::const_iterator itr = confs.begin(), end = confs.end(); itr != end; ++itr) {
const QXmppBookmarkConference& c = *itr;
2020-07-26 19:41:30 +00:00
QString jid = c.jid().toLower();
2020-06-14 21:23:43 +00:00
std::map<QString, Conference*>::const_iterator cItr = conferences.find(jid);
if (cItr == conferences.end()) {
addNewRoom(jid, c.nickName(), c.name(), c.autoJoin());
} else {
if (c.autoJoin())
cItr->second->setJoined(true);
else
cItr->second->setAutoJoin(false);
2020-06-14 21:23:43 +00:00
}
}
}
void Core::RosterHandler::onMucJoinedChanged(bool joined){
2020-06-14 21:23:43 +00:00
Conference* room = static_cast<Conference*>(sender());
emit acc->changeRoom(room->jid, {{"joined", joined}});
2020-06-14 21:23:43 +00:00
}
void Core::RosterHandler::onMucAutoJoinChanged(bool autoJoin) {
2020-06-14 21:23:43 +00:00
storeConferences();
Conference* room = static_cast<Conference*>(sender());
emit acc->changeRoom(room->jid, {{"autoJoin", autoJoin}});
2020-06-14 21:23:43 +00:00
}
void Core::RosterHandler::onMucNickNameChanged(const QString& nickName){
2020-06-14 21:23:43 +00:00
storeConferences();
Conference* room = static_cast<Conference*>(sender());
emit acc->changeRoom(room->jid, {{"nick", nickName}});
2020-06-14 21:23:43 +00:00
}
Shared::SubscriptionState Core::RosterHandler::castSubscriptionState(QXmppRosterIq::Item::SubscriptionType qs){
2020-06-14 21:23:43 +00:00
Shared::SubscriptionState state;
if (qs == QXmppRosterIq::Item::NotSet)
2020-06-14 21:23:43 +00:00
state = Shared::SubscriptionState::unknown;
else
2020-06-14 21:23:43 +00:00
state = static_cast<Shared::SubscriptionState>(qs);
2020-06-14 21:23:43 +00:00
return state;
}
void Core::RosterHandler::storeConferences() {
2020-06-14 21:23:43 +00:00
QXmppBookmarkSet bms = acc->bm->bookmarks();
QList<QXmppBookmarkConference> confs;
for (std::map<QString, Conference*>::const_iterator itr = conferences.begin(), end = conferences.end(); itr != end; ++itr) {
Conference* conference = itr->second;
QXmppBookmarkConference conf;
conf.setJid(conference->jid);
conf.setName(conference->getName());
conf.setNickName(conference->getNick());
conf.setAutoJoin(conference->getAutoJoin());
confs.push_back(conf);
}
bms.setConferences(confs);
acc->bm->setBookmarks(bms);
}
void Core::RosterHandler::clearConferences() {
2020-06-14 21:23:43 +00:00
for (std::map<QString, Conference*>::const_iterator itr = conferences.begin(), end = conferences.end(); itr != end; itr++) {
itr->second->deleteLater();
emit acc->removeRoom(itr->first);
}
conferences.clear();
}
void Core::RosterHandler::removeRoomRequest(const QString& jid) {
2020-07-26 19:41:30 +00:00
QString lcJid = jid.toLower();
std::map<QString, Conference*>::const_iterator itr = conferences.find(lcJid);
2023-11-14 23:23:39 +00:00
if (itr == conferences.end())
2020-07-26 19:41:30 +00:00
qDebug() << "An attempt to remove non existing room" << lcJid << "from account" << acc->name << ", skipping";
2023-11-14 23:23:39 +00:00
2020-06-14 21:23:43 +00:00
itr->second->deleteLater();
conferences.erase(itr);
2020-07-26 19:41:30 +00:00
emit acc->removeRoom(lcJid);
2020-06-14 21:23:43 +00:00
storeConferences();
}
void Core::RosterHandler::addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin) {
2023-08-15 15:28:25 +00:00
SHARED_UNUSED(password);
2020-07-26 19:41:30 +00:00
QString lcJid = jid.toLower();
std::map<QString, Conference*>::const_iterator cItr = conferences.find(lcJid);
2020-06-14 21:23:43 +00:00
if (cItr == conferences.end()) {
2020-07-26 19:41:30 +00:00
addNewRoom(lcJid, nick, "", autoJoin);
2020-06-14 21:23:43 +00:00
storeConferences();
} else {
2020-07-26 19:41:30 +00:00
qDebug() << "An attempt to add a MUC " << lcJid << " which is already present in the rester, skipping";
2020-06-14 21:23:43 +00:00
}
}
void Core::RosterHandler::addContactToGroupRequest(const QString& jid, const QString& groupName) {
2020-07-26 19:41:30 +00:00
QString lcJid = jid.toLower();
std::map<QString, Contact*>::const_iterator itr = contacts.find(lcJid);
2020-06-14 21:23:43 +00:00
if (itr == contacts.end()) {
2020-07-26 19:41:30 +00:00
qDebug() << "An attempt to add non existing contact" << lcJid << "of account"
2020-06-14 21:23:43 +00:00
<< acc->name << "to the group" << groupName << ", skipping";
} else {
2020-07-26 19:41:30 +00:00
QXmppRosterIq::Item item = acc->rm->getRosterEntry(lcJid);
2020-06-14 21:23:43 +00:00
QSet<QString> groups = item.groups();
if (groups.find(groupName) == groups.end()) { //TODO need to change it, I guess that sort of code is better in qxmpp lib
groups.insert(groupName);
item.setGroups(groups);
QXmppRosterIq iq;
iq.setType(QXmppIq::Set);
iq.addItem(item);
acc->client.sendPacket(iq);
} else {
qDebug() << "An attempt to add contact" << jid << "of account"
<< acc->name << "to the group" << groupName << "but it's already in that group, skipping";
}
}
}
void Core::RosterHandler::removeContactFromGroupRequest(const QString& jid, const QString& groupName) {
2020-07-26 19:41:30 +00:00
QString lcJid = jid.toLower();
std::map<QString, Contact*>::const_iterator itr = contacts.find(lcJid);
2020-06-14 21:23:43 +00:00
if (itr == contacts.end()) {
2020-07-26 19:41:30 +00:00
qDebug() << "An attempt to remove non existing contact" << lcJid << "of account"
2020-06-14 21:23:43 +00:00
<< acc->name << "from the group" << groupName << ", skipping";
return;
}
QXmppRosterIq::Item item = acc->rm->getRosterEntry(lcJid);
QSet<QString> groups = item.groups();
QSet<QString>::const_iterator gItr = groups.find(groupName);
if (gItr != groups.end()) {
groups.erase(gItr);
item.setGroups(groups);
QXmppRosterIq iq;
iq.setType(QXmppIq::Set);
iq.addItem(item);
acc->client.sendPacket(iq);
2020-06-14 21:23:43 +00:00
} else {
qDebug() << "An attempt to remove contact" << lcJid << "of account"
<< acc->name << "from the group" << groupName << "but it's not in that group, skipping";
2020-06-14 21:23:43 +00:00
}
}
void Core::RosterHandler::onContactAvatarChanged(Shared::Avatar type, const QString& path) {
2020-06-14 21:23:43 +00:00
RosterItem* item = static_cast<RosterItem*>(sender());
QMap<QString, QVariant> cData({
{"avatarState", QVariant::fromValue(type)},
2020-06-14 21:23:43 +00:00
{"avatarPath", path}
});
emit acc->changeContact(item->jid, cData);
}
void Core::RosterHandler::handleOffline() {
2020-06-14 21:23:43 +00:00
for (const std::pair<const QString, Conference*>& pair : conferences) {
pair.second->clearArchiveRequests();
pair.second->downgradeDatabaseState();
2020-06-14 21:23:43 +00:00
}
for (const std::pair<const QString, Contact*>& pair : contacts) {
pair.second->clearArchiveRequests();
pair.second->downgradeDatabaseState();
2020-06-14 21:23:43 +00:00
}
}
void Core::RosterHandler::onPepSupportedChanged(Shared::Support support) {
if (support == Shared::Support::supported) {
for (const std::pair<const QString, Contact*>& pair : contacts) {
if (pair.second->getPepSupport() == Shared::Support::unknown)
acc->dm->requestInfo(pair.first);
}
}
2020-06-14 21:23:43 +00:00
}