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 "qasactivity.h"
25 //------------------------------------------------------------------------------
27 QMap
<QString
, QASActivity
*> QASActivity::s_activities
;
29 void QASActivity::clearCache() { deleteMap
<QASActivity
*>(s_activities
); }
31 //------------------------------------------------------------------------------
33 QASActivity::QASActivity(QString id
, QObject
* parent
) :
34 QASAbstractObject(QAS_ACTIVITY
, parent
),
42 qDebug() << "new Activity" << m_id
;
46 //------------------------------------------------------------------------------
48 void QASActivity::update(QVariantMap json
) {
50 qDebug() << "updating Activity" << m_id
;
54 updateVar(json
, m_verb
, "verb", ch
);
55 updateVar(json
, m_url
, "url", ch
);
56 updateVar(json
, m_content
, "content", ch
);
58 if (json
.contains("actor")) {
59 m_actor
= QASActor::getActor(json
["actor"].toMap(), parent());
60 //connectSignals(m_actor);
63 if (json
.contains("object")) {
64 m_object
= QASObject::getObject(json
["object"].toMap(), parent(),
65 isLikeVerb(m_verb
) || isShareVerb(m_verb
));
66 //connectSignals(m_object);
67 if (!m_object
->author())
68 m_object
->setAuthor(m_actor
);
69 m_object
->setPostingActivity(this);
72 updateVar(json
, m_published
, "published", ch
);
73 updateVar(json
, m_updated
, "updated", ch
);
74 updateVar(json
, m_generatorName
, "generator", "displayName", ch
);
76 if (m_object
&& m_object
->inReplyTo())
77 m_object
->inReplyTo()->addReply(m_object
);
79 if (isLikeVerb(m_verb
) && m_object
&& m_actor
)
80 m_object
->addLike(m_actor
, !m_verb
.startsWith("un"));
82 if (m_verb
== "share" && m_object
&& m_actor
)
83 m_object
->addShare(m_actor
);
85 if (json
.contains("to"))
86 m_to
= QASObjectList::getObjectList(json
["to"].toList(), parent());
88 if (json
.contains("cc"))
89 m_cc
= QASObjectList::getObjectList(json
["cc"].toList(), parent());
95 //------------------------------------------------------------------------------
97 QASActivity
* QASActivity::getActivity(QVariantMap json
, QObject
* parent
) {
98 QString id
= json
["id"].toString();
103 QASActivity
* act
= s_activities
.contains(id
) ? s_activities
[id
] :
104 new QASActivity(id
, parent
);
105 s_activities
.insert(id
, act
);
111 //------------------------------------------------------------------------------
113 bool QASActivity::hasTo() const {
114 return m_to
&& m_to
->size();
117 //------------------------------------------------------------------------------
119 bool QASActivity::hasCc() const {
120 return m_cc
&& m_cc
->size();
124 //------------------------------------------------------------------------------
126 bool QASActivity::skipNotify() const {
127 return generatorName() == "pumpbridge";