Skip to content

Commit

Permalink
Add support for lemmy 0.19.3 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV-GH authored Jan 23, 2024
1 parent a9a44fb commit c0193b3
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,5 @@ suspend fun downloadTypes(
}

suspend fun main() {
downloadTypes("0.19.0", "v0x19")
downloadTypes("0.19.2-alpha.3", "v0x19")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import io.github.z4kn4fein.semver.withoutSuffixes
/**
* Use these flags to check if a certain feature is available on this version of Lemmy.
*/
@Suppress("unused")
class FeatureFlags(val version: Version) {
private val v0x19Plus = version.withoutSuffixes() >= "0.19.0".toVersion()
private val v0x19x2Plus = version.withoutSuffixes() >= "0.19.2".toVersion()

/**
* InstanceBlock Feature added in 0.19
Expand Down Expand Up @@ -39,4 +41,9 @@ class FeatureFlags(val version: Version) {
* Logout, invalidate current token Feature added in 0.19
*/
fun logout(): Boolean = v0x19Plus

/**
* List comment/post votes, feature added in 0.19.2
*/
fun listAdminVotes(): Boolean = v0x19x2Plus
}
4 changes: 2 additions & 2 deletions app/src/commonMain/kotlin/it/vercruysse/lemmyapi/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ val baseClient: HttpClient =

install(HttpTimeout) {
requestTimeoutMillis = TIMEOUT_MS
socketTimeoutMillis = TIMEOUT_MS / 2
connectTimeoutMillis = TIMEOUT_MS / 2
socketTimeoutMillis = TIMEOUT_MS
connectTimeoutMillis = TIMEOUT_MS
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ import it.vercruysse.lemmyapi.v0x19.datatypes.GetSiteResponse
import it.vercruysse.lemmyapi.v0x19.datatypes.GetUnreadCountResponse
import it.vercruysse.lemmyapi.v0x19.datatypes.GetUnreadRegistrationApplicationCountResponse
import it.vercruysse.lemmyapi.v0x19.datatypes.HideCommunity
import it.vercruysse.lemmyapi.v0x19.datatypes.ListCommentLikes
import it.vercruysse.lemmyapi.v0x19.datatypes.ListCommentLikesResponse
import it.vercruysse.lemmyapi.v0x19.datatypes.ListCommentReports
import it.vercruysse.lemmyapi.v0x19.datatypes.ListCommentReportsResponse
import it.vercruysse.lemmyapi.v0x19.datatypes.ListCommunities
import it.vercruysse.lemmyapi.v0x19.datatypes.ListCommunitiesResponse
import it.vercruysse.lemmyapi.v0x19.datatypes.ListPostLikes
import it.vercruysse.lemmyapi.v0x19.datatypes.ListPostLikesResponse
import it.vercruysse.lemmyapi.v0x19.datatypes.ListPostReports
import it.vercruysse.lemmyapi.v0x19.datatypes.ListPostReportsResponse
import it.vercruysse.lemmyapi.v0x19.datatypes.ListPrivateMessageReports
Expand Down Expand Up @@ -925,4 +929,22 @@ class LemmyV0x19Wrapper(
override suspend fun logout(): Result<Unit> {
notSupported()
}

/**
* List a post's likes. Admin-only.
*
* @GET("post/like/list")
*/
override suspend fun listPostLikes(form: ListPostLikes): Result<ListPostLikesResponse> {
notSupported()
}

/**
* List a comment's likes. Admin-only.
*
* @GET("comment/like/list")
*/
override suspend fun listCommentLikes(form: ListCommentLikes): Result<ListCommentLikesResponse> {
notSupported()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ internal class Transformer(var auth: String) : DatatypesMapper {
users_active_week = d.users_active_week,
users_active_month = d.users_active_month,
users_active_half_year = d.users_active_half_year,
subscribers_local = null,
)

override fun toV0x19(d: V0x18DatatypesCommunityBlockView): V0x19DatatypesCommunityBlockView =
Expand Down
14 changes: 14 additions & 0 deletions app/src/commonMain/kotlin/it/vercruysse/lemmyapi/v0x19/LemmyApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,18 @@ abstract class LemmyApi(
* @POST("user/logout")
*/
abstract suspend fun logout(): Result<Unit>

/**
* List a post's likes. Admin-only.
*
* @GET("post/like/list")
*/
abstract suspend fun listPostLikes(form: ListPostLikes): Result<ListPostLikesResponse>

/**
* List a comment's likes. Admin-only.
*
* @GET("comment/like/list")
*/
abstract suspend fun listCommentLikes(form: ListCommentLikes): Result<ListCommentLikesResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,22 @@ class LemmyApiService(
* @POST("user/logout")
*/
override suspend fun logout(): Result<Unit> = ktor.postResult("user/logout")

/**
* List a post's likes. Admin-only.
*
* @GET("post/like/list")
*/
override suspend fun listPostLikes(form: ListPostLikes): Result<ListPostLikesResponse> =
ktor.getResult("post/like/list", form)

/**
* List a comment's likes. Admin-only.
*
* @GET("comment/like/list")
*/
override suspend fun listCommentLikes(form: ListCommentLikes): Result<ListCommentLikesResponse> =
ktor.getResult("comment/like/list", form)
}

suspend fun main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ data class CommunityAggregates(
val users_active_week: Int,
val users_active_month: Int,
val users_active_half_year: Int,
val subscribers_local: Int?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ data class CreateCommunity(
val nsfw: Boolean? = null,
val posting_restricted_to_mods: Boolean? = null,
val discussion_languages: List<LanguageId>? = null,
val local_only: Boolean? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ data class EditCommunity(
val nsfw: Boolean? = null,
val posting_restricted_to_mods: Boolean? = null,
val discussion_languages: List<LanguageId>? = null,
val local_only: Boolean? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package it.vercruysse.lemmyapi.v0x19.datatypes

import kotlinx.serialization.Serializable

@Serializable
data class ListCommentLikes(
val comment_id: CommentId,
val page: Int? = null,
val limit: Int? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package it.vercruysse.lemmyapi.v0x19.datatypes

import kotlinx.serialization.Serializable

@Serializable
data class ListCommentLikesResponse(
val comment_likes: List<VoteView>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package it.vercruysse.lemmyapi.v0x19.datatypes

import kotlinx.serialization.Serializable

@Serializable
data class ListPostLikes(
val post_id: PostId,
val page: Int? = null,
val limit: Int? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package it.vercruysse.lemmyapi.v0x19.datatypes

import kotlinx.serialization.Serializable

@Serializable
data class ListPostLikesResponse(
val post_likes: List<VoteView>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable

@Serializable
data class MarkPostAsRead(
// val post_id: PostId? = null, // Removed because it will be deprecated in the next version anyway, just use the list argument
// val post_id: PostId? = null, Removed because it will be deprecated in the next version anyway, just use the list argument
val post_ids: List<PostId>,
val read: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.vercruysse.lemmyapi.v0x19.datatypes

import kotlinx.serialization.Serializable

@Serializable
data class VoteView(
val creator: Person,
val score: Int,
)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ POM_DEVELOPER_URL=https://github.com/MV-GH

POM_ARTIFACT_ID=lemmy-api
GROUP=it.vercruysse.lemmyapi
VERSION_NAME=0.2.3-SNAPSHOT
VERSION_NAME=0.2.4-SNAPSHOT

0 comments on commit c0193b3

Please sign in to comment.