Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Remove uses of JsonObject in client server API #6

Open
Dominaezzz opened this issue May 25, 2022 · 0 comments
Open

Remove uses of JsonObject in client server API #6

Dominaezzz opened this issue May 25, 2022 · 0 comments

Comments

@Dominaezzz
Copy link
Owner

Some endpoints like SendMessage take a JsonObject which is less that ideal.

public class SendMessage(
public override val url: Url,
public override val body: JsonObject
) : MatrixRpc.WithAuth<RpcMethod.Put, SendMessage.Url, JsonObject, SendMessage.Response> {

To send messages one has to do this, which is rather verbose and forces one to specify MatrixJson which can break some abstractions.

SendMessage(
    SendMessage.Url(roomId, "m.room.message", txnId),
    MatrixJson.encodeToJsonElement<MessageContent>(MessageContent.Text("test body")).jsonObject
)

It had to be done this way since KTor just didn't support it. Request bodies underwent type erasure.
However this has been fixed in KTor 2.0.0 and so we can now use generics.

Fixing this issue means allowing this to be possible.

SendMessage<MessageContent>(
    SendMessage.Url(roomId, "m.room.message", txnId),
    MessageContent.Text("test body")
)

In some cases the generic parameter need to be a JSON object and not an array, string, etc.
There isn't an idiomatic way to prevent the user from being naughty here so I'll leave it to the user to behave. This library shouldn't be jumping through hoops to hand hold the user.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant