summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGravatar grunfink2025-06-26 10:39:47 +0200
committerGravatar grunfink2025-06-26 10:39:47 +0200
commitc976b9a334872e14aadc1f454680599468652231 (patch)
tree357dc81cd871a94e861c3cef199ce30d1a66b079 /main.c
parentFixed crash. (diff)
downloadsnac2-c976b9a334872e14aadc1f454680599468652231.tar.gz
snac2-c976b9a334872e14aadc1f454680599468652231.tar.xz
snac2-c976b9a334872e14aadc1f454680599468652231.zip
Sending notes from the cmdline allows setting an inReplyTo field.
Diffstat (limited to '')
-rw-r--r--main.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/main.c b/main.c
index f271abc..ce4e7ce 100644
--- a/main.c
+++ b/main.c
@@ -7,6 +7,7 @@
7#include "xs_time.h" 7#include "xs_time.h"
8#include "xs_openssl.h" 8#include "xs_openssl.h"
9#include "xs_match.h" 9#include "xs_match.h"
10#include "xs_random.h"
10 11
11#include "snac.h" 12#include "snac.h"
12 13
@@ -779,12 +780,24 @@ int main(int argc, char *argv[])
779 xs *msg = NULL; 780 xs *msg = NULL;
780 xs *c_msg = NULL; 781 xs *c_msg = NULL;
781 xs *attl = xs_list_new(); 782 xs *attl = xs_list_new();
782 char *fn = NULL; 783 const char *fn = NULL;
784 const char *in_reply_to = NULL;
785 const char **next = NULL;
783 786
784 /* iterate possible attachments */ 787 /* iterate possible attachments */
785 while ((fn = GET_ARGV())) { 788 while ((fn = GET_ARGV())) {
786 FILE *f; 789 FILE *f;
787 790
791 if (next) {
792 *next = fn;
793 next = NULL;
794 }
795 else
796 if (strcmp(fn, "-r") == 0) {
797 /* next argument is an inReplyTo */
798 next = &in_reply_to;
799 }
800 else
788 if ((f = fopen(fn, "rb")) != NULL) { 801 if ((f = fopen(fn, "rb")) != NULL) {
789 /* get the file size and content */ 802 /* get the file size and content */
790 fseek(f, 0, SEEK_END); 803 fseek(f, 0, SEEK_END);
@@ -794,8 +807,10 @@ int main(int argc, char *argv[])
794 fclose(f); 807 fclose(f);
795 808
796 char *ext = strrchr(fn, '.'); 809 char *ext = strrchr(fn, '.');
797 xs *hash = xs_md5_hex(fn, strlen(fn)); 810 char rnd[32];
798 xs *id = xs_fmt("%s%s", hash, ext); 811 xs_rnd_buf(rnd, sizeof(rnd));
812 xs *hash = xs_md5_hex(rnd, sizeof(rnd));
813 xs *id = xs_fmt("post-%s%s", hash, ext ? ext : "");
799 xs *url = xs_fmt("%s/s/%s", snac.actor, id); 814 xs *url = xs_fmt("%s/s/%s", snac.actor, id);
800 815
801 /* store */ 816 /* store */
@@ -856,7 +871,7 @@ int main(int argc, char *argv[])
856 if (strcmp(cmd, "note_unlisted") == 0) 871 if (strcmp(cmd, "note_unlisted") == 0)
857 scope = 2; 872 scope = 2;
858 873
859 msg = msg_note(&snac, content, NULL, NULL, attl, scope, getenv("LANG"), NULL); 874 msg = msg_note(&snac, content, NULL, in_reply_to, attl, scope, getenv("LANG"), NULL);
860 875
861 c_msg = msg_create(&snac, msg); 876 c_msg = msg_create(&snac, msg);
862 877