1 /*
2 * %kadu copyright begin%
3 * Copyright 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
4 * %kadu copyright end%
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "accounts/account.h"
21 #include "contacts/contact-manager.h"
22
23 #include "otr-op-data.h"
24
25 #include "otr-is-logged-in-service.h"
26
wrapperOtrIsLoggedIn(void * data,const char * accountName,const char * protocol,const char * recipient)27 int OtrIsLoggedInService::wrapperOtrIsLoggedIn(void *data, const char *accountName, const char *protocol, const char *recipient)
28 {
29 Q_UNUSED(accountName);
30 Q_UNUSED(protocol);
31
32 OtrOpData *opData = static_cast<OtrOpData *>(data);
33 if (opData->isLoggedInService())
34 return static_cast<int>(opData->isLoggedInService()->isLoggedIn(opData->contact().contactAccount(), QString::fromUtf8(recipient)));
35 else
36 return static_cast<int>(OtrIsLoggedInService::NotSure);
37 }
38
OtrIsLoggedInService(QObject * parent)39 OtrIsLoggedInService::OtrIsLoggedInService(QObject *parent) :
40 QObject{parent}
41 {
42 }
43
~OtrIsLoggedInService()44 OtrIsLoggedInService::~OtrIsLoggedInService()
45 {
46 }
47
setContactManager(ContactManager * contactManager)48 void OtrIsLoggedInService::setContactManager(ContactManager *contactManager)
49 {
50 m_contactManager = contactManager;
51 }
52
isLoggedIn(const Account & account,const QString & contactId)53 OtrIsLoggedInService::IsLoggedInStatus OtrIsLoggedInService::isLoggedIn(const Account &account, const QString &contactId)
54 {
55 auto contact = m_contactManager->byId(account, contactId, ActionReturnNull);
56
57 if (!contact)
58 return NotSure;
59
60 if (contact.currentStatus().isDisconnected())
61 return NotLoggedIn;
62 else
63 return LoggedIn;
64 }
65
66 #include "moc_otr-is-logged-in-service.cpp"
67