summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar violette2025-12-18 07:58:24 +0100
committerGravatar grunfink2025-12-18 07:58:24 +0100
commit85ed0eb0d535700a5df837c37f51848811e461a0 (patch)
tree818c80cc48c445b2950796230946c63eca3a3242 /data.c
parentBumped version. (diff)
downloadsnac2-85ed0eb0d535700a5df837c37f51848811e461a0.tar.gz
snac2-85ed0eb0d535700a5df837c37f51848811e461a0.tar.xz
snac2-85ed0eb0d535700a5df837c37f51848811e461a0.zip
Added emoji reactions (contributed by violette).
Diffstat (limited to '')
-rw-r--r--data.c124
1 files changed, 116 insertions, 8 deletions
diff --git a/data.c b/data.c
index 688d2e3..07eea3c 100644
--- a/data.c
+++ b/data.c
@@ -1043,6 +1043,14 @@ xs_list *object_children(const char *id)
1043} 1043}
1044 1044
1045 1045
1046xs_list *object_get_emoji_reacts(const char *id)
1047/* returns the list of an object's emoji reactions */
1048{
1049 xs *fn = _object_index_fn(id, "_e.idx");
1050 return index_list(fn, XS_ALL);
1051}
1052
1053
1046xs_list *object_likes(const char *id) 1054xs_list *object_likes(const char *id)
1047{ 1055{
1048 xs *fn = _object_index_fn(id, "_l.idx"); 1056 xs *fn = _object_index_fn(id, "_l.idx");
@@ -1086,12 +1094,26 @@ int object_admire(const char *id, const char *actor, int like)
1086 1094
1087 1095
1088int object_unadmire(const char *id, const char *actor, int like) 1096int object_unadmire(const char *id, const char *actor, int like)
1089/* actor no longer likes or announces this object */ 1097/* actor retrives their likes, announces or emojis this object */
1090{ 1098{
1099 switch (like) {
1100 case 0:
1101 like = 'a';
1102 break;
1103 case 1:
1104 like = 'l';
1105 break;
1106 case 2:
1107 like = 'e';
1108 break;
1109 }
1091 int status; 1110 int status;
1092 xs *fn = _object_fn(id); 1111 xs *fn = _object_fn(id);
1093 1112
1094 fn = xs_replace_i(fn, ".json", like ? "_l.idx" : "_a.idx"); 1113 char sfx[7] = "_x.idx";
1114 sfx[1] = like;
1115
1116 fn = xs_replace_i(fn, ".json", sfx);
1095 1117
1096 status = index_del(fn, actor); 1118 status = index_del(fn, actor);
1097 1119
@@ -1099,7 +1121,46 @@ int object_unadmire(const char *id, const char *actor, int like)
1099 index_gc(fn); 1121 index_gc(fn);
1100 1122
1101 srv_debug(0, 1123 srv_debug(0,
1102 xs_fmt("object_unadmire (%s) %s %s %d", like ? "Like" : "Announce", actor, fn, status)); 1124 xs_fmt("object_unadmire (%s) %s %s %d", like >= 'e' ?
1125 (like == 'l' ? "Like" : "EmojiReact") : "Announce" , actor, fn, status));
1126
1127 return status;
1128}
1129
1130int object_emoji_react(const char *mid, const char *eid)
1131/* actor reacts w/ an emoji */
1132{
1133 int status = HTTP_STATUS_OK;
1134 xs *fn = _object_fn(mid);
1135
1136 fn = xs_replace_i(fn, ".json", "_e.idx");
1137
1138 if (!index_in(fn, eid)) {
1139 status = index_add(fn, eid);
1140
1141 srv_debug(1, xs_fmt("object_emoji_react (%s) added %s to %s", "EmojiReact", eid, fn));
1142 }
1143
1144 return status;
1145}
1146
1147
1148int object_rm_emoji_react(const char *mid, const char *eid)
1149/* actor retrives their emoji reaction */
1150{
1151 int status;
1152 xs *fn = _object_fn(mid);
1153
1154 fn = xs_replace_i(fn, ".json", "_e.idx");
1155
1156 status = index_del(fn, eid);
1157 object_del(eid);
1158
1159 if (valid_status(status))
1160 index_gc(fn);
1161
1162 srv_debug(0,
1163 xs_fmt("object_unadmire (EmojiReact) %s %s %d", eid, fn, status));
1103 1164
1104 return status; 1165 return status;
1105} 1166}
@@ -1506,19 +1567,47 @@ int timeline_add(snac *snac, const char *id, const xs_dict *o_msg)
1506} 1567}
1507 1568
1508 1569
1509int timeline_admire(snac *snac, const char *id, const char *admirer, int like) 1570int timeline_emoji_react(const char *act, const char *id, xs_dict *msg)
1510/* updates a timeline entry with a new admiration */ 1571/* adds an emoji reaction to a message */
1572{
1573 msg = xs_dict_append(msg, "attributedTo", act);
1574 msg = xs_dict_set(msg, "type", "EmojiReact");
1575 const char *emote_id = xs_dict_get(msg, "id");
1576
1577 int ret = object_add(emote_id, msg);
1578 if (ret == HTTP_STATUS_OK || ret == HTTP_STATUS_CREATED)
1579 ret = object_emoji_react(id, emote_id);
1580
1581 return ret;
1582}
1583
1584
1585int timeline_admire(snac *snac, const char *id,
1586 const char *admirer, int like, xs_dict *msg)
1587/* updates a timeline entry with a new admiration or emoji reaction */
1511{ 1588{
1589 int ret;
1590 const char *content = xs_dict_get_path(msg, "content");
1591 const char *type = xs_dict_get_path(msg, "type");
1592
1512 /* if we are admiring this, add to both timelines */ 1593 /* if we are admiring this, add to both timelines */
1513 if (!like && strcmp(admirer, snac->actor) == 0) { 1594 if (!like && strcmp(admirer, snac->actor) == 0) {
1514 object_user_cache_add(snac, id, "public"); 1595 object_user_cache_add(snac, id, "public");
1515 object_user_cache_add(snac, id, "private"); 1596 object_user_cache_add(snac, id, "private");
1516 } 1597 }
1517 1598
1518 int ret = object_admire(id, admirer, like); 1599 /* use utf <3 as a like, as it is ugly */
1600 if (type && xs_match(type, "Like|EmojiReact|Emoji") &&
1601 content && strcmp(content, "❤") != 0) {
1602 ret = timeline_emoji_react(xs_dup(snac->actor), id, xs_dup(msg));
1603 snac_debug(snac, 1, xs_fmt("timeline_emoji_react %s", id));
1604 }
1519 1605
1520 snac_debug(snac, 1, xs_fmt("timeline_admire (%s) %s %s", 1606 else {
1521 like ? "Like" : "Announce", id, admirer)); 1607 ret = object_admire(id, admirer, like);
1608 snac_debug(snac, 1, xs_fmt("timeline_admire (%s) %s %s",
1609 like ? "Like" : "Announce", id, admirer));
1610 }
1522 1611
1523 return ret; 1612 return ret;
1524} 1613}
@@ -1867,6 +1956,25 @@ xs_list *muted_list(snac *user)
1867 return l; 1956 return l;
1868} 1957}
1869 1958
1959/** emojis react **/
1960
1961const xs_str *emoji_reacted(snac *user, const char *id)
1962/* returns the emoji an user reacted to a message */
1963{
1964 xs *emojis = object_get_emoji_reacts(id);
1965 int c = 0;
1966 const char *v;
1967 xs_dict *msg;
1968
1969 while (xs_list_next(emojis, &v, &c)) {
1970 if (object_get_by_md5(v, &msg)) {
1971 const xs_val *act = xs_dict_get(msg, "actor");
1972 if (act && strcmp(act, user->actor) == 0)
1973 return xs_dict_get(msg, "content");
1974 }
1975 }
1976 return NULL;
1977}
1870 1978
1871/** bookmarking **/ 1979/** bookmarking **/
1872 1980