diff --git a/saoriaccount.cpp b/saoriaccount.cpp index 4d2a7f2..80b77ad 100644 --- a/saoriaccount.cpp +++ b/saoriaccount.cpp @@ -154,3 +154,37 @@ }); return; } + +void SaoriAccount::reblogStatus(qlonglong id, bool state) +{ + QNetworkRequest request = createHearder(); + QString u = m_instance->instance().url(); + if (state) u += QString(SAORI_MASTODON_APIPATH_STATUS_REBLOG).arg(QString::number(id)); + else u += QString(SAORI_MASTODON_APIPATH_STATUS_UNREBLOG).arg(QString::number(id)); + request.setUrl(u); + auto *reply = SaoriApplication::saori()->manager->post(request,QByteArray()); + connect(reply,&QNetworkReply::finished,[=](){ + if (reply->error() == QNetworkReply::NoError) { + emit updateStatus(id); + } + reply->deleteLater(); + }); + return; +} + +void SaoriAccount::favouriteStatus(qlonglong id, bool state) +{ + QNetworkRequest request = createHearder(); + QString u = m_instance->instance().url(); + if (state) u += QString(SAORI_MASTODON_APIPATH_STATUS_FAVOURITE).arg(QString::number(id)); + else u += QString(SAORI_MASTODON_APIPATH_STATUS_UNFAVOURITE).arg(QString::number(id)); + request.setUrl(u); + auto *reply = SaoriApplication::saori()->manager->post(request,QByteArray()); + connect(reply,&QNetworkReply::finished,[=](){ + if (reply->error() == QNetworkReply::NoError) { + emit updateStatus(id); + } + reply->deleteLater(); + }); + return; +} diff --git a/saoriaccount.h b/saoriaccount.h index be22af7..4079e53 100644 --- a/saoriaccount.h +++ b/saoriaccount.h @@ -55,6 +55,8 @@ void getTimelineData(const QString timeline,const QUrlQuery query); void postNewStatus(const QString timeline,const QString data); void getRelationship(qlonglong id); + void reblogStatus(qlonglong id,bool state); + void favouriteStatus(qlonglong id,bool state); protected: void getAccountInfomation(); @@ -71,6 +73,7 @@ void accountInfomationChanged(); void apiData(const QString timeline,const QByteArray data,const QByteArray link); void posted(const QString timeline,int result); + void updateStatus(qlonglong id); void relationship(qlonglong id,QJsonObject relationship); public slots: diff --git a/saoridef.h b/saoridef.h index f0f9e12..d810c7b 100644 --- a/saoridef.h +++ b/saoridef.h @@ -46,6 +46,10 @@ #define SAORI_MASTODON_APIPATH_FAVOURITES "/api/v1/favourites" #define SAORI_MASTODON_APIPATH_NOTIFICATION "/api/v1/notifications" #define SAORI_MASTODON_APIPATH_POST "/api/v1/statuses" +#define SAORI_MASTODON_APIPATH_STATUS_FAVOURITE "/api/v1/statuses/%1/favourite" +#define SAORI_MASTODON_APIPATH_STATUS_UNFAVOURITE "/api/v1/statuses/%1/unfavourite" +#define SAORI_MASTODON_APIPATH_STATUS_REBLOG "/api/v1/statuses/%1/reblog" +#define SAORI_MASTODON_APIPATH_STATUS_UNREBLOG "/api/v1/statuses/%1/unreblog" #define SAORI_SETTING_GETLIMIT "application/getlimit" #define SAORI_SETTING_GETLIMIT_DEFAULT 10 diff --git a/saoriview.cpp b/saoriview.cpp index e5a0153..d03b700 100644 --- a/saoriview.cpp +++ b/saoriview.cpp @@ -289,15 +289,21 @@ visibility + " " + htmlAnc("reply:" + json["id"].toString(), htmlImg("icon",SAORI_ICONS_RELPY)) + " " + - htmlAnc("boost:" + json["id"].toString(), - json["reblogged"].toBool() ? - htmlImg("icon",SAORI_ICONS_BOOSTED) : - htmlImg("icon",SAORI_ICONS_BOOST)) + + ( + json["reblogged"].toBool() ? + htmlAnc("unreblog:" + json["id"].toString(), + htmlImg("icon",SAORI_ICONS_BOOSTED)) : + htmlAnc("reblog:" + json["id"].toString(), + htmlImg("icon",SAORI_ICONS_BOOST)) + ) + QString::number(json["reblogs_count"].toInt()) + - htmlAnc("fav:" + json["id"].toString(), - json["favourited"].toBool() ? - htmlImg("icon",SAORI_ICONS_FAVOURITED) : - htmlImg("icon",SAORI_ICONS_FAVOURITE)) + + ( + json["favourited"].toBool() ? + htmlAnc("unfav:" + json["id"].toString(), + htmlImg("icon",SAORI_ICONS_FAVOURITED)) : + htmlAnc("fav:" + json["id"].toString(), + htmlImg("icon",SAORI_ICONS_FAVOURITE)) + ) + QString::number(json["favourites_count"].toInt()) ); } @@ -547,11 +553,35 @@ if (url.toString().left(6) == "media:") { QUrl u(url.toString().mid(6)); emit openMediaView(u); + return; } if (url.toString().left(9) == "accounts:") { QStringList v; v << m_account << url.toString(); emit openAccountView(v); + return; + } + + auto account = SaoriApplication::saori()->findAccount(m_account); + if (url.toString().left(7) == "reblog:") { + qlonglong id = url.toString().split(':').at(1).toLongLong(); + if (account) account->reblogStatus(id,true); + return; + } + if (url.toString().left(9) == "unreblog:") { + qlonglong id = url.toString().split(':').at(1).toLongLong(); + if (account) account->reblogStatus(id,false); + return; + } + if (url.toString().left(4) == "fav:") { + qlonglong id = url.toString().split(':').at(1).toLongLong(); + if (account) account->favouriteStatus(id,true); + return; + } + if (url.toString().left(6) == "unfav:") { + qlonglong id = url.toString().split(':').at(1).toLongLong(); + if (account) account->favouriteStatus(id,false); + return; } }