summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2024-01-18 22:21:05 +0100
committerGravatar default2024-01-18 22:21:05 +0100
commitf162c0779192a3ea19d6aecd692993723769e64e (patch)
tree937af08250331d284451f42b7a0f5a33d40d3f65
parentVersion 2.45 RELEASED. (diff)
downloadsnac2-f162c0779192a3ea19d6aecd692993723769e64e.tar.gz
snac2-f162c0779192a3ea19d6aecd692993723769e64e.tar.xz
snac2-f162c0779192a3ea19d6aecd692993723769e64e.zip
Added some support for Peertube videos.
-rw-r--r--activitypub.c7
-rw-r--r--html.c102
2 files changed, 99 insertions, 10 deletions
diff --git a/activitypub.c b/activitypub.c
index 9928c76..2306eb5 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -1733,6 +1733,13 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
1733 snac_log(snac, xs_fmt("new 'Question' %s %s", actor, id)); 1733 snac_log(snac, xs_fmt("new 'Question' %s %s", actor, id));
1734 } 1734 }
1735 else 1735 else
1736 if (strcmp(utype, "Video") == 0) { /** **/
1737 char *id = xs_dict_get(object, "id");
1738
1739 if (timeline_add(snac, id, object))
1740 snac_log(snac, xs_fmt("new 'Video' %s %s", actor, id));
1741 }
1742 else
1736 snac_debug(snac, 1, xs_fmt("ignored 'Create' for object type '%s'", utype)); 1743 snac_debug(snac, 1, xs_fmt("ignored 'Create' for object type '%s'", utype));
1737 } 1744 }
1738 else 1745 else
diff --git a/html.c b/html.c
index 4abfa37..327a6bc 100644
--- a/html.c
+++ b/html.c
@@ -227,15 +227,11 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
227} 227}
228 228
229 229
230xs_html *html_msg_icon(snac *user, const xs_dict *msg) 230xs_html *html_msg_icon(snac *user, char *actor_id, const xs_dict *msg)
231{ 231{
232 char *actor_id;
233 xs *actor = NULL; 232 xs *actor = NULL;
234 xs_html *actor_icon = NULL; 233 xs_html *actor_icon = NULL;
235 234
236 if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
237 actor_id = xs_dict_get(msg, "actor");
238
239 if (actor_id && valid_status(actor_get(actor_id, &actor))) { 235 if (actor_id && valid_status(actor_get(actor_id, &actor))) {
240 char *date = NULL; 236 char *date = NULL;
241 char *udate = NULL; 237 char *udate = NULL;
@@ -243,7 +239,7 @@ xs_html *html_msg_icon(snac *user, const xs_dict *msg)
243 int priv = 0; 239 int priv = 0;
244 const char *type = xs_dict_get(msg, "type"); 240 const char *type = xs_dict_get(msg, "type");
245 241
246 if (xs_match(type, "Note|Question|Page|Article")) 242 if (xs_match(type, "Note|Question|Page|Article|Video"))
247 url = xs_dict_get(msg, "id"); 243 url = xs_dict_get(msg, "id");
248 244
249 priv = !is_msg_public(msg); 245 priv = !is_msg_public(msg);
@@ -1268,10 +1264,10 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
1268 xs_html_tag("div", 1264 xs_html_tag("div",
1269 xs_html_attr("class", "snac-origin"), 1265 xs_html_attr("class", "snac-origin"),
1270 xs_html_text(L("follows you"))), 1266 xs_html_text(L("follows you"))),
1271 html_msg_icon(local ? NULL : user, msg))); 1267 html_msg_icon(local ? NULL : user, xs_dict_get(msg, "actor"), msg)));
1272 } 1268 }
1273 else 1269 else
1274 if (!xs_match(type, "Note|Question|Page|Article")) { 1270 if (!xs_match(type, "Note|Question|Page|Article|Video")) {
1275 /* skip oddities */ 1271 /* skip oddities */
1276 return NULL; 1272 return NULL;
1277 } 1273 }
@@ -1284,6 +1280,31 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
1284 if ((actor = xs_dict_get(msg, "attributedTo")) == NULL) 1280 if ((actor = xs_dict_get(msg, "attributedTo")) == NULL)
1285 return NULL; 1281 return NULL;
1286 1282
1283 /* if the actor is a list (like on Peertube videos), pick the Person */
1284 if (xs_type(actor) == XSTYPE_LIST) {
1285 char *e_actor = NULL;
1286 xs_list *p = actor;
1287
1288 while (xs_list_iter(&p, &v)) {
1289 if (xs_type(v) == XSTYPE_DICT) {
1290 char *type = xs_dict_get(v, "type");
1291 if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Person") == 0) {
1292 e_actor = xs_dict_get(v, "id");
1293
1294 if (xs_type(e_actor) == XSTYPE_STRING)
1295 break;
1296 else
1297 e_actor = NULL;
1298 }
1299 }
1300 }
1301
1302 if (e_actor != NULL)
1303 actor = e_actor;
1304 else
1305 return NULL;
1306 }
1307
1287 /* ignore muted morons immediately */ 1308 /* ignore muted morons immediately */
1288 if (user && is_muted(user, actor)) 1309 if (user && is_muted(user, actor))
1289 return NULL; 1310 return NULL;
@@ -1416,7 +1437,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
1416 } 1437 }
1417 1438
1418 xs_html_add(post_header, 1439 xs_html_add(post_header,
1419 html_msg_icon(local ? NULL : user, msg)); 1440 html_msg_icon(local ? NULL : user, actor, msg));
1420 1441
1421 /** post content **/ 1442 /** post content **/
1422 1443
@@ -1625,7 +1646,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
1625 poll); 1646 poll);
1626 } 1647 }
1627 1648
1628 /* add the attachments */ 1649 /** attachments **/
1629 v = xs_dict_get(msg, "attachment"); 1650 v = xs_dict_get(msg, "attachment");
1630 1651
1631 if (!xs_is_null(v)) { /** attachments **/ 1652 if (!xs_is_null(v)) { /** attachments **/
@@ -1747,6 +1768,67 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local,
1747 } 1768 }
1748 } 1769 }
1749 1770
1771 /** urls (attachments from Peertube) **/
1772 v = xs_dict_get(msg, "url");
1773
1774 if (xs_type(v) == XSTYPE_LIST) {
1775 xs_list *p = v;
1776 char *url = NULL;
1777
1778 xs_debug();
1779
1780 while (url == NULL && xs_list_iter(&p, &v)) {
1781 if (xs_type(v) == XSTYPE_DICT) {
1782 char *type = xs_dict_get(v, "type");
1783
1784 if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Link") == 0) {
1785 char *mtype = xs_dict_get(v, "mediaType");
1786 xs_list *tag = xs_dict_get(v, "tag");
1787
1788 if (xs_type(mtype) == XSTYPE_STRING &&
1789 strcmp(mtype, "application/x-mpegURL") == 0 &&
1790 xs_type(tag) == XSTYPE_LIST) {
1791 /* now iterate the tag list, looking for a video URL */
1792 xs_dict *d;
1793
1794 while (url == NULL && xs_list_iter(&tag, &d)) {
1795 if (xs_type(d) == XSTYPE_DICT) {
1796 if (xs_type(mtype = xs_dict_get(d, "mediaType")) == XSTYPE_STRING &&
1797 xs_startswith(mtype, "video/")) {
1798
1799 /* this is probably it */
1800 if (xs_type(url = xs_dict_get(d, "href")) != XSTYPE_STRING)
1801 url = NULL;
1802 }
1803 }
1804 }
1805 }
1806 }
1807 }
1808 }
1809
1810 if (url != NULL) {
1811 xs_html *content_attachments = xs_html_tag("div",
1812 xs_html_attr("class", "snac-content-attachments"));
1813
1814 xs_html_add(snac_content,
1815 content_attachments);
1816
1817 xs_html_add(content_attachments,
1818 xs_html_tag("video",
1819 xs_html_attr("preload", "none"),
1820 xs_html_attr("style", "width: 100%"),
1821 xs_html_attr("class", "snac-embedded-video"),
1822 xs_html_attr("controls", NULL),
1823 xs_html_attr("src", url),
1824 xs_html_text(L("Video")),
1825 xs_html_text(": "),
1826 xs_html_tag("a",
1827 xs_html_attr("href", url),
1828 xs_html_text("---"))));
1829 }
1830 }
1831
1750 /* has this message an audience (i.e., comes from a channel or community)? */ 1832 /* has this message an audience (i.e., comes from a channel or community)? */
1751 char *audience = xs_dict_get(msg, "audience"); 1833 char *audience = xs_dict_get(msg, "audience");
1752 if (strcmp(type, "Page") == 0 && !xs_is_null(audience)) { 1834 if (strcmp(type, "Page") == 0 && !xs_is_null(audience)) {