~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to src/contactupdatesmanager.cpp

  • Committer: Package Import Robot
  • Author(s): Jan Niehusmann
  • Date: 2014-07-01 21:49:34 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140701214934-gt4dkgm94byi4vnn
Tags: 0.15-1
* New upstream version
* set debhelper compat level to 9
* set Standards-Version to 3.9.5 (no further changes)
* add lintian override regarding license-problem-non-free-RFC
* use qconf to regenerate configure script
* implement hardening using buildflags instead of hardening-wrapper

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * contactupdatesmanager.cpp
 
3
 * Copyright (C) 2008-2010  Yandex LLC (Michail Pishchagin)
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 *
 
19
 */
 
20
 
 
21
#include "contactupdatesmanager.h"
 
22
 
 
23
#include <QTimer>
 
24
 
 
25
#include "psiaccount.h"
 
26
#include "psicontact.h"
 
27
#include "psicon.h"
 
28
#include "psievent.h"
 
29
#include "userlist.h"
 
30
 
 
31
#ifdef YAPSI_ACTIVEX_SERVER
 
32
#include "yaonline.h"
 
33
#endif
 
34
 
 
35
ContactUpdatesManager::ContactUpdatesManager(PsiCon* parent)
 
36
        : QObject(parent)
 
37
        , controller_(parent)
 
38
{
 
39
        Q_ASSERT(controller_);
 
40
        updateTimer_ = new QTimer(this);
 
41
        updateTimer_->setSingleShot(false);
 
42
        updateTimer_->setInterval(0);
 
43
        connect(updateTimer_, SIGNAL(timeout()), SLOT(update()));
 
44
}
 
45
 
 
46
ContactUpdatesManager::~ContactUpdatesManager()
 
47
{
 
48
}
 
49
 
 
50
void ContactUpdatesManager::contactBlocked(PsiAccount* account, const XMPP::Jid& jid)
 
51
{
 
52
        Q_ASSERT(account);
 
53
        updates_ << ContactUpdateAction(ContactBlocked, account, jid);
 
54
        updateTimer_->start();
 
55
}
 
56
 
 
57
void ContactUpdatesManager::contactDeauthorized(PsiAccount* account, const XMPP::Jid& jid)
 
58
{
 
59
        Q_ASSERT(account);
 
60
        updates_ << ContactUpdateAction(ContactDeauthorized, account, jid);
 
61
        updateTimer_->start();
 
62
}
 
63
 
 
64
void ContactUpdatesManager::contactAuthorized(PsiAccount* account, const XMPP::Jid& jid)
 
65
{
 
66
        Q_ASSERT(account);
 
67
        updates_ << ContactUpdateAction(ContactAuthorized, account, jid);
 
68
        updateTimer_->start();
 
69
}
 
70
 
 
71
void ContactUpdatesManager::contactRemoved(PsiAccount* account, const XMPP::Jid& jid)
 
72
{
 
73
        Q_ASSERT(account);
 
74
        // we must act immediately, since otherwise all corresponding events
 
75
        // will be simply deleted
 
76
        removeAuthRequestEventsFor(account, jid, true);
 
77
        removeToastersFor(account, jid);
 
78
}
 
79
 
 
80
void ContactUpdatesManager::removeAuthRequestEventsFor(PsiAccount* account, const XMPP::Jid& jid, bool denyAuthRequests)
 
81
{
 
82
        Q_ASSERT(account);
 
83
        if (!account || !controller_)
 
84
                return;
 
85
 
 
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);
 
93
                                }
 
94
#ifdef YAPSI_ACTIVEX_SERVER
 
95
                                controller_->yaOnline()->closeNotify(p.first, e);
 
96
#endif
 
97
                                account->eventQueue()->dequeue(e);
 
98
                                e->deleteLater();
 
99
                        }
 
100
                }
 
101
        }
 
102
}
 
103
 
 
104
void ContactUpdatesManager::removeToastersFor(PsiAccount* account, const XMPP::Jid& jid)
 
105
{
 
106
        Q_ASSERT(account);
 
107
        if (!account || !controller_)
 
108
                return;
 
109
 
 
110
        foreach(EventQueue::PsiEventId p, account->eventQueue()->eventsFor(jid, false)) {
 
111
                PsiEvent* e = p.second;
 
112
                if (e->type() == PsiEvent::Message
 
113
#ifdef YAPSI
 
114
                    || e->type() == PsiEvent::Mood
 
115
#endif
 
116
                    )
 
117
                {
 
118
#ifdef YAPSI_ACTIVEX_SERVER
 
119
                        controller_->yaOnline()->closeNotify(p.first, e);
 
120
#endif
 
121
                        account->eventQueue()->dequeue(e);
 
122
                        e->deleteLater();
 
123
                }
 
124
        }
 
125
}
 
126
 
 
127
void ContactUpdatesManager::removeNotInListContacts(PsiAccount* account, const XMPP::Jid& jid)
 
128
{
 
129
        Q_ASSERT(account);
 
130
        if (!account)
 
131
                return;
 
132
 
 
133
        foreach(UserListItem* u, account->findRelevant(jid)) {
 
134
                if (u && !u->inList()) {
 
135
                        account->actionRemove(u->jid());
 
136
                }
 
137
        }
 
138
}
 
139
 
 
140
void ContactUpdatesManager::update()
 
141
{
 
142
        while (!updates_.isEmpty()) {
 
143
                ContactUpdateAction action = updates_.takeFirst();
 
144
                if (!action.account)
 
145
                        continue;
 
146
 
 
147
                if (action.type == ContactBlocked) {
 
148
                        removeAuthRequestEventsFor(action.account, action.jid, true);
 
149
                        removeNotInListContacts(action.account, action.jid);
 
150
                }
 
151
                else if (action.type == ContactAuthorized) {
 
152
                        removeAuthRequestEventsFor(action.account, action.jid, false);
 
153
                }
 
154
                else if (action.type == ContactDeauthorized) {
 
155
                        removeAuthRequestEventsFor(action.account, action.jid, false);
 
156
                        removeNotInListContacts(action.account, action.jid);
 
157
                }
 
158
                else if (action.type == ContactRemoved) {
 
159
                        Q_ASSERT(false);
 
160
                }
 
161
        }
 
162
 
 
163
        if (updates_.isEmpty())
 
164
                updateTimer_->stop();
 
165
        else
 
166
                updateTimer_->start();
 
167
}