feat: anilist notifications
This commit is contained in:
parent
e2eae6250b
commit
7ac679f927
15 changed files with 572 additions and 28 deletions
|
@ -28,6 +28,7 @@ object Anilist {
|
|||
var bg: String? = null
|
||||
var episodesWatched: Int? = null
|
||||
var chapterRead: Int? = null
|
||||
var unreadNotificationCount: Int = 0
|
||||
|
||||
var genres: ArrayList<String>? = null
|
||||
var tags: Map<Boolean, List<String>>? = null
|
||||
|
|
|
@ -7,6 +7,8 @@ import ani.dantotsu.checkId
|
|||
import ani.dantotsu.connections.anilist.Anilist.authorRoles
|
||||
import ani.dantotsu.connections.anilist.Anilist.executeQuery
|
||||
import ani.dantotsu.connections.anilist.api.FuzzyDate
|
||||
import ani.dantotsu.connections.anilist.api.Notification
|
||||
import ani.dantotsu.connections.anilist.api.NotificationResponse
|
||||
import ani.dantotsu.connections.anilist.api.Page
|
||||
import ani.dantotsu.connections.anilist.api.Query
|
||||
import ani.dantotsu.currContext
|
||||
|
@ -36,7 +38,7 @@ class AnilistQueries {
|
|||
val response: Query.Viewer?
|
||||
measureTimeMillis {
|
||||
response =
|
||||
executeQuery("""{Viewer{name options{displayAdultContent}avatar{medium}bannerImage id mediaListOptions{rowOrder animeList{sectionOrder customLists}mangaList{sectionOrder customLists}}statistics{anime{episodesWatched}manga{chaptersRead}}}}""")
|
||||
executeQuery("""{Viewer{name options{displayAdultContent}avatar{medium}bannerImage id mediaListOptions{rowOrder animeList{sectionOrder customLists}mangaList{sectionOrder customLists}}statistics{anime{episodesWatched}manga{chaptersRead}}unreadNotificationCount}}""")
|
||||
}.also { println("time : $it") }
|
||||
val user = response?.data?.user ?: return false
|
||||
|
||||
|
@ -49,6 +51,7 @@ class AnilistQueries {
|
|||
Anilist.episodesWatched = user.statistics?.anime?.episodesWatched
|
||||
Anilist.chapterRead = user.statistics?.manga?.chaptersRead
|
||||
Anilist.adult = user.options?.displayAdultContent ?: false
|
||||
Anilist.unreadNotificationCount = user.unreadNotificationCount?:0
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -1337,4 +1340,12 @@ Page(page:$page,perPage:50) {
|
|||
default[1] = userBannerImage("MANGA",id)
|
||||
return default
|
||||
}
|
||||
|
||||
suspend fun getNotifications(id: Int): NotificationResponse? {
|
||||
val res = executeQuery<NotificationResponse>("""{User(id:$id){unreadNotificationCount}Page{notifications(resetNotificationCount:true){__typename...on AiringNotification{id,type,animeId,episode,contexts,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}},}...on FollowingNotification{id,userId,type,context,createdAt,user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityMessageNotification{id,userId,type,activityId,context,createdAt,message{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityMentionNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplyNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplySubscribedNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityLikeNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplyLikeNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentMentionNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentReplyNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentSubscribedNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentLikeNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadLikeNotification{id,userId,type,threadId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on RelatedMediaAdditionNotification{id,type,context,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaDataChangeNotification{id,type,mediaId,context,reason,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaMergeNotification{id,type,mediaId,deletedMediaTitles,context,reason,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaDeletionNotification{id,type,deletedMediaTitle,context,reason,createdAt,}}}}""", force = true)
|
||||
if (res != null) {
|
||||
Anilist.unreadNotificationCount = 0
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package ani.dantotsu.connections.anilist.api
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
enum class NotificationType(val value: String) {
|
||||
ACTIVITY_MESSAGE("ACTIVITY_MESSAGE"),
|
||||
ACTIVITY_REPLY("ACTIVITY_REPLY"),
|
||||
FOLLOWING("FOLLOWING"),
|
||||
ACTIVITY_MENTION("ACTIVITY_MENTION"),
|
||||
THREAD_COMMENT_MENTION("THREAD_COMMENT_MENTION"),
|
||||
THREAD_SUBSCRIBED("THREAD_SUBSCRIBED"),
|
||||
THREAD_COMMENT_REPLY("THREAD_COMMENT_REPLY"),
|
||||
AIRING("AIRING"),
|
||||
ACTIVITY_LIKE("ACTIVITY_LIKE"),
|
||||
ACTIVITY_REPLY_LIKE("ACTIVITY_REPLY_LIKE"),
|
||||
THREAD_LIKE("THREAD_LIKE"),
|
||||
THREAD_COMMENT_LIKE("THREAD_COMMENT_LIKE"),
|
||||
ACTIVITY_REPLY_SUBSCRIBED("ACTIVITY_REPLY_SUBSCRIBED"),
|
||||
RELATED_MEDIA_ADDITION("RELATED_MEDIA_ADDITION"),
|
||||
MEDIA_DATA_CHANGE("MEDIA_DATA_CHANGE"),
|
||||
MEDIA_MERGE("MEDIA_MERGE"),
|
||||
MEDIA_DELETION("MEDIA_DELETION")
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class NotificationResponse(
|
||||
@SerialName("data")
|
||||
val data: Data,
|
||||
) : java.io.Serializable {
|
||||
@Serializable
|
||||
data class Data(
|
||||
@SerialName("User")
|
||||
val user: NotificationUser,
|
||||
@SerialName("Page")
|
||||
val page: NotificationPage,
|
||||
) : java.io.Serializable
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class NotificationUser(
|
||||
@SerialName("unreadNotificationCount")
|
||||
val unreadNotificationCount: Int,
|
||||
) : java.io.Serializable
|
||||
|
||||
@Serializable
|
||||
data class NotificationPage(
|
||||
@SerialName("notifications")
|
||||
val notifications: List<Notification>,
|
||||
) : java.io.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Notification(
|
||||
@SerialName("__typename")
|
||||
val typename: String,
|
||||
@SerialName("id")
|
||||
val id: Int,
|
||||
@SerialName("userId")
|
||||
val userId: Int?,
|
||||
@SerialName("CommentId")
|
||||
val commentId: Int?,
|
||||
@SerialName("type")
|
||||
val notificationType: String,
|
||||
@SerialName("activityId")
|
||||
val activityId: Int?,
|
||||
@SerialName("animeId")
|
||||
val mediaId: Int?,
|
||||
@SerialName("episode")
|
||||
val episode: Int?,
|
||||
@SerialName("contexts")
|
||||
val contexts: List<String>?,
|
||||
@SerialName("context")
|
||||
val context: String?,
|
||||
@SerialName("reason")
|
||||
val reason: String?,
|
||||
@SerialName("deletedMediaTitle")
|
||||
val deletedMediaTitle: String?,
|
||||
@SerialName("deletedMediaTitles")
|
||||
val deletedMediaTitles: List<String>?,
|
||||
@SerialName("createdAt")
|
||||
val createdAt: Int,
|
||||
@SerialName("media")
|
||||
val media: ani.dantotsu.connections.anilist.api.Media?,
|
||||
@SerialName("user")
|
||||
val user: ani.dantotsu.connections.anilist.api.User?,
|
||||
@SerialName("message")
|
||||
val message: MessageActivity?,
|
||||
@SerialName("activity")
|
||||
val activity: ActivityUnion?,
|
||||
@SerialName("Thread")
|
||||
val thread: Thread?,
|
||||
@SerialName("comment")
|
||||
val comment: ThreadComment?,
|
||||
) : java.io.Serializable
|
||||
|
||||
@Serializable
|
||||
data class MessageActivity(
|
||||
@SerialName("id")
|
||||
val id: Int?,
|
||||
) : java.io.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ActivityUnion(
|
||||
@SerialName("id")
|
||||
val id: Int?,
|
||||
) : java.io.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Thread(
|
||||
@SerialName("id")
|
||||
val id: Int?,
|
||||
) : java.io.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ThreadComment(
|
||||
@SerialName("id")
|
||||
val id: Int?,
|
||||
) : java.io.Serializable
|
|
@ -46,7 +46,7 @@ data class User(
|
|||
@SerialName("statistics") var statistics: UserStatisticTypes?,
|
||||
|
||||
// The number of unread notifications the user has
|
||||
// @SerialName("unreadNotificationCount") var unreadNotificationCount: Int?,
|
||||
@SerialName("unreadNotificationCount") var unreadNotificationCount: Int?,
|
||||
|
||||
// The url for the user page on the AniList website
|
||||
// @SerialName("siteUrl") var siteUrl: String?,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue