@@ -98,24 +98,24 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
9898
9999 const auto notifies = json.object ().value (" ocs" _L1).toObject ().value (" data" _L1).toArray ();
100100
101- auto *ai = qvariant_cast<AccountState *>(sender ()->property (propertyAccountStateC));
101+ auto accountState = qvariant_cast<AccountState *>(sender ()->property (propertyAccountStateC));
102102
103103 ActivityList list;
104104 ActivityList callList;
105105
106- for (const auto element : notifies) {
107- auto json = element.toObject ();
108- auto a = Activity::fromActivityJson (json, ai ->account ());
106+ for (const auto & element : notifies) {
107+ const auto json = element.toObject ();
108+ auto activity = Activity::fromActivityJson (json, accountState ->account ());
109109
110- a ._type = Activity::NotificationType;
111- a ._id = json.value (" notification_id" _L1).toInteger ();
110+ activity ._type = Activity::NotificationType;
111+ activity ._id = json.value (" notification_id" _L1).toInteger ();
112112
113- if (json.contains (" subjectRichParameters" )) {
113+ if (json.contains (" subjectRichParameters" )) {
114114 const auto richParams = json.value (" subjectRichParameters" _L1).toObject ();
115115 const auto richParamsKeys = richParams.keys ();
116116 for (const auto &key : richParamsKeys) {
117117 const auto parameterJsonObject = richParams.value (key).toObject ();
118- a ._subjectRichParameters .insert (key, QVariant::fromValue (Activity::RichSubjectParameter{
118+ activity ._subjectRichParameters .insert (key, QVariant::fromValue (Activity::RichSubjectParameter{
119119 parameterJsonObject.value (" type" _L1).toString (),
120120 parameterJsonObject.value (" id" _L1).toString (),
121121 parameterJsonObject.value (" name" _L1).toString (),
@@ -126,60 +126,73 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
126126 }
127127
128128 if (json.contains (" shouldNotify" _L1)) {
129- a ._shouldNotify = json.value (" shouldNotify" _L1).toBool (true );
129+ activity ._shouldNotify = json.value (" shouldNotify" _L1).toBool (true );
130130 }
131131
132132 // 2 cases to consider:
133133 // 1. server == 24 & has Talk: object_type is chat/call/room & object_id contains conversationToken/messageId
134134 // 2. server < 24 & has Talk: object_type is chat/call/room & object_id contains _only_ conversationToken
135- if (a ._objectType == " chat" _L1 || a ._objectType == " call" _L1 || a ._objectType == " room" _L1) {
135+ if (activity ._objectType == " chat" _L1 || activity ._objectType == " call" _L1 || activity ._objectType == " room" _L1) {
136136 const auto objectId = json.value (" object_id" _L1).toString ();
137137 const auto objectIdData = objectId.split (u' /' );
138138
139- ActivityLink al ;
140- al ._label = tr (" Reply" );
141- al ._verb = " REPLY" ;
142- al ._primary = true ;
139+ ActivityLink link ;
140+ link ._label = tr (" Reply" );
141+ link ._verb = " REPLY" ;
142+ link ._primary = true ;
143143
144- a ._talkNotificationData .conversationToken = objectIdData.first ();
144+ activity ._talkNotificationData .conversationToken = objectIdData.first ();
145145
146- if (a ._objectType == " chat" && objectIdData.size () > 1 ) {
147- a ._talkNotificationData .messageId = objectIdData.last ();
146+ if (activity ._objectType == " chat" && objectIdData.size () > 1 ) {
147+ activity ._talkNotificationData .messageId = objectIdData.last ();
148148 } else {
149- qCInfo (lcServerNotification) << " Replying directly to Talk conversation" << a._talkNotificationData .conversationToken << " will not be possible because the notification doesn't contain the message ID." ;
149+ qCInfo (lcServerNotification) << " Replying directly to Talk conversation" << activity._talkNotificationData .conversationToken
150+ << " will not be possible because the notification doesn't contain the message ID." ;
150151 }
151152
152- if (a ._subjectRichParameters .contains (" user" _L1)) {
153+ if (activity ._subjectRichParameters .contains (" user" _L1)) {
153154
154155 // callback then it is the primary action
155- if (a ._objectType == " call" _L1) {
156- al ._primary = false ;
156+ if (activity ._objectType == " call" _L1) {
157+ link ._primary = false ;
157158 }
158159
159- a._talkNotificationData .userAvatar = ai->account ()->url ().toString () + QStringLiteral (" /index.php/avatar/" ) + a._subjectRichParameters [" user" _L1].value <Activity::RichSubjectParameter>().id + QStringLiteral (" /128" );
160+ activity._talkNotificationData .userAvatar = accountState->account ()->url ().toString ()
161+ + QStringLiteral (" /index.php/avatar/" )
162+ + activity._subjectRichParameters [" user" _L1].value <Activity::RichSubjectParameter>().id
163+ + QStringLiteral (" /128" );
160164 }
161165
162166 // We want to serve incoming call dialogs to the user for calls that
163- if (a ._objectType == " call" _L1 && a ._dateTime .secsTo (QDateTime::currentDateTime ()) < 120 ) {
164- callList.append (a );
167+ if (activity ._objectType == " call" _L1 && activity ._dateTime .secsTo (QDateTime::currentDateTime ()) < 120 ) {
168+ callList.append (activity );
165169 }
166170
167- a ._links .insert (al ._primary ? 0 : a ._links .size (), al );
171+ activity ._links .insert (link ._primary ? 0 : activity ._links .size (), link );
168172 }
169173
170- QUrl link (json.value (" link" _L1).toString ());
171- if (!link.isEmpty ()) {
172- if (link.host ().isEmpty ()) {
173- link.setScheme (ai->account ()->url ().scheme ());
174- link.setHost (ai->account ()->url ().host ());
174+ // e.g. announcement
175+ if (activity._objectType != " remote_share" _L1 && activity._links .isEmpty ()) {
176+ ActivityLink link;
177+ link._label = tr (" Dismiss" );
178+ link._verb = " DELETE" ;
179+ link._primary = true ;
180+ activity._links .append (link);
181+ }
182+
183+ QUrl url (json.value (" link" _L1).toString ());
184+ if (!url.isEmpty ()) {
185+ if (url.host ().isEmpty ()) {
186+ url.setScheme (accountState->account ()->url ().scheme ());
187+ url.setHost (accountState->account ()->url ().host ());
175188 }
176- if (link .port () == -1 ) {
177- link .setPort (ai ->account ()->url ().port ());
189+ if (url .port () == -1 ) {
190+ url .setPort (accountState ->account ()->url ().port ());
178191 }
179192 }
180- a ._link = link ;
193+ activity ._link = url ;
181194
182- list.append (a );
195+ list.append (activity );
183196 }
184197 emit newNotificationList (list);
185198 emit newIncomingCallsList (callList);
0 commit comments