mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-25 05:45:42 +03:00
Notifications: Propagate "Dismiss" as DELETE to server #5922
This commit is contained in:
parent
3cd8a2be1c
commit
e86416fff7
5 changed files with 19 additions and 5 deletions
|
@ -438,14 +438,13 @@ void ActivityWidget::slotNotifyServerFinished( const QString& reply, int replyCo
|
|||
}
|
||||
|
||||
endNotificationRequest(job->widget(), replyCode);
|
||||
// FIXME: remove the widget after a couple of seconds
|
||||
qDebug() << Q_FUNC_INFO << "Server Notification reply code"<< replyCode << reply;
|
||||
|
||||
// if the notification was successful start a timer that triggers
|
||||
// removal of the done widgets in a few seconds
|
||||
// Add 200 millisecs to the predefined value to make sure that the timer in
|
||||
// widget's method readyToClose() has elapsed.
|
||||
if( replyCode == OCS_SUCCESS_STATUS_CODE ) {
|
||||
if( replyCode == OCS_SUCCESS_STATUS_CODE || replyCode == OCS_SUCCESS_STATUS_CODE_V2 ) {
|
||||
scheduleWidgetToRemove( job->widget() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,8 +125,8 @@ void NotificationWidget::slotNotificationRequestFinished(int statusCode)
|
|||
|
||||
QString timeStr = locale.toString(QTime::currentTime());
|
||||
|
||||
// the ocs API returns stat code 100 if it succeeded.
|
||||
if( statusCode != OCS_SUCCESS_STATUS_CODE ) {
|
||||
// the ocs API returns stat code 100 or 200 inside the xml if it succeeded.
|
||||
if( statusCode != OCS_SUCCESS_STATUS_CODE && statusCode != OCS_SUCCESS_STATUS_CODE_V2 ) {
|
||||
qDebug() << Q_FUNC_INFO << "Notification Request to Server failed, leave button visible.";
|
||||
for( i = 0; i < _buttons.count(); i++ ) {
|
||||
_buttons.at(i)->setEnabled(true);
|
||||
|
|
|
@ -25,6 +25,7 @@ OcsJob::OcsJob(AccountPtr account)
|
|||
: AbstractNetworkJob(account, "")
|
||||
{
|
||||
_passStatusCodes.append(OCS_SUCCESS_STATUS_CODE);
|
||||
_passStatusCodes.append(OCS_SUCCESS_STATUS_CODE_V2);
|
||||
setIgnoreCredentialFailure(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <QUrl>
|
||||
|
||||
#define OCS_SUCCESS_STATUS_CODE 100
|
||||
// Apparantly the v2.php URLs can return that
|
||||
#define OCS_SUCCESS_STATUS_CODE_V2 200
|
||||
|
||||
namespace OCC {
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
namespace OCC
|
||||
{
|
||||
|
||||
const QString notificationsPath = QLatin1String("ocs/v2.php/apps/notifications/api/v1/notifications");
|
||||
|
||||
ServerNotificationHandler::ServerNotificationHandler(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
@ -47,7 +49,7 @@ void ServerNotificationHandler::slotFetchNotifications(AccountState *ptr)
|
|||
}
|
||||
|
||||
// if the previous notification job has finished, start next.
|
||||
_notificationJob = new JsonApiJob( ptr->account(), QLatin1String("ocs/v2.php/apps/notifications/api/v1/notifications"), this );
|
||||
_notificationJob = new JsonApiJob( ptr->account(), notificationsPath, this );
|
||||
QObject::connect(_notificationJob.data(), SIGNAL(jsonReceived(QVariantMap, int)),
|
||||
this, SLOT(slotNotificationsReceived(QVariantMap, int)));
|
||||
_notificationJob->setProperty("AccountStatePtr", QVariant::fromValue<AccountState*>(ptr));
|
||||
|
@ -94,6 +96,16 @@ void ServerNotificationHandler::slotNotificationsReceived(const QVariantMap& jso
|
|||
|
||||
a._links.append(al);
|
||||
}
|
||||
|
||||
// Add another action to dismiss notification on server
|
||||
// https://github.com/owncloud/notifications/blob/master/docs/ocs-endpoint-v1.md#deleting-a-notification-for-a-user
|
||||
ActivityLink al;
|
||||
al._label = tr("Dismiss");
|
||||
al._link = Utility::concatUrlPath(ai->account()->url(), notificationsPath + "/" + json.value("notification_id").toString()).toString();
|
||||
al._verb = "DELETE";
|
||||
al._isPrimary = false;
|
||||
a._links.append(al);
|
||||
|
||||
list.append(a);
|
||||
}
|
||||
emit newNotificationList( list );
|
||||
|
|
Loading…
Reference in a new issue