From 0a9f246f1843da88a24e4f2e029423f39f4ca29d Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Fri, 1 Apr 2022 14:57:31 +0000 Subject: [PATCH] More status actions, generate code for these FossilOrigin-Name: bdc585725147949ef7819a1550b683e8c9fb53936dfde0cbded4403f6d7bb9a5 --- include/mastodont_status.h | 37 ++++++++++++---------- src/status.c | 64 +++++++++++++++++++++----------------- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/include/mastodont_status.h b/include/mastodont_status.h index 2d130bc..20219d0 100644 --- a/include/mastodont_status.h +++ b/include/mastodont_status.h @@ -130,25 +130,30 @@ int mastodont_create_status(mastodont_t* data, struct mstdnt_args* args, struct mstdnt_storage* storage); -int mastodont_favourite_status(mastodont_t* data, - char* id, - struct mstdnt_storage* storage, - struct mstdnt_status* status); +/* Generates do and undo functions */ +#define MSTDNT_STATUS_ACTION_DECL(type) int mastodont_##type##_status(mastodont_t* data, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status) +#define MSTDNT_STATUS_ACTION_FUNC_URL(action) { \ + return mstdnt_status_action(data, id, storage, status, "api/v1/statuses/%s/" action);\ + } -int mastodont_unfavourite_status(mastodont_t* data, - char* id, - struct mstdnt_storage* storage, - struct mstdnt_status* status); +MSTDNT_STATUS_ACTION_DECL(favourite); +MSTDNT_STATUS_ACTION_DECL(unfavourite); +MSTDNT_STATUS_ACTION_DECL(reblog); +MSTDNT_STATUS_ACTION_DECL(unreblog); +MSTDNT_STATUS_ACTION_DECL(pin); +MSTDNT_STATUS_ACTION_DECL(unpin); +MSTDNT_STATUS_ACTION_DECL(bookmark); +MSTDNT_STATUS_ACTION_DECL(unbookmark); -int mastodont_reblog_status(mastodont_t* data, - char* id, - struct mstdnt_storage* storage, - struct mstdnt_status* status); +int mastodont_mute_conversation(mastodont_t* data, + char* id, + struct mstdnt_storage* storage, + struct mstdnt_status* status); -int mastodont_unreblog_status(mastodont_t* data, - char* id, - struct mstdnt_storage* storage, - struct mstdnt_status* status); +int mastodont_unmute_conversation(mastodont_t* data, + char* id, + struct mstdnt_storage* storage, + struct mstdnt_status* status); /* Callbacks */ struct _mstdnt_statuses_cb_args diff --git a/src/status.c b/src/status.c index e15e5c5..42930f6 100644 --- a/src/status.c +++ b/src/status.c @@ -236,38 +236,46 @@ static int mstdnt_status_action(mastodont_t* data, return mastodont_request(data, &req_args); } -int mastodont_favourite_status(mastodont_t* data, - char* id, - struct mstdnt_storage* storage, - struct mstdnt_status* status) +/* These are all the same */ +MSTDNT_STATUS_ACTION_DECL(favourite) +MSTDNT_STATUS_ACTION_FUNC_URL("favourite") + +MSTDNT_STATUS_ACTION_DECL(unfavourite) +MSTDNT_STATUS_ACTION_FUNC_URL("unfavourite") + +MSTDNT_STATUS_ACTION_DECL(reblog) +MSTDNT_STATUS_ACTION_FUNC_URL("reblog") + +MSTDNT_STATUS_ACTION_DECL(unreblog) +MSTDNT_STATUS_ACTION_FUNC_URL("unreblog") + +MSTDNT_STATUS_ACTION_DECL(pin) +MSTDNT_STATUS_ACTION_FUNC_URL("pin") + +MSTDNT_STATUS_ACTION_DECL(unpin) +MSTDNT_STATUS_ACTION_FUNC_URL("unpin") + +MSTDNT_STATUS_ACTION_DECL(bookmark) +MSTDNT_STATUS_ACTION_FUNC_URL("bookmark") + +MSTDNT_STATUS_ACTION_DECL(unbookmark) +MSTDNT_STATUS_ACTION_FUNC_URL("unbookmark") + +/* TODO Mutes can be timed */ +int mastodont_mute_conversation(mastodont_t* data, + char* id, + struct mstdnt_storage* storage, + struct mstdnt_status* status) { - return mstdnt_status_action(data, id, storage, status, "api/v1/statuses/%s/favourite"); + return mstdnt_status_action(data, id, storage, status, "api/v1/statuses/%s/mute"); } - -int mastodont_unfavourite_status(mastodont_t* data, - char* id, - struct mstdnt_storage* storage, - struct mstdnt_status* status) +int mastodont_unmute_conversation(mastodont_t* data, + char* id, + struct mstdnt_storage* storage, + struct mstdnt_status* status) { - return mstdnt_status_action(data, id, storage, status, "api/v1/statuses/%s/unfavourite"); -} - - -int mastodont_reblog_status(mastodont_t* data, - char* id, - struct mstdnt_storage* storage, - struct mstdnt_status* status) -{ - return mstdnt_status_action(data, id, storage, status, "api/v1/statuses/%s/reblog"); -} - -int mastodont_unreblog_status(mastodont_t* data, - char* id, - struct mstdnt_storage* storage, - struct mstdnt_status* status) -{ - return mstdnt_status_action(data, id, storage, status, "api/v1/statuses/%s/unreblog"); + return mstdnt_status_action(data, id, storage, status, "api/v1/statuses/%s/unmute"); } int mastodont_get_status(mastodont_t* data,