Visibility as enum
FossilOrigin-Name: 70f14b93638420569052adf7ee82887f5429f3f6229adc2b25ff33b65b065d92
This commit is contained in:
parent
d924d969b1
commit
98917fcfcb
4 changed files with 47 additions and 12 deletions
|
@ -39,7 +39,7 @@ struct mstdnt_status
|
|||
time_t created_at;
|
||||
struct mstdnt_account account;
|
||||
char* content;
|
||||
char* visibility;
|
||||
enum mstdnt_visibility_type visibility;
|
||||
mstdnt_bool sensitive;
|
||||
char* spoiler_text;
|
||||
struct mstdnt_attachment* media_attachments;
|
||||
|
|
|
@ -19,12 +19,23 @@
|
|||
|
||||
/* These used to uint8_t's, but because lists are custom strings,
|
||||
it was better to make these regular strings */
|
||||
#define MSTDNT_VISIBILITY_PUBLIC "public"
|
||||
#define MSTDNT_VISIBILITY_UNLISTED "unlisted"
|
||||
#define MSTDNT_VISIBILITY_PRIVATE "private"
|
||||
#define MSTDNT_VISIBILITY_DIRECT "direct"
|
||||
#define MSTDNT_VISIBILITY_LOCAL "local"
|
||||
#define MSTDNT_STR_VISIBILITY_PUBLIC "public"
|
||||
#define MSTDNT_STR_VISIBILITY_UNLISTED "unlisted"
|
||||
#define MSTDNT_STR_VISIBILITY_PRIVATE "private"
|
||||
#define MSTDNT_STR_VISIBILITY_DIRECT "direct"
|
||||
#define MSTDNT_STR_VISIBILITY_LOCAL "local"
|
||||
|
||||
typedef char* mstdnt_visibility_t;
|
||||
|
||||
enum mstdnt_visibility_type
|
||||
{
|
||||
MSTDNT_VISIBILITY_PUBLIC,
|
||||
MSTDNT_VISIBILITY_UNLISTED,
|
||||
MSTDNT_VISIBILITY_PRIVATE,
|
||||
MSTDNT_VISIBILITY_DIRECT,
|
||||
MSTDNT_VISIBILITY_LOCAL,
|
||||
MSTDNT_VISIBILITY_LIST,
|
||||
MSTDNT_VISIBILITY_UNKNOWN,
|
||||
};
|
||||
|
||||
#endif /* MASTODONT_VISIBILITY_TYPES_H */
|
||||
|
|
|
@ -130,11 +130,6 @@ void _mstdnt_val_string_int_call(cJSON* v, void* _type)
|
|||
void _mstdnt_val_string_call(cJSON* v, void* _type)
|
||||
{
|
||||
char** type = _type;
|
||||
if (!cJSON_IsString(v))
|
||||
{
|
||||
*type = NULL;
|
||||
return;
|
||||
}
|
||||
*type = v->valuestring;
|
||||
}
|
||||
|
||||
|
|
31
src/status.c
31
src/status.c
|
@ -45,6 +45,35 @@ void _mstdnt_val_malloc_status_call(cJSON* v, void* _type)
|
|||
mstdnt_status_json(*type, v->child);
|
||||
}
|
||||
|
||||
// Consider moving to mastodont_visibility_types?
|
||||
static void _mstdnt_val_visibility_call(cJSON* v, void* _type)
|
||||
{
|
||||
enum mstdnt_visibility_type* type = _type;
|
||||
|
||||
// Check first, as we must read it
|
||||
if (!cJSON_IsString(v))
|
||||
{
|
||||
*type = MSTDNT_VISIBILITY_UNKNOWN;
|
||||
return;
|
||||
}
|
||||
|
||||
char* str = v->valuestring;
|
||||
if (strcmp(str, "public") == 0)
|
||||
*type = MSTDNT_VISIBILITY_PUBLIC;
|
||||
else if (strcmp(str, "unlisted") == 0)
|
||||
*type = MSTDNT_VISIBILITY_UNLISTED;
|
||||
else if (strcmp(str, "private") == 0)
|
||||
*type = MSTDNT_VISIBILITY_PRIVATE;
|
||||
else if (strcmp(str, "direct") == 0)
|
||||
*type = MSTDNT_VISIBILITY_DIRECT;
|
||||
else if (strcmp(str, "local") == 0)
|
||||
*type = MSTDNT_VISIBILITY_LOCAL;
|
||||
else if (strcmp(str, "list") == 0)
|
||||
*type = MSTDNT_VISIBILITY_LIST;
|
||||
else
|
||||
*type = MSTDNT_VISIBILITY_UNKNOWN;
|
||||
}
|
||||
|
||||
int mstdnt_status_json(struct mstdnt_status* status, cJSON* js)
|
||||
{
|
||||
cJSON* v;
|
||||
|
@ -76,7 +105,7 @@ int mstdnt_status_json(struct mstdnt_status* status, cJSON* js)
|
|||
{ "language", &(status->language), _mstdnt_val_string_call },
|
||||
{ "url", &(status->url), _mstdnt_val_string_call },
|
||||
{ "text", &(status->text), _mstdnt_val_string_call },
|
||||
{ "visibility", &(status->visibility), _mstdnt_val_string_call },
|
||||
{ "visibility", &(status->visibility), _mstdnt_val_visibility_call },
|
||||
{ "in_reply_to_account_id", &(status->in_reply_to_account_id), _mstdnt_val_string_call },
|
||||
{ "sensitive", &(status->sensitive), _mstdnt_val_bool_call },
|
||||
{ "favourited", &(status->favourited), _mstdnt_val_bool_call },
|
||||
|
|
Loading…
Reference in a new issue