commit f162c07
default
·
2024-01-18 21:21:05 +0000 UTC
parent 02998eb
Added some support for Peertube videos.
2 files changed,
+99,
-10
M
html.c
+7,
-0
1@@ -1732,6 +1732,13 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
2 if (timeline_add(snac, id, object))
3 snac_log(snac, xs_fmt("new 'Question' %s %s", actor, id));
4 }
5+ else
6+ if (strcmp(utype, "Video") == 0) { /** **/
7+ char *id = xs_dict_get(object, "id");
8+
9+ if (timeline_add(snac, id, object))
10+ snac_log(snac, xs_fmt("new 'Video' %s %s", actor, id));
11+ }
12 else
13 snac_debug(snac, 1, xs_fmt("ignored 'Create' for object type '%s'", utype));
14 }
M
html.c
+92,
-10
1@@ -227,15 +227,11 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
2 }
3
4
5-xs_html *html_msg_icon(snac *user, const xs_dict *msg)
6+xs_html *html_msg_icon(snac *user, char *actor_id, const xs_dict *msg)
7 {
8- char *actor_id;
9 xs *actor = NULL;
10 xs_html *actor_icon = NULL;
11
12- if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
13- actor_id = xs_dict_get(msg, "actor");
14-
15 if (actor_id && valid_status(actor_get(actor_id, &actor))) {
16 char *date = NULL;
17 char *udate = NULL;
18@@ -243,7 +239,7 @@ xs_html *html_msg_icon(snac *user, const xs_dict *msg)
19 int priv = 0;
20 const char *type = xs_dict_get(msg, "type");
21
22- if (xs_match(type, "Note|Question|Page|Article"))
23+ if (xs_match(type, "Note|Question|Page|Article|Video"))
24 url = xs_dict_get(msg, "id");
25
26 priv = !is_msg_public(msg);
27@@ -1268,10 +1264,10 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
28 xs_html_tag("div",
29 xs_html_attr("class", "snac-origin"),
30 xs_html_text(L("follows you"))),
31- html_msg_icon(local ? NULL : user, msg)));
32+ html_msg_icon(local ? NULL : user, xs_dict_get(msg, "actor"), msg)));
33 }
34 else
35- if (!xs_match(type, "Note|Question|Page|Article")) {
36+ if (!xs_match(type, "Note|Question|Page|Article|Video")) {
37 /* skip oddities */
38 return NULL;
39 }
40@@ -1284,6 +1280,31 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
41 if ((actor = xs_dict_get(msg, "attributedTo")) == NULL)
42 return NULL;
43
44+ /* if the actor is a list (like on Peertube videos), pick the Person */
45+ if (xs_type(actor) == XSTYPE_LIST) {
46+ char *e_actor = NULL;
47+ xs_list *p = actor;
48+
49+ while (xs_list_iter(&p, &v)) {
50+ if (xs_type(v) == XSTYPE_DICT) {
51+ char *type = xs_dict_get(v, "type");
52+ if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Person") == 0) {
53+ e_actor = xs_dict_get(v, "id");
54+
55+ if (xs_type(e_actor) == XSTYPE_STRING)
56+ break;
57+ else
58+ e_actor = NULL;
59+ }
60+ }
61+ }
62+
63+ if (e_actor != NULL)
64+ actor = e_actor;
65+ else
66+ return NULL;
67+ }
68+
69 /* ignore muted morons immediately */
70 if (user && is_muted(user, actor))
71 return NULL;
72@@ -1416,7 +1437,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
73 }
74
75 xs_html_add(post_header,
76- html_msg_icon(local ? NULL : user, msg));
77+ html_msg_icon(local ? NULL : user, actor, msg));
78
79 /** post content **/
80
81@@ -1625,7 +1646,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
82 poll);
83 }
84
85- /* add the attachments */
86+ /** attachments **/
87 v = xs_dict_get(msg, "attachment");
88
89 if (!xs_is_null(v)) { /** attachments **/
90@@ -1747,6 +1768,67 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
91 }
92 }
93
94+ /** urls (attachments from Peertube) **/
95+ v = xs_dict_get(msg, "url");
96+
97+ if (xs_type(v) == XSTYPE_LIST) {
98+ xs_list *p = v;
99+ char *url = NULL;
100+
101+ xs_debug();
102+
103+ while (url == NULL && xs_list_iter(&p, &v)) {
104+ if (xs_type(v) == XSTYPE_DICT) {
105+ char *type = xs_dict_get(v, "type");
106+
107+ if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Link") == 0) {
108+ char *mtype = xs_dict_get(v, "mediaType");
109+ xs_list *tag = xs_dict_get(v, "tag");
110+
111+ if (xs_type(mtype) == XSTYPE_STRING &&
112+ strcmp(mtype, "application/x-mpegURL") == 0 &&
113+ xs_type(tag) == XSTYPE_LIST) {
114+ /* now iterate the tag list, looking for a video URL */
115+ xs_dict *d;
116+
117+ while (url == NULL && xs_list_iter(&tag, &d)) {
118+ if (xs_type(d) == XSTYPE_DICT) {
119+ if (xs_type(mtype = xs_dict_get(d, "mediaType")) == XSTYPE_STRING &&
120+ xs_startswith(mtype, "video/")) {
121+
122+ /* this is probably it */
123+ if (xs_type(url = xs_dict_get(d, "href")) != XSTYPE_STRING)
124+ url = NULL;
125+ }
126+ }
127+ }
128+ }
129+ }
130+ }
131+ }
132+
133+ if (url != NULL) {
134+ xs_html *content_attachments = xs_html_tag("div",
135+ xs_html_attr("class", "snac-content-attachments"));
136+
137+ xs_html_add(snac_content,
138+ content_attachments);
139+
140+ xs_html_add(content_attachments,
141+ xs_html_tag("video",
142+ xs_html_attr("preload", "none"),
143+ xs_html_attr("style", "width: 100%"),
144+ xs_html_attr("class", "snac-embedded-video"),
145+ xs_html_attr("controls", NULL),
146+ xs_html_attr("src", url),
147+ xs_html_text(L("Video")),
148+ xs_html_text(": "),
149+ xs_html_tag("a",
150+ xs_html_attr("href", url),
151+ xs_html_text("---"))));
152+ }
153+ }
154+
155 /* has this message an audience (i.e., comes from a channel or community)? */
156 char *audience = xs_dict_get(msg, "audience");
157 if (strcmp(type, "Page") == 0 && !xs_is_null(audience)) {