adding and removing contacts, rester testing

This commit is contained in:
Blue 2019-06-15 18:29:15 +03:00
parent f0f26ae1a1
commit bb509be29a
16 changed files with 389 additions and 14 deletions

View file

@ -195,11 +195,14 @@ void Core::Account::onRosterItemRemoved(const QString& bareJid)
return;
}
Contact* contact = itr->second;
contacts.erase(itr);
QSet<QString> cGroups = contact->getGroups();
for (QSet<QString>::const_iterator itr = cGroups.begin(), end = cGroups.end(); itr != end; ++itr) {
removeFromGroup(bareJid, *itr);
}
emit removeContact(bareJid);
contact->deleteLater();
}
void Core::Account::addedAccount(const QString& jid)
@ -240,17 +243,22 @@ void Core::Account::addedAccount(const QString& jid)
if (grCount == 0) {
emit addContact(jid, "", cData);
}
QObject::connect(contact, SIGNAL(groupAdded(const QString&)), this, SLOT(onContactGroupAdded(const QString&)));
QObject::connect(contact, SIGNAL(groupRemoved(const QString&)), this, SLOT(onContactGroupRemoved(const QString&)));
QObject::connect(contact, SIGNAL(nameChanged(const QString&)), this, SLOT(onContactNameChanged(const QString&)));
QObject::connect(contact, SIGNAL(subscriptionStateChanged(Shared::SubscriptionState)),
this, SLOT(onContactSubscriptionStateChanged(Shared::SubscriptionState)));
QObject::connect(contact, SIGNAL(needHistory(const QString&, const QString&)), this, SLOT(onContactNeedHistory(const QString&, const QString&)));
QObject::connect(contact, SIGNAL(historyResponse(const std::list<Shared::Message>&)), this, SLOT(onContactHistoryResponse(const std::list<Shared::Message>&)));
handleNewContact(contact);
}
}
void Core::Account::handleNewContact(Core::Contact* contact)
{
QObject::connect(contact, SIGNAL(groupAdded(const QString&)), this, SLOT(onContactGroupAdded(const QString&)));
QObject::connect(contact, SIGNAL(groupRemoved(const QString&)), this, SLOT(onContactGroupRemoved(const QString&)));
QObject::connect(contact, SIGNAL(nameChanged(const QString&)), this, SLOT(onContactNameChanged(const QString&)));
QObject::connect(contact, SIGNAL(subscriptionStateChanged(Shared::SubscriptionState)),
this, SLOT(onContactSubscriptionStateChanged(Shared::SubscriptionState)));
QObject::connect(contact, SIGNAL(needHistory(const QString&, const QString&)), this, SLOT(onContactNeedHistory(const QString&, const QString&)));
QObject::connect(contact, SIGNAL(historyResponse(const std::list<Shared::Message>&)), this, SLOT(onContactHistoryResponse(const std::list<Shared::Message>&)));
}
void Core::Account::onPresenceReceived(const QXmppPresence& presence)
{
QString id = presence.from();
@ -431,8 +439,21 @@ bool Core::Account::handleChatMessage(const QXmppMessage& msg, bool outgoing, bo
const QString& id(msg.id());
Shared::Message sMsg(Shared::Message::chat);
initializeMessage(sMsg, msg, outgoing, forwarded, guessing);
std::map<QString, Contact*>::const_iterator itr = contacts.find(sMsg.getPenPalJid());
itr->second->appendMessageToArchive(sMsg);
QString jid = sMsg.getPenPalJid();
std::map<QString, Contact*>::const_iterator itr = contacts.find(jid);
Contact* cnt;
if (itr != contacts.end()) {
cnt = itr->second;
} else {
cnt = new Contact(jid, name);
contacts.insert(std::make_pair(jid, cnt));
cnt->setSubscriptionState(Shared::unknown);
emit addContact(jid, "", QMap<QString, QVariant>({
{"state", Shared::unknown}
}));
handleNewContact(cnt);
}
cnt->appendMessageToArchive(sMsg);
emit message(sMsg);

View file

@ -107,6 +107,7 @@ private slots:
private:
void addedAccount(const QString &bareJid);
void handleNewContact(Contact* contact);
bool handleChatMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false, bool guessing = false);
void addToGroup(const QString& jid, const QString& group);
void removeFromGroup(const QString& jid, const QString& group);

View file

@ -365,3 +365,14 @@ void Core::Squawk::removeContactRequest(const QString& account, const QString& j
itr->second->removeContactRequest(jid);
}
void Core::Squawk::addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups)
{
AccountsMap::const_iterator itr = amap.find(account);
if (itr == amap.end()) {
qDebug("An attempt to add contact to a non existing account, skipping");
return;
}
itr->second->addContactRequest(jid, name, groups);
}

View file

@ -52,6 +52,7 @@ public slots:
void subscribeContact(const QString& account, const QString& jid, const QString& reason);
void unsubscribeContact(const QString& account, const QString& jid, const QString& reason);
void removeContactRequest(const QString& account, const QString& jid);
void addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups);
private:
typedef std::deque<Account*> Accounts;