~julienxx/masto9

7029129c4b7f1256bf5923b78c39537aa60267bf — Julien Blanchard 22 days ago 1cab90a master
Respect toots and notifications limits, handle snac edge case with favourites
1 files changed, 17 insertions(+), 10 deletions(-)

M masto9.c
M masto9.c => masto9.c +17 -10
@@ 12,8 12,7 @@ getcredentials(char *host)
{
	UserPasswd *p;

	if((p = auth_getuserpasswd(
			auth_getkey, "proto=pass service=mastodon server=%s", host)) == nil)
	if((p = auth_getuserpasswd(auth_getkey, "proto=pass service=mastodon server=%s", host)) == nil)
		sysfatal("getcredentials: failed to retrieve token: %r");

	return p;


@@ 86,7 85,7 @@ gethome(char *token, char *host, Toot toots[], char *beforeid)
	if(obj->t != JSONArray)
		sysfatal("gethome: jsonparse: not an array");

	for(JSONEl *p = obj->first; p != nil; p = p->next) {
	for(JSONEl *p = obj->first; p != nil && i < TOOTSCOUNT; p = p->next) {
		JSON *tootjson = p->val;

		id = getjsonkey(tootjson, "id");


@@ 122,8 121,7 @@ gethome(char *token, char *host, Toot toots[], char *beforeid)

		if(mediaattachments->s != nil) {
			int j = 0;
			for(JSONEl *at = mediaattachments->first; at != nil;
				at = at->next) {
			for(JSONEl *at = mediaattachments->first; at != nil; at = at->next) {
				JSON *attachmentjson = at->val;
				Attachment *attachment = emalloc(sizeof(Attachment));
				type = getjsonkey(attachmentjson, "type");


@@ 151,7 149,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, *statusid;
	JSON *obj, *id, *content, *displayname, *handle, *type, *account, *status, *statusid, *reblog;
	char *endpoint;
	int i = 0;



@@ 165,9 163,8 @@ getnotifications(char *token, char *host, Notification *notifs, char *filter)
	if(obj->t != JSONArray)
		sysfatal("getnotifications: jsonparse: not an array");

	for(JSONEl *p = obj->first; p != nil; p = p->next) {
	for(JSONEl *p = obj->first; p != nil && i < NOTIFSCOUNT; p = p->next) {
		JSON *notifjson = p->val;

		id = getjsonkey(notifjson, "id");
		type = getjsonkey(notifjson, "type");



@@ 183,9 180,19 @@ getnotifications(char *token, char *host, Notification *notifs, char *filter)

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

			if(strcmp(type->s, "favourite") == 0 && reblog->s != nil) {
				// Weird case with snac where a favourite is on a reblog
				// so the "content" key is inside the reblog object as "text"
				content = getjsonkey(reblog, "text");
			} else if (strcmp(type->s, "reblog") == 0 && reblog->s != nil) {
				content = getjsonkey(reblog, "content");
			} else {
				content = getjsonkey(status, "content");
			}

			statusid = getjsonkey(status, "id");
			notif->content = estrdup((char *)content->s);
			notif->statusid = estrdup((char *)statusid->s);
		}