UNPKG

social-butterfly

Version:

Incorporate federated social network protocols easily. Used with Hello, world federated blog.

75 lines (64 loc) 2.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _feed = require("./feed"); var _react = require("react"); var _server = require("react-dom/server"); var _default = options => async (req, res, next) => { const contentOwner = await options.getLocalUser(req.query.resource, req); if (!contentOwner) { return res.sendStatus(404); } const comments = await options.getRemoteCommentsOnLocalContent(req.query.resource); let renderedTree = `<?xml version='1.0' encoding='UTF-8'?>` + (0, _server.renderToString)( /*#__PURE__*/React.createElement(Comments, { contentOwner: contentOwner, comments: comments, req: req, constants: options.constants })); // XXX(mime): in the feeds I have some attributes that are `ref`. However, ref isn't allowed in React, // so in the DOM they are `refXXX`. Return them to normal here, sigh. renderedTree = renderedTree.replace(/refXXX="([^"]+)"/g, 'ref="$1"'); res.type('xml'); res.send(renderedTree); }; exports.default = _default; function Comments({ constants, req, comments, contentOwner }) { return /*#__PURE__*/React.createElement(_feed.GenericFeed, { contentOwner: contentOwner, constants: constants, req: req }, comments.map(comment => /*#__PURE__*/React.createElement(Comment, { key: comment.post_id, comment: comment, req: req }))); } function Comment({ comment, req }) { const html = '<![CDATA[' + comment.view + ']]>'; const tagDate = new Date().toISOString().slice(0, 10); const threadUrl = `tag:${req.get('host')},${tagDate}:${req.query.resource}`; return /*#__PURE__*/React.createElement("entry", null, /*#__PURE__*/React.createElement("link", { href: comment.link }), /*#__PURE__*/React.createElement("id", null, comment.post_id), /*#__PURE__*/React.createElement("author", null, /*#__PURE__*/React.createElement("name", null, comment.username), comment.from_user ? /*#__PURE__*/React.createElement("uri", null, comment.from_user) : null, /*#__PURE__*/(0, _react.createElement)('poco:photos', {}, [/*#__PURE__*/(0, _react.createElement)('poco:value', { key: 'value' }, comment.avatar), /*#__PURE__*/(0, _react.createElement)('poco:type', { key: 'type' }, 'thumbnail')])), /*#__PURE__*/React.createElement("content", { type: "html", dangerouslySetInnerHTML: { __html: html } }), /*#__PURE__*/React.createElement("published", null, new Date(comment.createdAt).toISOString().slice(0, 10)), /*#__PURE__*/(0, _react.createElement)('activity:verb', {}, `http://activitystrea.ms/schema/1.0/post`), /*#__PURE__*/(0, _react.createElement)('activity:object-type', {}, `http://activitystrea.ms/schema/1.0/comment`), /*#__PURE__*/(0, _react.createElement)('thr:in-reply-to', { refXXX: threadUrl })); }