MV-GH / LemmyBackwardsCompatibleAPI

Kotlin multiplatform Backward compatible Lemmy API
GNU Affero General Public License v3.0
4 stars 1 forks source link

`SuccessResponse` is missing. #54

Closed dessalines closed 4 months ago

dessalines commented 4 months ago

I'm trying to add HidePost, and a few other related 0.19.4 actions to jerboa, but some types are missing.

MV-GH commented 4 months ago

Which types beside SuccessResponse is missing?

I have SuccessResponse explicitly not included because currently it just hardcoded true value. I did not see any value in having the extra parsing cost + extra complexity to turn the result into a failure if success is false.

Result<Unit> conveys the same information

dessalines commented 4 months ago

SuccessResponse is a struct that's used in a lot of responses, and has a success field:

pub struct SuccessResponse {
  pub success: bool,
}

I suppose I could force that into Result , but that's not the actual type for either lemmy-js-client or rust.

MV-GH commented 4 months ago

No I mean for this client.

I return Result<Unit>

Result<SuccessResponse> is awkard API to use

For example

 api.hidePost(HidePost(listOf(1), true)).onSuccess { 
            if (it.sucesss) {
                doSucess()
            } else {
                doFailure()
            }
        }.onFailure { 
            doFailure()
        }

vs

     api.hidePost(HidePost(listOf(1), true))
            .onSuccess {
                doSuccess()
            }
            .onFailure {
                doFailure()
            }

Same in Lemmy-js-client where it returns a promise, you will have to explicitly check success in your then chain instead of your catch

Since Result already perfectly represents success/failure its pointless to have another object

dessalines commented 4 months ago

Okay thx, I'll try this out.