summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorGravatar default2023-08-31 16:11:58 +0200
committerGravatar default2023-08-31 16:11:58 +0200
commit57c84d1c3a153782d9bfa7b2edd157bdd1061e61 (patch)
treebec14e3546f9a9c64707f8dc5176f2a2d005b204 /activitypub.c
parentGot rid of old d_char. (diff)
downloadsnac2-57c84d1c3a153782d9bfa7b2edd157bdd1061e61.tar.gz
snac2-57c84d1c3a153782d9bfa7b2edd157bdd1061e61.tar.xz
snac2-57c84d1c3a153782d9bfa7b2edd157bdd1061e61.zip
Some fixes to 'Undo' messages.
msg_undo() now generates valid messages for objects that are only referenced by its id.
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/activitypub.c b/activitypub.c
index 35e9991..13e0c3c 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -761,6 +761,12 @@ xs_dict *msg_base(snac *snac, const char *type, const char *id,
761 xs *did = NULL; 761 xs *did = NULL;
762 xs *published = NULL; 762 xs *published = NULL;
763 xs *ntid = tid(0); 763 xs *ntid = tid(0);
764 const char *obj_id;
765
766 if (xs_type(object) == XSTYPE_DICT)
767 obj_id = xs_dict_get(object, "id");
768 else
769 obj_id = object;
764 770
765 /* generated values */ 771 /* generated values */
766 if (date && strcmp(date, "@now") == 0) { 772 if (date && strcmp(date, "@now") == 0) {
@@ -776,8 +782,8 @@ xs_dict *msg_base(snac *snac, const char *type, const char *id,
776 } 782 }
777 else 783 else
778 if (strcmp(id, "@object") == 0) { 784 if (strcmp(id, "@object") == 0) {
779 if (object != NULL) { 785 if (obj_id != NULL) {
780 did = xs_fmt("%s/%s_%s", xs_dict_get(object, "id"), type, ntid); 786 did = xs_fmt("%s/%s_%s", obj_id, type, ntid);
781 id = did; 787 id = did;
782 } 788 }
783 else 789 else
@@ -788,7 +794,7 @@ xs_dict *msg_base(snac *snac, const char *type, const char *id,
788 /* like @object, but always generate the same id */ 794 /* like @object, but always generate the same id */
789 if (object != NULL) { 795 if (object != NULL) {
790 date = xs_dict_get(object, "published"); 796 date = xs_dict_get(object, "published");
791 did = xs_fmt("%s/%s", xs_dict_get(object, "id"), type); 797 did = xs_fmt("%s/%s", obj_id, type);
792 id = did; 798 id = did;
793 } 799 }
794 else 800 else
@@ -996,8 +1002,10 @@ xs_dict *msg_undo(snac *snac, char *object)
996/* creates an 'Undo' message */ 1002/* creates an 'Undo' message */
997{ 1003{
998 xs_dict *msg = msg_base(snac, "Undo", "@object", snac->actor, "@now", object); 1004 xs_dict *msg = msg_base(snac, "Undo", "@object", snac->actor, "@now", object);
1005 const char *to;
999 1006
1000 msg = xs_dict_append(msg, "to", xs_dict_get(object, "object")); 1007 if (xs_type(object) == XSTYPE_DICT && (to = xs_dict_get(object, "object")))
1008 msg = xs_dict_append(msg, "to", to);
1001 1009
1002 return msg; 1010 return msg;
1003} 1011}