Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce invite RPC requests #22

Merged
merged 2 commits into from
Feb 12, 2022
Merged

Conversation

mycognosist
Copy link
Collaborator

Another simple addition. Here we add the ability to send invite.create and invite.use RPC requests.

invite.create has an optional argument to specify the number of uses for the invite being created, ie. "generate an invite code that can be used x times" (where x is the value of uses).

@mycognosist mycognosist marked this pull request as draft February 8, 2022 13:23
@mycognosist
Copy link
Collaborator Author

I've changed the status on this to Draft while I track down a bug in the uses argument for invite.create.

@mycognosist
Copy link
Collaborator Author

The invite.create RPC method expects the argument to be in the shape of an object. The object must not be inside of an array. This is different to the other methods currently supported by kuska.

I have introduced the ArgType enum to allow us to match inside of send_request() and format the args field for BodyRef correctly:

pub enum ArgType {
    Array,
    Tuple,
    Object,
}

// inside of `send_request()` ...
// note the different representation of `args` in each case
let body_str = match arg_type {
    ArgType::Array => serde_json::to_string(&BodyRef {
        name,
        rpc_type,
        args: &[args],
    })?,
    ArgType::Tuple => serde_json::to_string(&BodyRefWithOpts {
        name,
        rpc_type,
        args: (args, opts),
    })?,
    ArgType::Object => serde_json::to_string(&BodyRef {
        name,
        rpc_type,
        args: &args,
    })?,
};

I can confirm this is working against the go-sbot.

CC: @adria0, this is now ready for review :)

@mycognosist mycognosist marked this pull request as ready for review February 9, 2022 08:36
Copy link
Member

@adria0 adria0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with comments

#[derive(Debug)]
pub enum ArgType {
Array,
Tuple,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer ArgsOptsTuple I think that it's more descriptive.

@adria0 adria0 merged commit 47165dd into Kuska-ssb:master Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants