2
* contactupdatesmanager.cpp
3
* Copyright (C) 2008-2010 Yandex LLC (Michail Pishchagin)
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "contactupdatesmanager.h"
25
#include "psiaccount.h"
26
#include "psicontact.h"
31
#ifdef YAPSI_ACTIVEX_SERVER
35
ContactUpdatesManager::ContactUpdatesManager(PsiCon* parent)
39
Q_ASSERT(controller_);
40
updateTimer_ = new QTimer(this);
41
updateTimer_->setSingleShot(false);
42
updateTimer_->setInterval(0);
43
connect(updateTimer_, SIGNAL(timeout()), SLOT(update()));
46
ContactUpdatesManager::~ContactUpdatesManager()
50
void ContactUpdatesManager::contactBlocked(PsiAccount* account, const XMPP::Jid& jid)
53
updates_ << ContactUpdateAction(ContactBlocked, account, jid);
54
updateTimer_->start();
57
void ContactUpdatesManager::contactDeauthorized(PsiAccount* account, const XMPP::Jid& jid)
60
updates_ << ContactUpdateAction(ContactDeauthorized, account, jid);
61
updateTimer_->start();
64
void ContactUpdatesManager::contactAuthorized(PsiAccount* account, const XMPP::Jid& jid)
67
updates_ << ContactUpdateAction(ContactAuthorized, account, jid);
68
updateTimer_->start();
71
void ContactUpdatesManager::contactRemoved(PsiAccount* account, const XMPP::Jid& jid)
74
// we must act immediately, since otherwise all corresponding events
75
// will be simply deleted
76
removeAuthRequestEventsFor(account, jid, true);
77
removeToastersFor(account, jid);
80
void ContactUpdatesManager::removeAuthRequestEventsFor(PsiAccount* account, const XMPP::Jid& jid, bool denyAuthRequests)
83
if (!account || !controller_)
86
foreach(EventQueue::PsiEventId p, account->eventQueue()->eventsFor(jid, false)) {
87
PsiEvent* e = p.second;
88
if (e->type() == PsiEvent::Auth) {
89
AuthEvent* authEvent = static_cast<AuthEvent*>(e);
90
if (authEvent->authType() == "subscribe") {
91
if (denyAuthRequests) {
92
account->dj_deny(jid);
94
#ifdef YAPSI_ACTIVEX_SERVER
95
controller_->yaOnline()->closeNotify(p.first, e);
97
account->eventQueue()->dequeue(e);
104
void ContactUpdatesManager::removeToastersFor(PsiAccount* account, const XMPP::Jid& jid)
107
if (!account || !controller_)
110
foreach(EventQueue::PsiEventId p, account->eventQueue()->eventsFor(jid, false)) {
111
PsiEvent* e = p.second;
112
if (e->type() == PsiEvent::Message
114
|| e->type() == PsiEvent::Mood
118
#ifdef YAPSI_ACTIVEX_SERVER
119
controller_->yaOnline()->closeNotify(p.first, e);
121
account->eventQueue()->dequeue(e);
127
void ContactUpdatesManager::removeNotInListContacts(PsiAccount* account, const XMPP::Jid& jid)
133
foreach(UserListItem* u, account->findRelevant(jid)) {
134
if (u && !u->inList()) {
135
account->actionRemove(u->jid());
140
void ContactUpdatesManager::update()
142
while (!updates_.isEmpty()) {
143
ContactUpdateAction action = updates_.takeFirst();
147
if (action.type == ContactBlocked) {
148
removeAuthRequestEventsFor(action.account, action.jid, true);
149
removeNotInListContacts(action.account, action.jid);
151
else if (action.type == ContactAuthorized) {
152
removeAuthRequestEventsFor(action.account, action.jid, false);
154
else if (action.type == ContactDeauthorized) {
155
removeAuthRequestEventsFor(action.account, action.jid, false);
156
removeNotInListContacts(action.account, action.jid);
158
else if (action.type == ContactRemoved) {
163
if (updates_.isEmpty())
164
updateTimer_->stop();
166
updateTimer_->start();