Refactoring, account destruction fix, some thoughts about where to store contact settings (omemo enable status for instance)
This commit is contained in:
parent
283e9ebc4d
commit
fffef9876a
@ -44,6 +44,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
||||
#endif
|
||||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
cm(new QXmppCarbonManagerV2()),
|
||||
psm(new QXmppPubSubManager()),
|
||||
#else
|
||||
cm(new QXmppCarbonManager()),
|
||||
#endif
|
||||
@ -55,7 +56,6 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
||||
um(new QXmppUploadRequestManager()),
|
||||
dm(client.findExtension<QXmppDiscoveryManager>()),
|
||||
rcpm(new QXmppMessageReceiptManager()),
|
||||
psm(new QXmppPubSubManager()),
|
||||
reconnectScheduled(false),
|
||||
reconnectTimer(new QTimer),
|
||||
network(p_net),
|
||||
@ -167,22 +167,34 @@ Account::~Account() {
|
||||
QObject::disconnect(network, &NetworkAccess::downloadFileComplete, mh, &MessageHandler::onDownloadFileComplete);
|
||||
QObject::disconnect(network, &NetworkAccess::loadFileError, mh, &MessageHandler::onLoadFileError);
|
||||
|
||||
delete vh;
|
||||
delete mh;
|
||||
delete rh;
|
||||
|
||||
rh->clear(); //conferenses inside of roster handler hold QXmppMuc objects.
|
||||
//If we destroy QXmppMucManager, then when we will be destroying RosterHandler
|
||||
//it will try to destory Core::Conference objects
|
||||
//and inside of those QXmppMuc objects will already be destroyed.
|
||||
//So, clear will start the destruction from Core::Conference and this way it's not gonna crash
|
||||
|
||||
delete delay;
|
||||
delete reconnectTimer;
|
||||
#ifdef WITH_OMEMO
|
||||
delete om;
|
||||
#endif
|
||||
delete rcpm;
|
||||
delete dm;
|
||||
delete um;
|
||||
delete bm;
|
||||
delete mm;
|
||||
delete am;
|
||||
delete cm;
|
||||
delete delay;
|
||||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
delete psm;
|
||||
#endif
|
||||
#ifdef WITH_OMEMO
|
||||
delete om;
|
||||
delete tm;
|
||||
delete oh;
|
||||
delete th;
|
||||
#endif
|
||||
|
||||
delete dh;
|
||||
delete vh;
|
||||
delete rh;
|
||||
delete mh;
|
||||
}
|
||||
|
||||
Shared::ConnectionState Core::Account::getState() const {
|
||||
@ -345,7 +357,7 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence) {
|
||||
vh->handlePresenceOfMyAccountChange(p_presence);
|
||||
} else {
|
||||
RosterItem* item = rh->getRosterItem(jid);
|
||||
if (item != 0)
|
||||
if (item != nullptr)
|
||||
item->handlePresence(p_presence);
|
||||
}
|
||||
|
||||
@ -417,7 +429,7 @@ void Core::Account::requestArchive(const QString& jid, int count, const QString&
|
||||
qDebug() << "An archive request for " << jid << ", before " << before;
|
||||
RosterItem* contact = rh->getRosterItem(jid);
|
||||
|
||||
if (contact == 0) {
|
||||
if (contact == nullptr) {
|
||||
qDebug() << "An attempt to request archive for" << jid << "in account" << name << ", but the contact with such id wasn't found, skipping";
|
||||
emit responseArchive(jid, std::list<Shared::Message>(), true);
|
||||
return;
|
||||
@ -483,7 +495,7 @@ void Core::Account::onMamResultsReceived(const QString& queryId, const QXmppResu
|
||||
|
||||
RosterItem* ri = rh->getRosterItem(jid);
|
||||
|
||||
if (ri != 0) {
|
||||
if (ri != nullptr) {
|
||||
qDebug() << "Flushing messages for" << jid << ", complete:" << complete;
|
||||
ri->flushMessagesToArchive(complete, resultSetReply.first(), resultSetReply.last());
|
||||
}
|
||||
|
@ -200,6 +200,7 @@ private:
|
||||
#endif
|
||||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
QXmppCarbonManagerV2* cm;
|
||||
QXmppPubSubManager* psm;
|
||||
#else
|
||||
QXmppCarbonManager* cm;
|
||||
#endif
|
||||
@ -211,7 +212,6 @@ private:
|
||||
QXmppUploadRequestManager* um;
|
||||
QXmppDiscoveryManager* dm;
|
||||
QXmppMessageReceiptManager* rcpm;
|
||||
QXmppPubSubManager* psm;
|
||||
bool reconnectScheduled;
|
||||
QTimer* reconnectTimer;
|
||||
|
||||
|
@ -42,57 +42,48 @@ Core::Conference::Conference(const QString& p_jid, const QString& p_account, boo
|
||||
connect(room, &QXmppMucRoom::error, this, &Conference::onRoomError);
|
||||
|
||||
room->setNickName(nick);
|
||||
if (autoJoin) {
|
||||
if (autoJoin)
|
||||
room->join();
|
||||
}
|
||||
|
||||
archive->readAllResourcesAvatars(exParticipants);
|
||||
}
|
||||
|
||||
Core::Conference::~Conference()
|
||||
{
|
||||
if (joined) {
|
||||
Core::Conference::~Conference(){
|
||||
if (joined)
|
||||
room->leave();
|
||||
}
|
||||
|
||||
room->deleteLater();
|
||||
}
|
||||
|
||||
QString Core::Conference::getNick() const
|
||||
{
|
||||
QString Core::Conference::getNick() const {
|
||||
return nick;
|
||||
}
|
||||
|
||||
bool Core::Conference::getAutoJoin()
|
||||
{
|
||||
bool Core::Conference::getAutoJoin() const {
|
||||
return autoJoin;
|
||||
}
|
||||
|
||||
bool Core::Conference::getJoined() const
|
||||
{
|
||||
bool Core::Conference::getJoined() const {
|
||||
return joined;
|
||||
}
|
||||
|
||||
void Core::Conference::setJoined(bool p_joined)
|
||||
{
|
||||
void Core::Conference::setJoined(bool p_joined) {
|
||||
if (joined != p_joined) {
|
||||
if (p_joined) {
|
||||
if (p_joined)
|
||||
room->join();
|
||||
} else {
|
||||
else
|
||||
room->leave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::setAutoJoin(bool p_autoJoin)
|
||||
{
|
||||
void Core::Conference::setAutoJoin(bool p_autoJoin) {
|
||||
if (autoJoin != p_autoJoin) {
|
||||
autoJoin = p_autoJoin;
|
||||
emit autoJoinChanged(autoJoin);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::setNick(const QString& p_nick)
|
||||
{
|
||||
void Core::Conference::setNick(const QString& p_nick) {
|
||||
if (nick != p_nick) {
|
||||
if (joined) {
|
||||
room->setNickName(p_nick);
|
||||
@ -103,45 +94,38 @@ void Core::Conference::setNick(const QString& p_nick)
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomJoined()
|
||||
{
|
||||
void Core::Conference::onRoomJoined() {
|
||||
joined = true;
|
||||
emit joinedChanged(joined);
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomLeft()
|
||||
{
|
||||
void Core::Conference::onRoomLeft() {
|
||||
joined = false;
|
||||
emit joinedChanged(joined);
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomNameChanged(const QString& p_name)
|
||||
{
|
||||
void Core::Conference::onRoomNameChanged(const QString& p_name) {
|
||||
setName(p_name);
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomNickNameChanged(const QString& p_nick)
|
||||
{
|
||||
void Core::Conference::onRoomNickNameChanged(const QString& p_nick) {
|
||||
if (p_nick != nick) {
|
||||
nick = p_nick;
|
||||
emit nickChanged(nick);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomError(const QXmppStanza::Error& err)
|
||||
{
|
||||
void Core::Conference::onRoomError(const QXmppStanza::Error& err) {
|
||||
qDebug() << "MUC" << jid << "error:" << err.text();
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
||||
{
|
||||
void Core::Conference::onRoomParticipantAdded(const QString& p_name) {
|
||||
QStringList comps = p_name.split("/");
|
||||
QString resource = comps.back();
|
||||
QXmppPresence pres = room->participantPresence(p_name);
|
||||
QXmppMucItem mi = pres.mucItem();
|
||||
if (resource == jid) {
|
||||
if (resource == jid)
|
||||
resource = "";
|
||||
}
|
||||
|
||||
std::map<QString, Archive::AvatarInfo>::const_iterator itr = exParticipants.find(resource);
|
||||
bool hasAvatar = itr != exParticipants.end();
|
||||
@ -166,19 +150,7 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
if (hasAvatar) {
|
||||
if (itr->second.autogenerated) {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::valid));
|
||||
} else {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::autocreated));
|
||||
}
|
||||
cData.insert("avatarPath", avatarPath(resource) + "." + itr->second.type);
|
||||
} else {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::empty));
|
||||
cData.insert("avatarPath", "");
|
||||
emit requestVCard(p_name);
|
||||
}
|
||||
careAboutAvatar(hasAvatar, itr->second, cData, resource, p_name);
|
||||
|
||||
emit addParticipant(resource, cData);
|
||||
}
|
||||
@ -196,9 +168,9 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
||||
break;
|
||||
case QXmppPresence::VCardUpdateValidPhoto:{ //there is a photo, need to load
|
||||
if (hasAvatar) {
|
||||
if (itr->second.autogenerated || itr->second.hash != pres.photoHash()) {
|
||||
if (itr->second.autogenerated || itr->second.hash != pres.photoHash())
|
||||
emit requestVCard(p_name);
|
||||
}
|
||||
|
||||
} else {
|
||||
emit requestVCard(p_name);
|
||||
}
|
||||
@ -207,8 +179,7 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomParticipantChanged(const QString& p_name)
|
||||
{
|
||||
void Core::Conference::onRoomParticipantChanged(const QString& p_name) {
|
||||
QStringList comps = p_name.split("/");
|
||||
QString resource = comps.back();
|
||||
QXmppPresence pres = room->participantPresence(p_name);
|
||||
@ -216,9 +187,8 @@ void Core::Conference::onRoomParticipantChanged(const QString& p_name)
|
||||
handlePresence(pres);
|
||||
if (resource != jid) {
|
||||
QDateTime lastInteraction = pres.lastUserInteraction();
|
||||
if (!lastInteraction.isValid()) {
|
||||
if (!lastInteraction.isValid())
|
||||
lastInteraction = QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
|
||||
emit changeParticipant(resource, {
|
||||
{"lastActivity", lastInteraction},
|
||||
@ -237,8 +207,7 @@ void Core::Conference::onRoomParticipantChanged(const QString& p_name)
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomParticipantRemoved(const QString& p_name)
|
||||
{
|
||||
void Core::Conference::onRoomParticipantRemoved(const QString& p_name) {
|
||||
QStringList comps = p_name.split("/");
|
||||
QString resource = comps.back();
|
||||
if (resource == jid) {
|
||||
@ -248,29 +217,24 @@ void Core::Conference::onRoomParticipantRemoved(const QString& p_name)
|
||||
}
|
||||
}
|
||||
|
||||
QString Core::Conference::getSubject() const
|
||||
{
|
||||
if (joined) {
|
||||
QString Core::Conference::getSubject() const {
|
||||
if (joined)
|
||||
return room->subject();
|
||||
} else {
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomSubjectChanged(const QString& p_name)
|
||||
{
|
||||
void Core::Conference::onRoomSubjectChanged(const QString& p_name) {
|
||||
emit subjectChanged(p_name);
|
||||
}
|
||||
|
||||
void Core::Conference::handlePresence(const QXmppPresence& pres)
|
||||
{
|
||||
void Core::Conference::handlePresence(const QXmppPresence& pres) {
|
||||
QString id = pres.from();
|
||||
QStringList comps = id.split("/");
|
||||
QString jid = comps.front();
|
||||
QString resource("");
|
||||
if (comps.size() > 1) {
|
||||
if (comps.size() > 1)
|
||||
resource = comps.back();
|
||||
}
|
||||
|
||||
switch (pres.vCardUpdateType()) {
|
||||
case QXmppPresence::VCardUpdateNone: //this presence has nothing to do with photo
|
||||
@ -284,14 +248,13 @@ void Core::Conference::handlePresence(const QXmppPresence& pres)
|
||||
setAutoGeneratedAvatar(resource);
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case QXmppPresence::VCardUpdateValidPhoto:{ //there is a photo, need to load
|
||||
Archive::AvatarInfo info;
|
||||
bool hasAvatar = readAvatarInfo(info, resource);
|
||||
if (hasAvatar) {
|
||||
if (info.autogenerated || info.hash != pres.photoHash()) {
|
||||
if (info.autogenerated || info.hash != pres.photoHash())
|
||||
emit requestVCard(id);
|
||||
}
|
||||
} else {
|
||||
emit requestVCard(id);
|
||||
}
|
||||
@ -300,17 +263,15 @@ void Core::Conference::handlePresence(const QXmppPresence& pres)
|
||||
}
|
||||
}
|
||||
|
||||
bool Core::Conference::setAutoGeneratedAvatar(const QString& resource)
|
||||
{
|
||||
bool Core::Conference::setAutoGeneratedAvatar(const QString& resource) {
|
||||
Archive::AvatarInfo newInfo;
|
||||
bool result = RosterItem::setAutoGeneratedAvatar(newInfo, resource);
|
||||
if (result && resource.size() != 0) {
|
||||
std::map<QString, Archive::AvatarInfo>::iterator itr = exParticipants.find(resource);
|
||||
if (itr == exParticipants.end()) {
|
||||
if (itr == exParticipants.end())
|
||||
exParticipants.insert(std::make_pair(resource, newInfo));
|
||||
} else {
|
||||
else
|
||||
itr->second = newInfo;
|
||||
}
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(Shared::Avatar::autocreated)},
|
||||
{"avatarPath", avatarPath(resource) + "." + newInfo.type}
|
||||
@ -320,17 +281,15 @@ bool Core::Conference::setAutoGeneratedAvatar(const QString& resource)
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Core::Conference::setAvatar(const QByteArray& data, Archive::AvatarInfo& info, const QString& resource)
|
||||
{
|
||||
bool Core::Conference::setAvatar(const QByteArray& data, Archive::AvatarInfo& info, const QString& resource) {
|
||||
bool result = RosterItem::setAvatar(data, info, resource);
|
||||
if (result && resource.size() != 0) {
|
||||
if (data.size() > 0) {
|
||||
std::map<QString, Archive::AvatarInfo>::iterator itr = exParticipants.find(resource);
|
||||
if (itr == exParticipants.end()) {
|
||||
if (itr == exParticipants.end())
|
||||
exParticipants.insert(std::make_pair(resource, info));
|
||||
} else {
|
||||
else
|
||||
itr->second = info;
|
||||
}
|
||||
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(Shared::Avatar::autocreated)},
|
||||
@ -338,9 +297,8 @@ bool Core::Conference::setAvatar(const QByteArray& data, Archive::AvatarInfo& in
|
||||
});
|
||||
} else {
|
||||
std::map<QString, Archive::AvatarInfo>::iterator itr = exParticipants.find(resource);
|
||||
if (itr != exParticipants.end()) {
|
||||
if (itr != exParticipants.end())
|
||||
exParticipants.erase(itr);
|
||||
}
|
||||
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(Shared::Avatar::empty)},
|
||||
@ -353,10 +311,8 @@ bool Core::Conference::setAvatar(const QByteArray& data, Archive::AvatarInfo& in
|
||||
return result;
|
||||
}
|
||||
|
||||
void Core::Conference::handleResponseVCard(const QXmppVCardIq& card, const QString &resource, Shared::VCard& out)
|
||||
{
|
||||
void Core::Conference::handleResponseVCard(const QXmppVCardIq& card, const QString &resource, Shared::VCard& out) {
|
||||
RosterItem::handleResponseVCard(card, resource, out);
|
||||
|
||||
if (resource.size() > 0) {
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(out.getAvatarType())},
|
||||
@ -365,11 +321,21 @@ void Core::Conference::handleResponseVCard(const QXmppVCardIq& card, const QStri
|
||||
}
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> Core::Conference::getAllAvatars() const
|
||||
{
|
||||
QMap<QString, QVariant> Core::Conference::getAllAvatars() const {
|
||||
QMap<QString, QVariant> result;
|
||||
for (const std::pair<const QString, Archive::AvatarInfo>& pair : exParticipants) {
|
||||
for (const std::pair<const QString, Archive::AvatarInfo>& pair : exParticipants)
|
||||
result.insert(pair.first, avatarPath(pair.first) + "." + pair.second.type);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> Core::Conference::getInfo() const {
|
||||
QMap<QString, QVariant> data = RosterItem::getInfo();
|
||||
|
||||
data.insert("autoJoin", getAutoJoin());
|
||||
data.insert("joined", getJoined());
|
||||
data.insert("nick", getNick());
|
||||
data.insert("avatars", getAllAvatars());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -49,12 +49,13 @@ public:
|
||||
bool getJoined() const;
|
||||
void setJoined(bool p_joined);
|
||||
|
||||
bool getAutoJoin();
|
||||
bool getAutoJoin() const;
|
||||
void setAutoJoin(bool p_autoJoin);
|
||||
void handlePresence(const QXmppPresence & pres) override;
|
||||
bool setAutoGeneratedAvatar(const QString& resource = "") override;
|
||||
void handleResponseVCard(const QXmppVCardIq & card, const QString &resource, Shared::VCard& out) override;
|
||||
QMap<QString, QVariant> getAllAvatars() const;
|
||||
QMap<QString, QVariant> getInfo() const override;
|
||||
|
||||
signals:
|
||||
void nickChanged(const QString& nick);
|
||||
|
@ -24,54 +24,43 @@ Core::Contact::Contact(const QString& pJid, const QString& account, QObject* par
|
||||
groups(),
|
||||
subscriptionState(Shared::SubscriptionState::unknown),
|
||||
pep(Shared::Support::unknown)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
Core::Contact::~Contact()
|
||||
{
|
||||
}
|
||||
Core::Contact::~Contact() {}
|
||||
|
||||
QSet<QString> Core::Contact::getGroups() const
|
||||
{
|
||||
QSet<QString> Core::Contact::getGroups() const {
|
||||
return groups;
|
||||
}
|
||||
|
||||
unsigned int Core::Contact::groupsCount() const
|
||||
{
|
||||
unsigned int Core::Contact::groupsCount() const {
|
||||
return groups.size();
|
||||
}
|
||||
|
||||
void Core::Contact::setGroups(const QSet<QString>& set)
|
||||
{
|
||||
void Core::Contact::setGroups(const QSet<QString>& set) {
|
||||
QSet<QString> toRemove = groups - set;
|
||||
QSet<QString> toAdd = set - groups;
|
||||
|
||||
groups = set;
|
||||
|
||||
for (QSet<QString>::iterator itr = toRemove.begin(), end = toRemove.end(); itr != end; ++itr) {
|
||||
emit groupRemoved(*itr);
|
||||
}
|
||||
for (const QString& group : toRemove)
|
||||
emit groupRemoved(group);
|
||||
|
||||
for (QSet<QString>::iterator itr = toAdd.begin(), end = toAdd.end(); itr != end; ++itr) {
|
||||
emit groupAdded(*itr);
|
||||
}
|
||||
for (const QString& group : toAdd)
|
||||
emit groupAdded(group);
|
||||
}
|
||||
|
||||
Shared::SubscriptionState Core::Contact::getSubscriptionState() const
|
||||
{
|
||||
Shared::SubscriptionState Core::Contact::getSubscriptionState() const {
|
||||
return subscriptionState;
|
||||
}
|
||||
|
||||
void Core::Contact::setSubscriptionState(Shared::SubscriptionState state)
|
||||
{
|
||||
void Core::Contact::setSubscriptionState(Shared::SubscriptionState state) {
|
||||
if (subscriptionState != state) {
|
||||
subscriptionState = state;
|
||||
emit subscriptionStateChanged(subscriptionState);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Contact::handlePresence(const QXmppPresence& pres)
|
||||
{
|
||||
void Core::Contact::handlePresence(const QXmppPresence& pres) {
|
||||
switch (pres.vCardUpdateType()) {
|
||||
case QXmppPresence::VCardUpdateNone: //this presence has nothing to do with photo
|
||||
break;
|
||||
@ -101,13 +90,21 @@ void Core::Contact::handlePresence(const QXmppPresence& pres)
|
||||
}
|
||||
|
||||
void Core::Contact::setPepSupport(Shared::Support support) {
|
||||
if (pep != support) {
|
||||
if (pep != support)
|
||||
pep = support;
|
||||
}
|
||||
}
|
||||
|
||||
Shared::Support Core::Contact::getPepSupport() const {
|
||||
return pep;}
|
||||
return pep;
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> Core::Contact::getInfo() const {
|
||||
QMap<QString, QVariant> data = RosterItem::getInfo();
|
||||
|
||||
data.insert("state", QVariant::fromValue(subscriptionState));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
Shared::Support getPepSupport() const;
|
||||
|
||||
void handlePresence(const QXmppPresence & pres) override;
|
||||
QMap<QString, QVariant> getInfo() const override;
|
||||
|
||||
signals:
|
||||
void groupAdded(const QString& name);
|
||||
|
@ -83,7 +83,7 @@ void Core::MessageHandler::onMessageReceived(const QXmppMessage& msg)
|
||||
{"state", static_cast<uint>(Shared::Message::State::error)},
|
||||
{"errorText", msg.error().text()}
|
||||
};
|
||||
if (cnt != 0) {
|
||||
if (cnt != nullptr) {
|
||||
cnt->changeMessage(id, cData);
|
||||
}
|
||||
emit acc->changeMessage(jid, id, cData);
|
||||
@ -291,7 +291,7 @@ void Core::MessageHandler::onReceiptReceived(const QString& jid, const QString&
|
||||
QMap<QString, QVariant> cData = {{"state", static_cast<uint>(Shared::Message::State::delivered)}};
|
||||
RosterItem* ri = acc->rh->getRosterItem(std::get<2>(ids));
|
||||
|
||||
if (ri != 0) {
|
||||
if (ri != nullptr) {
|
||||
ri->changeMessage(std::get<1>(ids), cData);
|
||||
}
|
||||
emit acc->changeMessage(std::get<2>(ids), std::get<1>(ids), cData);
|
||||
@ -346,7 +346,7 @@ void Core::MessageHandler::performSending(Shared::Message data, const QString& o
|
||||
} else {
|
||||
realId = id;
|
||||
}
|
||||
if (ri != 0) {
|
||||
if (ri != nullptr) {
|
||||
if (newMessage) {
|
||||
ri->appendMessageToArchive(data);
|
||||
} else {
|
||||
@ -429,7 +429,7 @@ void Core::MessageHandler::prepareUpload(const Shared::Message& data, bool newMe
|
||||
QString jid = data.getPenPalJid();
|
||||
QString id = data.getId();
|
||||
RosterItem* ri = acc->rh->getRosterItem(jid);
|
||||
if (!ri) {
|
||||
if (ri == nullptr) {
|
||||
qDebug() << "An attempt to initialize upload in" << acc->name << "for pal" << jid << "but the object for this pal wasn't found, something went terrebly wrong, skipping send";
|
||||
return;
|
||||
}
|
||||
@ -517,7 +517,7 @@ void Core::MessageHandler::onDownloadFileComplete(const std::list<Shared::Messag
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
if (info.account == acc->getName()) {
|
||||
RosterItem* cnt = acc->rh->getRosterItem(info.jid);
|
||||
if (cnt != 0) {
|
||||
if (cnt != nullptr) {
|
||||
if (cnt->changeMessage(info.messageId, cData)) {
|
||||
emit acc->changeMessage(info.jid, info.messageId, cData);
|
||||
}
|
||||
@ -553,7 +553,7 @@ void Core::MessageHandler::onUploadFileComplete(const std::list<Shared::MessageI
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
if (info.account == acc->getName()) {
|
||||
RosterItem* ri = acc->rh->getRosterItem(info.jid);
|
||||
if (ri != 0) {
|
||||
if (ri != nullptr) {
|
||||
Shared::Message msg = ri->getMessage(info.messageId);
|
||||
msg.setAttachPath(path);
|
||||
sendMessageWithLocalUploadedFile(msg, url, false);
|
||||
@ -584,7 +584,7 @@ static const std::set<QString> allowedToChangeKeys({
|
||||
void Core::MessageHandler::requestChangeMessage(const QString& jid, const QString& messageId, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
RosterItem* cnt = acc->rh->getRosterItem(jid);
|
||||
if (cnt != 0) {
|
||||
if (cnt != nullptr) {
|
||||
bool allSupported = true;
|
||||
QString unsupportedString;
|
||||
for (QMap<QString, QVariant>::const_iterator itr = data.begin(); itr != data.end(); ++itr) { //I need all this madness
|
||||
@ -607,7 +607,7 @@ void Core::MessageHandler::requestChangeMessage(const QString& jid, const QStrin
|
||||
void Core::MessageHandler::resendMessage(const QString& jid, const QString& id)
|
||||
{
|
||||
RosterItem* cnt = acc->rh->getRosterItem(jid);
|
||||
if (cnt != 0) {
|
||||
if (cnt != nullptr) {
|
||||
try {
|
||||
Shared::Message msg = cnt->getMessage(id);
|
||||
if (msg.getState() == Shared::Message::State::error) {
|
||||
|
@ -41,19 +41,23 @@ void Core::RosterHandler::initialize() {
|
||||
connect(acc, &Account::pepSupportChanged, this, &RosterHandler::onPepSupportedChanged);
|
||||
}
|
||||
|
||||
Core::RosterHandler::~RosterHandler()
|
||||
{
|
||||
for (std::map<QString, Contact*>::const_iterator itr = contacts.begin(), end = contacts.end(); itr != end; ++itr) {
|
||||
delete itr->second;
|
||||
}
|
||||
|
||||
for (std::map<QString, Conference*>::const_iterator itr = conferences.begin(), end = conferences.end(); itr != end; ++itr) {
|
||||
delete itr->second;
|
||||
}
|
||||
Core::RosterHandler::~RosterHandler() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onRosterReceived()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
void Core::RosterHandler::onRosterReceived() {
|
||||
QStringList bj = acc->rm->getRosterBareJids();
|
||||
for (int i = 0; i < bj.size(); ++i) {
|
||||
const QString& jid = bj[i];
|
||||
@ -61,8 +65,7 @@ void Core::RosterHandler::onRosterReceived()
|
||||
}
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onRosterItemAdded(const QString& bareJid)
|
||||
{
|
||||
void Core::RosterHandler::onRosterItemAdded(const QString& bareJid) {
|
||||
QString lcJid = bareJid.toLower();
|
||||
addedAccount(lcJid);
|
||||
std::map<QString, QString>::const_iterator itr = queuedContacts.find(lcJid);
|
||||
@ -72,8 +75,7 @@ void Core::RosterHandler::onRosterItemAdded(const QString& bareJid)
|
||||
}
|
||||
}
|
||||
|
||||
void Core::RosterHandler::addedAccount(const QString& jid)
|
||||
{
|
||||
void Core::RosterHandler::addedAccount(const QString& jid) {
|
||||
std::map<QString, Contact*>::const_iterator itr = contacts.find(jid);
|
||||
QXmppRosterIq::Item re = acc->rm->getRosterEntry(jid);
|
||||
Contact* contact;
|
||||
@ -82,7 +84,6 @@ void Core::RosterHandler::addedAccount(const QString& jid)
|
||||
newContact = true;
|
||||
contact = new Contact(jid, acc->name);
|
||||
contacts.insert(std::make_pair(jid, contact));
|
||||
|
||||
} else {
|
||||
contact = itr->second;
|
||||
}
|
||||
@ -94,12 +95,7 @@ void Core::RosterHandler::addedAccount(const QString& jid)
|
||||
contact->setName(re.name());
|
||||
|
||||
if (newContact) {
|
||||
QMap<QString, QVariant> cData({
|
||||
{"name", re.name()},
|
||||
{"state", QVariant::fromValue(state)}
|
||||
});
|
||||
|
||||
careAboutAvatar(contact, cData);
|
||||
QMap<QString, QVariant> cData = contact->getInfo();
|
||||
int grCount = 0;
|
||||
for (QSet<QString>::const_iterator itr = gr.begin(), end = gr.end(); itr != end; ++itr) {
|
||||
const QString& groupName = *itr;
|
||||
@ -108,9 +104,9 @@ void Core::RosterHandler::addedAccount(const QString& jid)
|
||||
grCount++;
|
||||
}
|
||||
|
||||
if (grCount == 0) {
|
||||
if (grCount == 0)
|
||||
emit acc->addContact(jid, "", cData);
|
||||
}
|
||||
|
||||
if (acc->pepSupport == Shared::Support::supported) {
|
||||
acc->dm->requestInfo(jid);
|
||||
//acc->dm->requestItems(jid);
|
||||
@ -119,49 +115,22 @@ void Core::RosterHandler::addedAccount(const QString& jid)
|
||||
}
|
||||
}
|
||||
|
||||
void Core::RosterHandler::addNewRoom(const QString& jid, const QString& nick, const QString& roomName, bool autoJoin)
|
||||
{
|
||||
void Core::RosterHandler::addNewRoom(const QString& jid, const QString& nick, const QString& roomName, bool autoJoin) {
|
||||
QXmppMucRoom* room = acc->mm->addRoom(jid);
|
||||
QString lNick = nick;
|
||||
if (lNick.size() == 0) {
|
||||
if (lNick.size() == 0)
|
||||
lNick = acc->getName();
|
||||
}
|
||||
|
||||
Conference* conf = new Conference(jid, acc->getName(), autoJoin, roomName, lNick, room);
|
||||
conferences.insert(std::make_pair(jid, conf));
|
||||
|
||||
handleNewConference(conf);
|
||||
|
||||
QMap<QString, QVariant> cData = {
|
||||
{"autoJoin", conf->getAutoJoin()},
|
||||
{"joined", conf->getJoined()},
|
||||
{"nick", conf->getNick()},
|
||||
{"name", conf->getName()},
|
||||
{"avatars", conf->getAllAvatars()}
|
||||
};
|
||||
careAboutAvatar(conf, cData);
|
||||
QMap<QString, QVariant> cData = conf->getInfo();
|
||||
emit acc->addRoom(jid, cData);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::careAboutAvatar(Core::RosterItem* item, QMap<QString, QVariant>& data)
|
||||
{
|
||||
Archive::AvatarInfo info;
|
||||
bool hasAvatar = item->readAvatarInfo(info);
|
||||
if (hasAvatar) {
|
||||
if (info.autogenerated) {
|
||||
data.insert("avatarState", QVariant::fromValue(Shared::Avatar::autocreated));
|
||||
} else {
|
||||
data.insert("avatarState", QVariant::fromValue(Shared::Avatar::valid));
|
||||
}
|
||||
data.insert("avatarPath", item->avatarPath() + "." + info.type);
|
||||
} else {
|
||||
data.insert("avatarState", QVariant::fromValue(Shared::Avatar::empty));
|
||||
data.insert("avatarPath", "");
|
||||
acc->delay->requestVCard(item->jid);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::RosterHandler::addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups)
|
||||
{
|
||||
void Core::RosterHandler::addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups) {
|
||||
if (acc->state == Shared::ConnectionState::connected) {
|
||||
std::map<QString, QString>::const_iterator itr = queuedContacts.find(jid);
|
||||
if (itr != queuedContacts.end()) {
|
||||
@ -175,8 +144,7 @@ void Core::RosterHandler::addContactRequest(const QString& jid, const QString& n
|
||||
}
|
||||
}
|
||||
|
||||
void Core::RosterHandler::removeContactRequest(const QString& jid)
|
||||
{
|
||||
void Core::RosterHandler::removeContactRequest(const QString& jid) {
|
||||
QString lcJid = jid.toLower();
|
||||
if (acc->state == Shared::ConnectionState::connected) {
|
||||
std::set<QString>::const_iterator itr = outOfRosterContacts.find(lcJid);
|
||||
@ -191,25 +159,23 @@ void Core::RosterHandler::removeContactRequest(const QString& jid)
|
||||
}
|
||||
}
|
||||
|
||||
void Core::RosterHandler::handleNewRosterItem(Core::RosterItem* contact)
|
||||
{
|
||||
void Core::RosterHandler::handleNewRosterItem(Core::RosterItem* contact) {
|
||||
connect(contact, &RosterItem::needHistory, this->acc, &Account::onContactNeedHistory);
|
||||
connect(contact, &RosterItem::historyResponse, this->acc, &Account::onContactHistoryResponse);
|
||||
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);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::handleNewContact(Core::Contact* contact)
|
||||
{
|
||||
void Core::RosterHandler::handleNewContact(Core::Contact* contact) {
|
||||
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)
|
||||
{
|
||||
void Core::RosterHandler::handleNewConference(Core::Conference* contact) {
|
||||
handleNewRosterItem(contact);
|
||||
connect(contact, &Conference::nickChanged, this, &RosterHandler::onMucNickNameChanged);
|
||||
connect(contact, &Conference::subjectChanged, this, &RosterHandler::onMucSubjectChanged);
|
||||
@ -220,34 +186,27 @@ void Core::RosterHandler::handleNewConference(Core::Conference* contact)
|
||||
connect(contact, &Conference::removeParticipant, this, &RosterHandler::onMucRemoveParticipant);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onMucAddParticipant(const QString& nickName, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
void Core::RosterHandler::onMucAddParticipant(const QString& nickName, const QMap<QString, QVariant>& data) {
|
||||
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)
|
||||
{
|
||||
void Core::RosterHandler::onMucChangeParticipant(const QString& nickName, const QMap<QString, QVariant>& data) {
|
||||
Conference* room = static_cast<Conference*>(sender());
|
||||
emit acc->changeRoomParticipant(room->jid, nickName, data);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onMucRemoveParticipant(const QString& nickName)
|
||||
{
|
||||
void Core::RosterHandler::onMucRemoveParticipant(const QString& nickName) {
|
||||
Conference* room = static_cast<Conference*>(sender());
|
||||
emit acc->removeRoomParticipant(room->jid, nickName);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onMucSubjectChanged(const QString& subject)
|
||||
{
|
||||
void Core::RosterHandler::onMucSubjectChanged(const QString& subject) {
|
||||
Conference* room = static_cast<Conference*>(sender());
|
||||
emit acc->changeRoom(room->jid, {
|
||||
{"subject", subject}
|
||||
});
|
||||
emit acc->changeRoom(room->jid, {{"subject", subject}});
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onContactGroupAdded(const QString& group)
|
||||
{
|
||||
void Core::RosterHandler::onContactGroupAdded(const QString& group) {
|
||||
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
|
||||
@ -255,14 +214,14 @@ void Core::RosterHandler::onContactGroupAdded(const QString& group)
|
||||
|
||||
QMap<QString, QVariant> cData({
|
||||
{"name", contact->getName()},
|
||||
{"state", QVariant::fromValue(contact->getSubscriptionState())}
|
||||
{"state", QVariant::fromValue(contact->getSubscriptionState())},
|
||||
{"encryption", contact->isEncryptionEnabled()}
|
||||
});
|
||||
addToGroup(contact->jid, group);
|
||||
emit acc->addContact(contact->jid, group, cData);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onContactGroupRemoved(const QString& group)
|
||||
{
|
||||
void Core::RosterHandler::onContactGroupRemoved(const QString& group) {
|
||||
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
|
||||
@ -272,17 +231,17 @@ void Core::RosterHandler::onContactGroupRemoved(const QString& group)
|
||||
removeFromGroup(contact->jid, group);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onContactNameChanged(const QString& cname)
|
||||
{
|
||||
Contact* contact = static_cast<Contact*>(sender());
|
||||
QMap<QString, QVariant> cData({
|
||||
{"name", cname},
|
||||
});
|
||||
emit acc->changeContact(contact->jid, cData);
|
||||
void Core::RosterHandler::onContactNameChanged(const QString& cname) {
|
||||
RosterItem* contact = static_cast<RosterItem*>(sender());
|
||||
emit acc->changeContact(contact->jid, {{"name", cname}});
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onContactSubscriptionStateChanged(Shared::SubscriptionState cstate)
|
||||
{
|
||||
void Core::RosterHandler::onContactEncryptionChanged(bool value) {
|
||||
RosterItem* contact = static_cast<RosterItem*>(sender());
|
||||
emit acc->changeContact(contact->jid, {{"encryption", value}});
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onContactSubscriptionStateChanged(Shared::SubscriptionState cstate) {
|
||||
Contact* contact = static_cast<Contact*>(sender());
|
||||
QMap<QString, QVariant> cData({
|
||||
{"state", QVariant::fromValue(cstate)},
|
||||
@ -290,8 +249,7 @@ void Core::RosterHandler::onContactSubscriptionStateChanged(Shared::Subscription
|
||||
emit acc->changeContact(contact->jid, cData);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::addToGroup(const QString& jid, const QString& group)
|
||||
{
|
||||
void Core::RosterHandler::addToGroup(const QString& jid, const QString& group) {
|
||||
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;
|
||||
@ -300,8 +258,7 @@ void Core::RosterHandler::addToGroup(const QString& jid, const QString& group)
|
||||
gItr->second.insert(jid.toLower());
|
||||
}
|
||||
|
||||
void Core::RosterHandler::removeFromGroup(const QString& jid, const QString& group)
|
||||
{
|
||||
void Core::RosterHandler::removeFromGroup(const QString& jid, const QString& group) {
|
||||
QSet<QString> toRemove;
|
||||
std::map<QString, std::set<QString>>::iterator itr = groups.find(group);
|
||||
if (itr == groups.end()) {
|
||||
@ -319,24 +276,21 @@ void Core::RosterHandler::removeFromGroup(const QString& jid, const QString& gro
|
||||
}
|
||||
}
|
||||
|
||||
Core::RosterItem * Core::RosterHandler::getRosterItem(const QString& jid)
|
||||
{
|
||||
RosterItem* item = 0;
|
||||
Core::RosterItem * Core::RosterHandler::getRosterItem(const QString& jid) {
|
||||
RosterItem* item = nullptr;
|
||||
QString lcJid = jid.toLower();
|
||||
std::map<QString, Contact*>::const_iterator citr = contacts.find(lcJid);
|
||||
if (citr != contacts.end()) {
|
||||
item = citr->second;
|
||||
} else {
|
||||
std::map<QString, Conference*>::const_iterator coitr = conferences.find(lcJid);
|
||||
if (coitr != conferences.end()) {
|
||||
if (coitr != conferences.end())
|
||||
item = coitr->second;
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
Core::Conference * Core::RosterHandler::getConference(const QString& jid)
|
||||
{
|
||||
Core::Conference * Core::RosterHandler::getConference(const QString& jid) {
|
||||
Conference* item = 0;
|
||||
std::map<QString, Conference*>::const_iterator coitr = conferences.find(jid.toLower());
|
||||
if (coitr != conferences.end()) {
|
||||
@ -345,8 +299,7 @@ Core::Conference * Core::RosterHandler::getConference(const QString& jid)
|
||||
return item;
|
||||
}
|
||||
|
||||
Core::Contact * Core::RosterHandler::getContact(const QString& jid)
|
||||
{
|
||||
Core::Contact * Core::RosterHandler::getContact(const QString& jid) {
|
||||
Contact* item = 0;
|
||||
std::map<QString, Contact*>::const_iterator citr = contacts.find(jid.toLower());
|
||||
if (citr != contacts.end()) {
|
||||
@ -355,22 +308,21 @@ Core::Contact * Core::RosterHandler::getContact(const QString& jid)
|
||||
return item;
|
||||
}
|
||||
|
||||
Core::Contact * Core::RosterHandler::addOutOfRosterContact(const QString& jid)
|
||||
{
|
||||
Core::Contact * Core::RosterHandler::addOutOfRosterContact(const QString& jid) {
|
||||
QString lcJid = jid.toLower();
|
||||
Contact* cnt = new Contact(lcJid, acc->name);
|
||||
contacts.insert(std::make_pair(lcJid, cnt));
|
||||
outOfRosterContacts.insert(lcJid);
|
||||
cnt->setSubscriptionState(Shared::SubscriptionState::unknown);
|
||||
emit acc->addContact(lcJid, "", QMap<QString, QVariant>({
|
||||
{"state", QVariant::fromValue(Shared::SubscriptionState::unknown)}
|
||||
{"state", QVariant::fromValue(Shared::SubscriptionState::unknown)},
|
||||
{"encryption", false}
|
||||
}));
|
||||
handleNewContact(cnt);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onRosterItemChanged(const QString& bareJid)
|
||||
{
|
||||
void Core::RosterHandler::onRosterItemChanged(const QString& bareJid) {
|
||||
QString lcJid = bareJid.toLower();
|
||||
std::map<QString, Contact*>::const_iterator itr = contacts.find(lcJid);
|
||||
if (itr == contacts.end()) {
|
||||
@ -387,8 +339,7 @@ void Core::RosterHandler::onRosterItemChanged(const QString& bareJid)
|
||||
contact->setName(re.name());
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onRosterItemRemoved(const QString& bareJid)
|
||||
{
|
||||
void Core::RosterHandler::onRosterItemRemoved(const QString& bareJid) {
|
||||
QString lcJid = bareJid.toLower();
|
||||
std::map<QString, Contact*>::const_iterator itr = contacts.find(lcJid);
|
||||
if (itr == contacts.end()) {
|
||||
@ -406,14 +357,12 @@ void Core::RosterHandler::onRosterItemRemoved(const QString& bareJid)
|
||||
contact->deleteLater();
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onMucRoomAdded(QXmppMucRoom* room)
|
||||
{
|
||||
void Core::RosterHandler::onMucRoomAdded(QXmppMucRoom* room) {
|
||||
qDebug() << "room" << room->jid() << "added with name" << room->name()
|
||||
<< ", account" << acc->getName() << "joined:" << room->isJoined();
|
||||
}
|
||||
|
||||
void Core::RosterHandler::bookmarksReceived(const QXmppBookmarkSet& bookmarks)
|
||||
{
|
||||
void Core::RosterHandler::bookmarksReceived(const QXmppBookmarkSet& bookmarks) {
|
||||
QList<QXmppBookmarkConference> confs = bookmarks.conferences();
|
||||
for (QList<QXmppBookmarkConference>::const_iterator itr = confs.begin(), end = confs.end(); itr != end; ++itr) {
|
||||
const QXmppBookmarkConference& c = *itr;
|
||||
@ -423,54 +372,42 @@ void Core::RosterHandler::bookmarksReceived(const QXmppBookmarkSet& bookmarks)
|
||||
if (cItr == conferences.end()) {
|
||||
addNewRoom(jid, c.nickName(), c.name(), c.autoJoin());
|
||||
} else {
|
||||
if (c.autoJoin()) {
|
||||
if (c.autoJoin())
|
||||
cItr->second->setJoined(true);
|
||||
} else {
|
||||
else
|
||||
cItr->second->setAutoJoin(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onMucJoinedChanged(bool joined)
|
||||
{
|
||||
void Core::RosterHandler::onMucJoinedChanged(bool joined){
|
||||
Conference* room = static_cast<Conference*>(sender());
|
||||
emit acc->changeRoom(room->jid, {
|
||||
{"joined", joined}
|
||||
});
|
||||
emit acc->changeRoom(room->jid, {{"joined", joined}});
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onMucAutoJoinChanged(bool autoJoin)
|
||||
{
|
||||
void Core::RosterHandler::onMucAutoJoinChanged(bool autoJoin) {
|
||||
storeConferences();
|
||||
Conference* room = static_cast<Conference*>(sender());
|
||||
emit acc->changeRoom(room->jid, {
|
||||
{"autoJoin", autoJoin}
|
||||
});
|
||||
emit acc->changeRoom(room->jid, {{"autoJoin", autoJoin}});
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onMucNickNameChanged(const QString& nickName)
|
||||
{
|
||||
void Core::RosterHandler::onMucNickNameChanged(const QString& nickName){
|
||||
storeConferences();
|
||||
Conference* room = static_cast<Conference*>(sender());
|
||||
emit acc->changeRoom(room->jid, {
|
||||
{"nick", nickName}
|
||||
});
|
||||
emit acc->changeRoom(room->jid, {{"nick", nickName}});
|
||||
}
|
||||
|
||||
Shared::SubscriptionState Core::RosterHandler::castSubscriptionState(QXmppRosterIq::Item::SubscriptionType qs)
|
||||
{
|
||||
Shared::SubscriptionState Core::RosterHandler::castSubscriptionState(QXmppRosterIq::Item::SubscriptionType qs){
|
||||
Shared::SubscriptionState state;
|
||||
if (qs == QXmppRosterIq::Item::NotSet) {
|
||||
if (qs == QXmppRosterIq::Item::NotSet)
|
||||
state = Shared::SubscriptionState::unknown;
|
||||
} else {
|
||||
else
|
||||
state = static_cast<Shared::SubscriptionState>(qs);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void Core::RosterHandler::storeConferences()
|
||||
{
|
||||
void Core::RosterHandler::storeConferences() {
|
||||
QXmppBookmarkSet bms = acc->bm->bookmarks();
|
||||
QList<QXmppBookmarkConference> confs;
|
||||
for (std::map<QString, Conference*>::const_iterator itr = conferences.begin(), end = conferences.end(); itr != end; ++itr) {
|
||||
@ -486,8 +423,7 @@ void Core::RosterHandler::storeConferences()
|
||||
acc->bm->setBookmarks(bms);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::clearConferences()
|
||||
{
|
||||
void Core::RosterHandler::clearConferences() {
|
||||
for (std::map<QString, Conference*>::const_iterator itr = conferences.begin(), end = conferences.end(); itr != end; itr++) {
|
||||
itr->second->deleteLater();
|
||||
emit acc->removeRoom(itr->first);
|
||||
@ -495,8 +431,7 @@ void Core::RosterHandler::clearConferences()
|
||||
conferences.clear();
|
||||
}
|
||||
|
||||
void Core::RosterHandler::removeRoomRequest(const QString& jid)
|
||||
{
|
||||
void Core::RosterHandler::removeRoomRequest(const QString& jid) {
|
||||
QString lcJid = jid.toLower();
|
||||
std::map<QString, Conference*>::const_iterator itr = conferences.find(lcJid);
|
||||
if (itr == conferences.end()) {
|
||||
@ -508,8 +443,7 @@ void Core::RosterHandler::removeRoomRequest(const QString& jid)
|
||||
storeConferences();
|
||||
}
|
||||
|
||||
void Core::RosterHandler::addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin)
|
||||
{
|
||||
void Core::RosterHandler::addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin) {
|
||||
QString lcJid = jid.toLower();
|
||||
std::map<QString, Conference*>::const_iterator cItr = conferences.find(lcJid);
|
||||
if (cItr == conferences.end()) {
|
||||
@ -520,8 +454,7 @@ void Core::RosterHandler::addRoomRequest(const QString& jid, const QString& nick
|
||||
}
|
||||
}
|
||||
|
||||
void Core::RosterHandler::addContactToGroupRequest(const QString& jid, const QString& groupName)
|
||||
{
|
||||
void Core::RosterHandler::addContactToGroupRequest(const QString& jid, const QString& groupName) {
|
||||
QString lcJid = jid.toLower();
|
||||
std::map<QString, Contact*>::const_iterator itr = contacts.find(lcJid);
|
||||
if (itr == contacts.end()) {
|
||||
@ -545,8 +478,7 @@ void Core::RosterHandler::addContactToGroupRequest(const QString& jid, const QSt
|
||||
}
|
||||
}
|
||||
|
||||
void Core::RosterHandler::removeContactFromGroupRequest(const QString& jid, const QString& groupName)
|
||||
{
|
||||
void Core::RosterHandler::removeContactFromGroupRequest(const QString& jid, const QString& groupName) {
|
||||
QString lcJid = jid.toLower();
|
||||
std::map<QString, Contact*>::const_iterator itr = contacts.find(lcJid);
|
||||
if (itr == contacts.end()) {
|
||||
@ -571,19 +503,17 @@ void Core::RosterHandler::removeContactFromGroupRequest(const QString& jid, cons
|
||||
}
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onContactAvatarChanged(Shared::Avatar type, const QString& path)
|
||||
{
|
||||
void Core::RosterHandler::onContactAvatarChanged(Shared::Avatar type, const QString& path) {
|
||||
RosterItem* item = static_cast<RosterItem*>(sender());
|
||||
QMap<QString, QVariant> cData({
|
||||
{"avatarState", static_cast<uint>(type)},
|
||||
{"avatarState", QVariant::fromValue(type)},
|
||||
{"avatarPath", path}
|
||||
});
|
||||
|
||||
emit acc->changeContact(item->jid, cData);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::handleOffline()
|
||||
{
|
||||
void Core::RosterHandler::handleOffline() {
|
||||
for (const std::pair<const QString, Conference*>& pair : conferences) {
|
||||
pair.second->clearArchiveRequests();
|
||||
pair.second->downgradeDatabaseState();
|
||||
@ -595,13 +525,11 @@ void Core::RosterHandler::handleOffline()
|
||||
}
|
||||
|
||||
|
||||
void Core::RosterHandler::onPepSupportedChanged(Shared::Support support)
|
||||
{
|
||||
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) {
|
||||
if (pair.second->getPepSupport() == Shared::Support::unknown)
|
||||
acc->dm->requestInfo(pair.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public:
|
||||
void clearConferences();
|
||||
|
||||
void initialize();
|
||||
void clear();
|
||||
|
||||
private slots:
|
||||
void onRosterReceived();
|
||||
@ -91,6 +92,7 @@ private slots:
|
||||
void onContactNameChanged(const QString& name);
|
||||
void onContactSubscriptionStateChanged(Shared::SubscriptionState state);
|
||||
void onContactAvatarChanged(Shared::Avatar, const QString& path);
|
||||
void onContactEncryptionChanged(bool value);
|
||||
void onPepSupportedChanged(Shared::Support support);
|
||||
|
||||
private:
|
||||
@ -101,7 +103,6 @@ private:
|
||||
void handleNewRosterItem(Core::RosterItem* contact);
|
||||
void handleNewContact(Core::Contact* contact);
|
||||
void handleNewConference(Core::Conference* contact);
|
||||
void careAboutAvatar(Core::RosterItem* item, QMap<QString, QVariant>& data);
|
||||
|
||||
static Shared::SubscriptionState castSubscriptionState(QXmppRosterIq::Item::SubscriptionType qs);
|
||||
|
||||
|
@ -88,7 +88,7 @@ void Core::VCardHandler::onVCardReceived(const QXmppVCardIq& card) {
|
||||
}
|
||||
RosterItem* item = acc->rh->getRosterItem(jid);
|
||||
|
||||
if (item == 0) {
|
||||
if (item == nullptr) {
|
||||
if (jid == acc->getBareJid())
|
||||
onOwnVCardReceived(card);
|
||||
else
|
||||
|