Added some support for Peertube videos.

This commit is contained in:
default 2024-01-18 22:21:05 +01:00
parent 02998ebb59
commit f162c07791
2 changed files with 99 additions and 10 deletions

View file

@ -1732,6 +1732,13 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
if (timeline_add(snac, id, object)) if (timeline_add(snac, id, object))
snac_log(snac, xs_fmt("new 'Question' %s %s", actor, id)); snac_log(snac, xs_fmt("new 'Question' %s %s", actor, id));
} }
else
if (strcmp(utype, "Video") == 0) { /** **/
char *id = xs_dict_get(object, "id");
if (timeline_add(snac, id, object))
snac_log(snac, xs_fmt("new 'Video' %s %s", actor, id));
}
else else
snac_debug(snac, 1, xs_fmt("ignored 'Create' for object type '%s'", utype)); snac_debug(snac, 1, xs_fmt("ignored 'Create' for object type '%s'", utype));
} }

102
html.c
View file

@ -227,15 +227,11 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
} }
xs_html *html_msg_icon(snac *user, const xs_dict *msg) xs_html *html_msg_icon(snac *user, char *actor_id, const xs_dict *msg)
{ {
char *actor_id;
xs *actor = NULL; xs *actor = NULL;
xs_html *actor_icon = NULL; xs_html *actor_icon = NULL;
if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
actor_id = xs_dict_get(msg, "actor");
if (actor_id && valid_status(actor_get(actor_id, &actor))) { if (actor_id && valid_status(actor_get(actor_id, &actor))) {
char *date = NULL; char *date = NULL;
char *udate = NULL; char *udate = NULL;
@ -243,7 +239,7 @@ xs_html *html_msg_icon(snac *user, const xs_dict *msg)
int priv = 0; int priv = 0;
const char *type = xs_dict_get(msg, "type"); const char *type = xs_dict_get(msg, "type");
if (xs_match(type, "Note|Question|Page|Article")) if (xs_match(type, "Note|Question|Page|Article|Video"))
url = xs_dict_get(msg, "id"); url = xs_dict_get(msg, "id");
priv = !is_msg_public(msg); priv = !is_msg_public(msg);
@ -1268,10 +1264,10 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
xs_html_tag("div", xs_html_tag("div",
xs_html_attr("class", "snac-origin"), xs_html_attr("class", "snac-origin"),
xs_html_text(L("follows you"))), xs_html_text(L("follows you"))),
html_msg_icon(local ? NULL : user, msg))); html_msg_icon(local ? NULL : user, xs_dict_get(msg, "actor"), msg)));
} }
else else
if (!xs_match(type, "Note|Question|Page|Article")) { if (!xs_match(type, "Note|Question|Page|Article|Video")) {
/* skip oddities */ /* skip oddities */
return NULL; return NULL;
} }
@ -1284,6 +1280,31 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
if ((actor = xs_dict_get(msg, "attributedTo")) == NULL) if ((actor = xs_dict_get(msg, "attributedTo")) == NULL)
return NULL; return NULL;
/* if the actor is a list (like on Peertube videos), pick the Person */
if (xs_type(actor) == XSTYPE_LIST) {
char *e_actor = NULL;
xs_list *p = actor;
while (xs_list_iter(&p, &v)) {
if (xs_type(v) == XSTYPE_DICT) {
char *type = xs_dict_get(v, "type");
if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Person") == 0) {
e_actor = xs_dict_get(v, "id");
if (xs_type(e_actor) == XSTYPE_STRING)
break;
else
e_actor = NULL;
}
}
}
if (e_actor != NULL)
actor = e_actor;
else
return NULL;
}
/* ignore muted morons immediately */ /* ignore muted morons immediately */
if (user && is_muted(user, actor)) if (user && is_muted(user, actor))
return NULL; return NULL;
@ -1416,7 +1437,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
} }
xs_html_add(post_header, xs_html_add(post_header,
html_msg_icon(local ? NULL : user, msg)); html_msg_icon(local ? NULL : user, actor, msg));
/** post content **/ /** post content **/
@ -1625,7 +1646,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
poll); poll);
} }
/* add the attachments */ /** attachments **/
v = xs_dict_get(msg, "attachment"); v = xs_dict_get(msg, "attachment");
if (!xs_is_null(v)) { /** attachments **/ if (!xs_is_null(v)) { /** attachments **/
@ -1747,6 +1768,67 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
} }
} }
/** urls (attachments from Peertube) **/
v = xs_dict_get(msg, "url");
if (xs_type(v) == XSTYPE_LIST) {
xs_list *p = v;
char *url = NULL;
xs_debug();
while (url == NULL && xs_list_iter(&p, &v)) {
if (xs_type(v) == XSTYPE_DICT) {
char *type = xs_dict_get(v, "type");
if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Link") == 0) {
char *mtype = xs_dict_get(v, "mediaType");
xs_list *tag = xs_dict_get(v, "tag");
if (xs_type(mtype) == XSTYPE_STRING &&
strcmp(mtype, "application/x-mpegURL") == 0 &&
xs_type(tag) == XSTYPE_LIST) {
/* now iterate the tag list, looking for a video URL */
xs_dict *d;
while (url == NULL && xs_list_iter(&tag, &d)) {
if (xs_type(d) == XSTYPE_DICT) {
if (xs_type(mtype = xs_dict_get(d, "mediaType")) == XSTYPE_STRING &&
xs_startswith(mtype, "video/")) {
/* this is probably it */
if (xs_type(url = xs_dict_get(d, "href")) != XSTYPE_STRING)
url = NULL;
}
}
}
}
}
}
}
if (url != NULL) {
xs_html *content_attachments = xs_html_tag("div",
xs_html_attr("class", "snac-content-attachments"));
xs_html_add(snac_content,
content_attachments);
xs_html_add(content_attachments,
xs_html_tag("video",
xs_html_attr("preload", "none"),
xs_html_attr("style", "width: 100%"),
xs_html_attr("class", "snac-embedded-video"),
xs_html_attr("controls", NULL),
xs_html_attr("src", url),
xs_html_text(L("Video")),
xs_html_text(": "),
xs_html_tag("a",
xs_html_attr("href", url),
xs_html_text("---"))));
}
}
/* has this message an audience (i.e., comes from a channel or community)? */ /* has this message an audience (i.e., comes from a channel or community)? */
char *audience = xs_dict_get(msg, "audience"); char *audience = xs_dict_get(msg, "audience");
if (strcmp(type, "Page") == 0 && !xs_is_null(audience)) { if (strcmp(type, "Page") == 0 && !xs_is_null(audience)) {