mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-09 12:58:43 +01:00
feat(inbox): add mentions api
This commit is contained in:
parent
2b9dfa799b
commit
abadb0587d
@ -0,0 +1,17 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.api.dto
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
|
||||
enum class CommentSortType {
|
||||
@SerialName("Hot")
|
||||
Hot,
|
||||
|
||||
@SerialName("Top")
|
||||
Top,
|
||||
|
||||
@SerialName("New")
|
||||
New,
|
||||
|
||||
@SerialName("Old")
|
||||
Old,
|
||||
}
|
@ -10,3 +10,4 @@ typealias SiteId = Int
|
||||
typealias LocalSiteId = Int
|
||||
typealias LocalUserId = Int
|
||||
typealias CustomEmojiId = Int
|
||||
typealias PersonMentionId = Int
|
||||
|
@ -0,0 +1,10 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.api.dto
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GetPersonMentionsResponse(
|
||||
@SerialName("mentions")
|
||||
val mentions: List<PersonMentionView>,
|
||||
)
|
@ -0,0 +1,13 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.api.dto
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PersonMention(
|
||||
@SerialName("id") val id: PersonMentionId,
|
||||
@SerialName("recipient_id") val recipientId: PersonId,
|
||||
@SerialName("comment_id") val commentId: CommentId,
|
||||
@SerialName("read") val read: Boolean,
|
||||
@SerialName("published") val published: String,
|
||||
)
|
@ -0,0 +1,20 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.api.dto
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PersonMentionView(
|
||||
@SerialName("person_mention") val personMention: PersonMention,
|
||||
@SerialName("comment") val comment: Comment,
|
||||
@SerialName("creator") val creator: Person,
|
||||
@SerialName("post") val post: Post,
|
||||
@SerialName("community") val community: Community,
|
||||
@SerialName("recipient") val recipient: Person,
|
||||
@SerialName("counts") val counts: CommentAggregates,
|
||||
@SerialName("creator_banned_from_community") val creatorBannedFromCommunity: Boolean,
|
||||
@SerialName("subscribed") val subscribed: SubscribedType,
|
||||
@SerialName("saved") val saved: Boolean,
|
||||
@SerialName("creator_blocked") val creatorBlocked: Boolean,
|
||||
@SerialName("my_vote") val myVote: Int? = null,
|
||||
)
|
@ -1,6 +1,7 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.api.service
|
||||
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CommentResponse
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CommentSortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CreateCommentForm
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CreateCommentLikeForm
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.DeleteCommentForm
|
||||
@ -8,7 +9,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.EditCommentForm
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.GetCommentsResponse
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.ListingType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.SaveCommentForm
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.SortType
|
||||
import de.jensklingenberg.ktorfit.Response
|
||||
import de.jensklingenberg.ktorfit.http.Body
|
||||
import de.jensklingenberg.ktorfit.http.GET
|
||||
@ -22,7 +22,7 @@ interface CommentService {
|
||||
suspend fun getAll(
|
||||
@Query("auth") auth: String? = null,
|
||||
@Query("limit") limit: Int? = null,
|
||||
@Query("sort") sort: SortType? = null,
|
||||
@Query("sort") sort: CommentSortType? = null,
|
||||
@Query("post_id") postId: Int? = null,
|
||||
@Query("parent_id") parentId: Int? = null,
|
||||
@Query("page") page: Int? = null,
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.api.service
|
||||
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CommentSortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.GetPersonDetailsResponse
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.SortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.GetPersonMentionsResponse
|
||||
import de.jensklingenberg.ktorfit.Response
|
||||
import de.jensklingenberg.ktorfit.http.GET
|
||||
import de.jensklingenberg.ktorfit.http.Query
|
||||
@ -15,8 +16,17 @@ interface UserService {
|
||||
@Query("person_id") personId: Int? = null,
|
||||
@Query("page") page: Int? = null,
|
||||
@Query("limit") limit: Int? = null,
|
||||
@Query("sort") sort: SortType = SortType.Active,
|
||||
@Query("sort") sort: CommentSortType = CommentSortType.New,
|
||||
@Query("username") username: String? = null,
|
||||
@Query("saved_only") savedOnly: Boolean? = null,
|
||||
): Response<GetPersonDetailsResponse>
|
||||
|
||||
@GET("user/mention")
|
||||
suspend fun getMentions(
|
||||
@Query("auth") auth: String? = null,
|
||||
@Query("page") page: Int? = null,
|
||||
@Query("limit") limit: Int? = null,
|
||||
@Query("sort") sort: CommentSortType = CommentSortType.New,
|
||||
@Query("unread_only") unreadOnly: Boolean? = null,
|
||||
): Response<GetPersonMentionsResponse>
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data
|
||||
|
||||
data class PersonMentionModel(
|
||||
val post: PostModel,
|
||||
val comment: CommentModel,
|
||||
)
|
@ -6,6 +6,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.api.provider.ServiceProvide
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommentModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.ListingType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.SortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.utils.toCommentDto
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.utils.toDto
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.utils.toModel
|
||||
|
||||
@ -30,7 +31,7 @@ class CommentRepository(
|
||||
page = page,
|
||||
limit = limit,
|
||||
type = type.toDto(),
|
||||
sort = sort.toDto(),
|
||||
sort = sort.toCommentDto(),
|
||||
)
|
||||
val dto = response.body()?.comments ?: emptyList()
|
||||
return dto.map { it.toModel() }
|
||||
|
@ -2,10 +2,11 @@ package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository
|
||||
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.provider.ServiceProvider
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommentModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PersonMentionModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.SortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.utils.toDto
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.utils.toCommentDto
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.utils.toHost
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.utils.toModel
|
||||
|
||||
@ -46,7 +47,7 @@ class UserRepository(
|
||||
personId = id,
|
||||
page = page,
|
||||
limit = limit,
|
||||
sort = sort.toDto(),
|
||||
sort = sort.toCommentDto(),
|
||||
savedOnly = savedOnly,
|
||||
)
|
||||
val dto = response.body() ?: return emptyList()
|
||||
@ -65,9 +66,27 @@ class UserRepository(
|
||||
personId = id,
|
||||
page = page,
|
||||
limit = limit,
|
||||
sort = sort.toDto(),
|
||||
sort = sort.toCommentDto(),
|
||||
)
|
||||
val dto = response.body() ?: return emptyList()
|
||||
return dto.comments.map { it.toModel() }
|
||||
}
|
||||
|
||||
suspend fun getMentions(
|
||||
auth: String? = null,
|
||||
page: Int,
|
||||
limit: Int = PostsRepository.DEFAULT_PAGE_SIZE,
|
||||
sort: SortType = SortType.Active,
|
||||
unreadOnly: Boolean = true,
|
||||
): List<PersonMentionModel> {
|
||||
val response = serviceProvider.user.getMentions(
|
||||
auth = auth,
|
||||
limit = limit,
|
||||
sort = sort.toCommentDto(),
|
||||
page = page,
|
||||
unreadOnly = unreadOnly,
|
||||
)
|
||||
val dto = response.body() ?: return emptyList()
|
||||
return dto.mentions.map { it.toModel() }
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.utils
|
||||
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CommentSortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CommentView
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.Community
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CommunityFollowerView
|
||||
@ -8,6 +9,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.ListingType.Local
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.ListingType.Subscribed
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.Person
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.PersonAggregates
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.PersonMentionView
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.PostView
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.SortType.Active
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.SortType.Hot
|
||||
@ -26,6 +28,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.SortType.TopYear
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommentModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.ListingType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PersonMentionModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.SortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
||||
@ -54,6 +57,14 @@ internal fun SortType.toDto() = when (this) {
|
||||
else -> Active
|
||||
}
|
||||
|
||||
internal fun SortType.toCommentDto(): CommentSortType = when (this) {
|
||||
SortType.Hot -> CommentSortType.Hot
|
||||
SortType.New -> CommentSortType.New
|
||||
SortType.Top.Generic -> CommentSortType.Top
|
||||
SortType.Old -> CommentSortType.Old
|
||||
else -> CommentSortType.New
|
||||
}
|
||||
|
||||
internal fun Person.toModel() = UserModel(
|
||||
id = id,
|
||||
name = name,
|
||||
@ -110,6 +121,19 @@ internal fun CommunityFollowerView.toModel() = CommunityModel(
|
||||
host = community.actorId.toHost(),
|
||||
)
|
||||
|
||||
internal fun PersonMentionView.toModel() = PersonMentionModel(
|
||||
post = PostModel(
|
||||
id = post.id,
|
||||
title = post.name,
|
||||
text = post.body.orEmpty(),
|
||||
),
|
||||
comment = CommentModel(
|
||||
id = comment.id,
|
||||
text = comment.content,
|
||||
community = community.toModel(),
|
||||
),
|
||||
)
|
||||
|
||||
internal fun String.toHost(): String = this.replace("https://", "").let {
|
||||
val index = it.indexOf("/")
|
||||
if (index < 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user