commit 57c84d1

default  ·  2023-08-31 14:11:58 +0000 UTC
parent dfeb466
Some fixes to 'Undo' messages.

msg_undo() now generates valid messages for objects that are only
referenced by its id.
1 files changed,  +12, -4
+12, -4
 1@@ -761,6 +761,12 @@ xs_dict *msg_base(snac *snac, const char *type, const char *id,
 2     xs *did       = NULL;
 3     xs *published = NULL;
 4     xs *ntid      = tid(0);
 5+    const char *obj_id;
 6+
 7+    if (xs_type(object) == XSTYPE_DICT)
 8+        obj_id = xs_dict_get(object, "id");
 9+    else
10+        obj_id = object;
11 
12     /* generated values */
13     if (date && strcmp(date, "@now") == 0) {
14@@ -776,8 +782,8 @@ xs_dict *msg_base(snac *snac, const char *type, const char *id,
15         }
16         else
17         if (strcmp(id, "@object") == 0) {
18-            if (object != NULL) {
19-                did = xs_fmt("%s/%s_%s", xs_dict_get(object, "id"), type, ntid);
20+            if (obj_id != NULL) {
21+                did = xs_fmt("%s/%s_%s", obj_id, type, ntid);
22                 id = did;
23             }
24             else
25@@ -788,7 +794,7 @@ xs_dict *msg_base(snac *snac, const char *type, const char *id,
26             /* like @object, but always generate the same id */
27             if (object != NULL) {
28                 date = xs_dict_get(object, "published");
29-                did = xs_fmt("%s/%s", xs_dict_get(object, "id"), type);
30+                did = xs_fmt("%s/%s", obj_id, type);
31                 id = did;
32             }
33             else
34@@ -996,8 +1002,10 @@ xs_dict *msg_undo(snac *snac, char *object)
35 /* creates an 'Undo' message */
36 {
37     xs_dict *msg = msg_base(snac, "Undo", "@object", snac->actor, "@now", object);
38+    const char *to;
39 
40-    msg = xs_dict_append(msg, "to", xs_dict_get(object, "object"));
41+    if (xs_type(object) == XSTYPE_DICT && (to = xs_dict_get(object, "object")))
42+        msg = xs_dict_append(msg, "to", to);
43 
44     return msg;
45 }