Notification policy (#4768)

This was so much work wow. I think it works pretty well and is the best
compromise between all the alternative we considered. Yes the
pull-to-refreh on the notifications works slightly different now when
the new bar is visible, but I don't think there is a way around that.

Things I plan to do later, i.e. not as part of this PR or release:
- Cache the notification policy summary for better offline behavior and
less view shifting when it loads
- try to reduce some of the code duplications that are now in there
- if there is user demand, add a "legacy mode" setting where this
feature is disabled even if the server would support it

closes #4331
closes #4550 as won't do
closes #4712 as won't do

<img
src="https://github.com/user-attachments/assets/de322d3c-3775-41e7-be57-28ab7fbaecdf"
width="240"/> <img
src="https://github.com/user-attachments/assets/1ce958a4-4f15-484c-a337-5ad93f36046c"
width="240"/> <img
src="https://github.com/user-attachments/assets/98b0482b-1c05-4c99-a371-f7f4d8a69abd"
width="240"/>
This commit is contained in:
Konrad Pozniak 2024-12-03 18:46:50 +01:00 committed by GitHub
commit cd57352cbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 2401 additions and 97 deletions

View file

@ -36,6 +36,8 @@ import com.keylesspalace.tusky.entity.MastoList
import com.keylesspalace.tusky.entity.MediaUploadResult
import com.keylesspalace.tusky.entity.NewStatus
import com.keylesspalace.tusky.entity.Notification
import com.keylesspalace.tusky.entity.NotificationPolicy
import com.keylesspalace.tusky.entity.NotificationRequest
import com.keylesspalace.tusky.entity.NotificationSubscribeResult
import com.keylesspalace.tusky.entity.Poll
import com.keylesspalace.tusky.entity.Relationship
@ -150,7 +152,9 @@ interface MastodonApi {
/** Maximum number of results to return. Defaults to 15, max is 30 */
@Query("limit") limit: Int? = null,
/** Types to excludes from the results */
@Query("exclude_types[]") excludes: Set<Notification.Type>? = null
@Query("exclude_types[]") excludes: Set<Notification.Type>? = null,
/** Return only notifications received from the specified account. */
@Query("account_id") accountId: String? = null
): Response<List<Notification>>
/** Fetch a single notification */
@ -722,4 +726,31 @@ interface MastodonApi {
@Path("id") statusId: String,
@Field("lang") targetLanguage: String?
): NetworkResult<Translation>
@GET("api/v2/notifications/policy")
suspend fun notificationPolicy(): NetworkResult<NotificationPolicy>
@FormUrlEncoded
@PATCH("api/v2/notifications/policy")
suspend fun updateNotificationPolicy(
@Field("for_not_following") forNotFollowing: String?,
@Field("for_not_followers") forNotFollowers: String?,
@Field("for_new_accounts") forNewAccounts: String?,
@Field("for_private_mentions") forPrivateMentions: String?,
@Field("for_limited_accounts") forLimitedAccounts: String?
): NetworkResult<NotificationPolicy>
@GET("api/v1/notifications/requests")
suspend fun getNotificationRequests(
@Query("max_id") maxId: String? = null,
@Query("min_id") minId: String? = null,
@Query("since_id") sinceId: String? = null,
@Query("limit") limit: Int? = null
): Response<List<NotificationRequest>>
@POST("api/v1/notifications/requests/{id}/accept")
suspend fun acceptNotificationRequest(@Path("id") notificationId: String): NetworkResult<Unit>
@POST("api/v1/notifications/requests/{id}/dismiss")
suspend fun dismissNotificationRequest(@Path("id") notificationId: String): NetworkResult<Unit>
}