~julienxx/masto9

c6ef27f226f6a5817532a02c1fb273f1631a564e — Julien Blanchard 1 year, 7 months ago 0711761
Cleanup before initial release
4 files changed, 70 insertions(+), 66 deletions(-)

M README.md
M display.c
M masto9.c
M masto9.h
M README.md => README.md +1 -1
@@ 1,6 1,6 @@
# masto9

A mastodon client for 9front.
A simple mastodon client for 9front.

## Usage


M display.c => display.c +18 -15
@@ 61,9 61,9 @@ displaytoots(Toot toots[], char *server)

		username = esmprint("%s (%s)", toot.displayname, toot.handle);

		Bprint(&out, "\n\n——————————\n");
		Bprint(&out, "\n——————————\n");
		if(toot.reblogged == 1) {
			Bprint(&out, "⊙ %s retooted %s:\n", username, toot.rebloggedhandle);
			Bprint(&out, "∞ %s retooted %s:\n", username, toot.rebloggedhandle);
		} else {
			Bprint(&out, "⊙ %s:\n", username);
		}


@@ 75,10 75,10 @@ displaytoots(Toot toots[], char *server)
			}
			Bprint(&out, "\n");
		}
		Bprint(&out, "\nReply[%s] | Boost[%s] | Favorite[%s]", toot.id, toot.id,
		Bprint(&out, "\n→ Reply[%s] ∙ Boost[%s] ∙ Favorite[%s]\n", toot.id, toot.id,
			   toot.id);
	}
	Bprint(&out, "\n\n\n⇒ Send the next line to load more");
	Bprint(&out, "\n\n⇒ Send the next line to load more");
	Bprint(&out, "\nmasto9 %s more %s\n\n", server, toots[TOOTSCOUNT - 1].id);
	Bflush(&out);
}


@@ 93,28 93,31 @@ displaynotifications(Notification notifs[])
		Notification notif = notifs[i];
		char *username;

    if(strlen(notif.displayname) > 0) {
      username = esmprint("%s (%s)", notif.displayname, notif.handle);
    } else {
      username = notif.handle;
    }
		if(strlen(notif.displayname) > 0) {
			username = esmprint("%s (%s)", notif.displayname, notif.handle);
		} else {
			username = notif.handle;
		}

		Bprint(&out, "\n——————————\n");
		if(strcmp(notif.type, "reblog") == 0) {
			Bprint(&out, "\n⊙ %s retooted\n %s", username,
			Bprint(&out, "∞ %s retooted:\n\n%s", username,
				   fmthtml(cleanup(notif.content)));
		} else if(strcmp(notif.type, "favourite") == 0) {
			Bprint(&out, "\n⊙ %s favorited\n %s", username,
			Bprint(&out, "★ %s favorited:\n\n%s", username,
				   fmthtml(cleanup(notif.content)));
		} else if(strcmp(notif.type, "mention") == 0) {
			Bprint(&out, "\n⊙ %s mentioned you\n %s", username,
			Bprint(&out, "⊙ %s mentioned you:\n\n%s", username,
				   fmthtml(cleanup(notif.content)));
			Bprint(&out, "\n→ Reply[%s] ∙ Boost[%s] ∙ Favorite[%s]\n",
				   notif.statusid, notif.statusid, notif.statusid);
		} else if(strcmp(notif.type, "follow") == 0) {
			Bprint(&out, "\n⊙ %s followed you\n", username);
			Bprint(&out, "↔ %s followed you.\n", username);
		} else if(strcmp(notif.type, "poll") == 0) {
			Bprint(&out, "\n⊙ %s poll ended\n %s", username,
			Bprint(&out, "∴ %s poll ended:\n\n%s", username,
				   fmthtml(cleanup(notif.content)));
		}
	}
	Bprint(&out, "\n");
	Bprint(&out, "\n\n");
	Bflush(&out);
}

M masto9.c => masto9.c +50 -50
@@ 35,6 35,39 @@ mastodonget(char *token, char *host, char *endpoint)
}

static void
perform(char *token, char *host, char *id, char *action)
{
	char *url;
	url = esmprint("https://%s/api/v1/statuses/%s/%s", host, id, action);
	httppost(token, url, "");
}

static char *
tootauthor(char *token, char *host, char *id)
{
	JSON *obj, *account, *reblog;
	char *endpoint, *response;

	endpoint = esmprint("statuses/%s", id);
	obj = mastodonget(token, host, endpoint);

	reblog = getjsonkey(obj, "reblog");
	if(reblog->s != nil) {
		account = getjsonkey(reblog, "account");
	} else {
		account = getjsonkey(obj, "account");
	}

	response = estrdup((char *)getjsonkey(account, "acct")->s);

	free(account);
	free(reblog);
	free(obj);

	return response;
}

static void
gethome(char *token, char *host, Toot toots[], char *beforeid)
{
	JSON *obj, *id, *content, *reblogcontent, *account, *reblogaccount, *handle,


@@ 118,7 151,7 @@ gethome(char *token, char *host, Toot toots[], char *beforeid)
static void
getnotifications(char *token, char *host, Notification *notifs, char *filter)
{
	JSON *obj, *id, *content, *displayname, *handle, *type, *account, *status;
	JSON *obj, *id, *content, *displayname, *handle, *type, *account, *status, *statusid;
	char *endpoint;
	int i = 0;



@@ 137,25 170,25 @@ getnotifications(char *token, char *host, Notification *notifs, char *filter)

		id = getjsonkey(notifjson, "id");
		type = getjsonkey(notifjson, "type");
		if(strcmp(type->s, "follow") != 0) {
			status = getjsonkey(notifjson, "status");
			content = getjsonkey(status, "content");
		} else {
			content = jsonparse("");
		}
		account = getjsonkey(notifjson, "account");

    account = getjsonkey(notifjson, "account");
		displayname = getjsonkey(account, "display_name");
		handle = getjsonkey(account, "acct");

		Notification *notif = emalloc(sizeof(Notification));
		notif->id = estrdup((char *)id->s);

		notif->type = estrdup((char *)type->s);
		notif->displayname = estrdup((char *)displayname->s);
		notif->handle = estrdup((char *)handle->s);

		if(strcmp(type->s, "follow") != 0) {
			status = getjsonkey(notifjson, "status");
			content = getjsonkey(status, "content");
			statusid = getjsonkey(status, "id");

			notif->content = estrdup((char *)content->s);
			notif->statusid = estrdup((char *)statusid->s);
		}
		notif->displayname = estrdup((char *)displayname->s);
		notif->handle = estrdup((char *)handle->s);

		notifs[i] = *notif;
		i++;


@@ 173,31 206,6 @@ posttoot(char *token, char *host, char *text)
	print("Posted:\n %s\n", text);
}

static char *
tootauthor(char *token, char *host, char *id)
{
	JSON *obj, *account, *reblog;
	char *endpoint, *response;

	endpoint = esmprint("statuses/%s", id);
	obj = mastodonget(token, host, endpoint);

	reblog = getjsonkey(obj, "reblog");
	if(reblog->s != nil) {
		account = getjsonkey(reblog, "account");
	} else {
		account = getjsonkey(obj, "account");
	}

	response = estrdup((char *)getjsonkey(account, "acct")->s);

	free(account);
	free(reblog);
	free(obj);

	return response;
}

static void
postattachment(char *token, char *host, char *text, char *filepath)
{


@@ 224,14 232,6 @@ postattachment(char *token, char *host, char *text, char *filepath)
}

static void
perform(char *token, char *host, char *id, char *action)
{
	char *url;
	url = esmprint("https://%s/api/v1/statuses/%s/%s", host, id, action);
	httppost(token, url, "");
}

static void
boost(char *token, char *host, char *id)
{
	perform(token, host, id, "reblog");


@@ 294,12 294,6 @@ reply(char *token, char *host, char *id)
}

static void
usage(void)
{
	sysfatal("usage: masto9 DOMAIN [COMMAND] [DATA]");
}

static void
debug(char *token, char *host, char *id)
{
	JSON *obj;


@@ 311,6 305,12 @@ debug(char *token, char *host, char *id)
	jsonfree(obj);
}

static void
usage(void)
{
	sysfatal("usage: masto9 DOMAIN [COMMAND] [DATA]");
}

void
main(int argc, char **argv)
{

M masto9.h => masto9.h +1 -0
@@ 14,6 14,7 @@ typedef struct Notification {
  char *handle;
  char *displayname;
  char *content;
  char *statusid;
} Notification;

typedef struct Toot {