No longer honours following status in JSON, instead relies solely on following list.
[larjonas-pumpa.git] / src / qasobjectlist.cpp
blob2f1227123ab2e36070b271fd137101976bd6d9cc
1 /*
2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #include "qasobjectlist.h"
22 #include "qasactor.h"
23 #include "util.h"
25 #include <QDebug>
27 //------------------------------------------------------------------------------
29 QMap<QString, QASObjectList*> QASObjectList::s_objectLists;
30 void QASObjectList::clearCache() { deleteMap<QASObjectList*>(s_objectLists); }
32 //------------------------------------------------------------------------------
34 QASObjectList::QASObjectList(QString url, QObject* parent) :
35 QASAbstractObjectList(QAS_OBJECTLIST, url, parent),
36 m_isReplies(false)
38 #ifdef DEBUG_QAS
39 qDebug() << "new ObjectList" << m_url;
40 #endif
43 //------------------------------------------------------------------------------
45 QASAbstractObject* QASObjectList::getAbstractObject(QVariantMap json,
46 QObject* parent) {
47 if (json["objectType"].toString() == "person")
48 return QASActor::getActor(json, parent);
49 return QASObject::getObject(json, parent);
53 //------------------------------------------------------------------------------
55 QASObjectList* QASObjectList::initObjectList(QString url, QObject* parent) {
56 if (s_objectLists.contains(url))
57 return s_objectLists[url];
59 QASObjectList* ol = new QASObjectList(url, parent);
60 s_objectLists.insert(url, ol);
62 return ol;
65 //------------------------------------------------------------------------------
67 QASObjectList* QASObjectList::getObjectList(QVariantMap json, QObject* parent,
68 int id) {
69 QString url = json["url"].toString();
70 // if (url.isEmpty())
71 // return NULL;
73 QASObjectList* ol = s_objectLists.contains(url) ? s_objectLists[url] :
74 new QASObjectList(url, parent);
75 if (!url.isEmpty())
76 s_objectLists.insert(url, ol);
78 ol->update(json, id & QAS_OLDER);
79 return ol;
82 //------------------------------------------------------------------------------
84 QASObjectList* QASObjectList::getObjectList(QVariantList json, QObject* parent,
85 int id) {
86 QVariantMap jmap;
87 jmap["totalItems"] = json.size();
88 jmap["items"] = json;
90 return getObjectList(jmap, parent, id);
93 //------------------------------------------------------------------------------
95 void QASObjectList::update(QVariantMap json, bool older, bool) {
96 // if (m_isReplies && json.contains("items")) {
97 // m_item_set.clear();
98 // m_items.clear();
99 // }
100 QASAbstractObjectList::update(json, older);
103 //------------------------------------------------------------------------------
105 RecipientList QASObjectList::toRecipientList() const {
106 RecipientList rl;
107 for (size_t i=0; i<size(); ++i)
108 rl.append(at(i));
109 return rl;
112 //------------------------------------------------------------------------------
114 bool QASObjectList::containsYou() const {
115 for (size_t i=0; i<size(); ++i) {
116 QASActor* actor = at(i)->asActor();
117 if (actor && actor->isYou())
118 return true;
120 return false;