ref: c6ef27f226f6a5817532a02c1fb273f1631a564e
parent: 0711761832f4be41bb103cee39cb91d766f67f33
author: Julien Blanchard <julien@typed-hole.org>
date: Fri Apr 14 19:27:58 EDT 2023
Cleanup before initial release
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# masto9
-A mastodon client for 9front.
+A simple mastodon client for 9front.
## Usage
--- a/display.c
+++ b/display.c
@@ -61,9 +61,9 @@
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 @@
}
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 @@
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);
}
--- a/masto9.c
+++ b/masto9.c
@@ -35,6 +35,39 @@
}
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 @@
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 @@
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 @@
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 @@
}
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 @@
}
static void
-usage(void)
-{
- sysfatal("usage: masto9 DOMAIN [COMMAND] [DATA]");
-}
-
-static void
debug(char *token, char *host, char *id)
{
JSON *obj;
@@ -309,6 +303,12 @@
obj = mastodonget(token, host, endpoint);
print("%J\n", obj);
jsonfree(obj);
+}
+
+static void
+usage(void)
+{
+ sysfatal("usage: masto9 DOMAIN [COMMAND] [DATA]");
}
void
--- a/masto9.h
+++ b/masto9.h
@@ -14,6 +14,7 @@
char *handle;
char *displayname;
char *content;
+ char *statusid;
} Notification;
typedef struct Toot {