activity_view.js 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  1. const { div, h2, p, section, button, form, a, input, img, textarea, br, span, video: videoHyperaxe, audio: audioHyperaxe, table, tr, td, th } = require("../server/node_modules/hyperaxe");
  2. const { template, i18n } = require('./main_views');
  3. const moment = require("../server/node_modules/moment");
  4. const { renderUrl } = require('../backend/renderUrl');
  5. const { getConfig } = require("../configs/config-manager.js");
  6. const { sanitizeHtml } = require('../backend/sanitizeHtml');
  7. const renderMediaBlob = (value, fallbackSrc = null) => {
  8. if (!value) return fallbackSrc ? img({ src: fallbackSrc }) : null
  9. const s = String(value).trim()
  10. if (!s) return fallbackSrc ? img({ src: fallbackSrc }) : null
  11. if (s.startsWith('&')) return img({ src: `/blob/${encodeURIComponent(s)}` })
  12. const mVideo = s.match(/\[video:[^\]]*\]\(\s*(&[^)\s]+\.sha256)\s*\)/)
  13. if (mVideo) return videoHyperaxe({ controls: true, class: 'post-video', src: `/blob/${encodeURIComponent(mVideo[1])}` })
  14. const mAudio = s.match(/\[audio:[^\]]*\]\(\s*(&[^)\s]+\.sha256)\s*\)/)
  15. if (mAudio) return audioHyperaxe({ controls: true, class: 'post-audio', src: `/blob/${encodeURIComponent(mAudio[1])}` })
  16. const mImg = s.match(/!\[[^\]]*\]\(\s*(&[^)\s]+\.sha256)\s*\)/)
  17. if (mImg) return img({ src: `/blob/${encodeURIComponent(mImg[1])}`, class: 'post-image' })
  18. return fallbackSrc ? img({ src: fallbackSrc }) : null
  19. }
  20. const FEED_TEXT_MIN = Number(getConfig().feed?.minLength ?? 1);
  21. const FEED_TEXT_MAX = Number(getConfig().feed?.maxLength ?? 280);
  22. function cleanFeedText(t) {
  23. return typeof t === 'string' ? t.trim() : '';
  24. }
  25. function isValidFeedText(t) {
  26. const s = cleanFeedText(t);
  27. return s.length >= FEED_TEXT_MIN && s.length <= FEED_TEXT_MAX;
  28. }
  29. function capitalize(str) {
  30. return typeof str === 'string' && str.length ? str[0].toUpperCase() + str.slice(1) : '';
  31. }
  32. function sumAmounts(list = []) {
  33. return list.reduce((s, x) => s + (parseFloat(x.amount || 0) || 0), 0);
  34. }
  35. function pickActiveParliamentTerm(terms) {
  36. if (!terms.length) return null;
  37. const now = Date.now();
  38. const getC = t => t.value?.content || t.content || {};
  39. const isActive = t => {
  40. const c = getC(t);
  41. const s = new Date(c.startAt || 0).getTime();
  42. const e = new Date(c.endAt || 0).getTime();
  43. return s && e && s <= now && now < e;
  44. };
  45. const cmp = (a, b) => {
  46. const ca = getC(a);
  47. const cb = getC(b);
  48. const aAn = String(ca.method || '').toUpperCase() === 'ANARCHY' ? 1 : 0;
  49. const bAn = String(cb.method || '').toUpperCase() === 'ANARCHY' ? 1 : 0;
  50. if (aAn !== bAn) return aAn - bAn;
  51. const aC = new Date(ca.createdAt || ca.startAt || 0).getTime();
  52. const bC = new Date(cb.createdAt || cb.startAt || 0).getTime();
  53. if (aC !== bC) return aC - bC;
  54. const aS = new Date(ca.startAt || 0).getTime();
  55. const bS = new Date(cb.startAt || 0).getTime();
  56. if (aS !== bS) return aS - bS;
  57. return String(a.id || '').localeCompare(String(b.id || ''));
  58. };
  59. const active = terms.filter(isActive);
  60. if (active.length) return active.sort(cmp)[0];
  61. return terms.sort(cmp)[0];
  62. }
  63. function safeMsgId(x) {
  64. if (typeof x === 'string') return x;
  65. if (x && typeof x === 'object') return x.key || x.id || x.link || '';
  66. return '';
  67. }
  68. function normalizeSpreadLink(x) {
  69. const s = safeMsgId(x);
  70. return typeof s === 'string' && s.startsWith('thread:') ? s.slice(7) : s;
  71. }
  72. function stripHtml(s) {
  73. return String(s || '')
  74. .replace(/<[^>]*>/g, ' ')
  75. .replace(/\s+/g, ' ')
  76. .trim();
  77. }
  78. function excerptPostText(content, max = 220) {
  79. const raw = stripHtml(content?.text || content?.description || content?.title || '');
  80. if (!raw) return '';
  81. return raw.length > max ? raw.slice(0, max - 1) + '…' : raw;
  82. }
  83. const decodeMaybe = (s) => {
  84. try { return decodeURIComponent(String(s || '')); } catch { return String(s || ''); }
  85. };
  86. const rewriteHashtagLinks = (html) => {
  87. const s = String(html || '');
  88. return s.replace(/href=(["'])(?:https?:\/\/[^"']+)?\/hashtag\/([^"'?#]+)([^"']*)\1/g, (m, q, tag, rest) => {
  89. const t = decodeMaybe(tag).replace(/^#/, '').trim().toLowerCase();
  90. const href = `/search?query=%23${encodeURIComponent(t)}`;
  91. return `href=${q}${href}${q}`;
  92. });
  93. };
  94. function renderUrlPreserveNewlines(text) {
  95. const s = String(text || '');
  96. const lines = s.split(/\r\n|\r|\n/);
  97. const out = [];
  98. for (let i = 0; i < lines.length; i++) {
  99. if (i) out.push(br());
  100. out.push(...renderUrl(lines[i]));
  101. }
  102. return out;
  103. }
  104. function getThreadIdFromPost(action) {
  105. const c = action.value?.content || action.content || {};
  106. const fork = safeMsgId(c.fork);
  107. const root = safeMsgId(c.root);
  108. return fork || root || safeMsgId(action);
  109. }
  110. function getReplyToIdFromPost(action, byId) {
  111. const c = action.value?.content || action.content || {};
  112. const root = safeMsgId(c.root);
  113. const branch = Array.isArray(c.branch) ? c.branch.filter(x => typeof x === 'string') : [];
  114. let best = '';
  115. let bestTs = -1;
  116. for (const id of branch) {
  117. const a = byId.get(id);
  118. if (a && (a.ts || 0) > bestTs) { best = id; bestTs = a.ts || 0; }
  119. }
  120. return best || root || '';
  121. }
  122. function buildActivityItemsWithPostThreads(deduped, allActions) {
  123. const byId = new Map();
  124. for (const a of allActions) {
  125. const id = safeMsgId(a);
  126. if (id) byId.set(id, a);
  127. }
  128. for (const a of deduped) {
  129. const id = safeMsgId(a);
  130. if (id) byId.set(id, a);
  131. }
  132. const groups = new Map();
  133. const out = [];
  134. for (const a of deduped) {
  135. if (a.type !== 'post') {
  136. out.push(a);
  137. continue;
  138. }
  139. const threadId = getThreadIdFromPost(a);
  140. if (!groups.has(threadId)) groups.set(threadId, []);
  141. groups.get(threadId).push(a);
  142. }
  143. for (const [threadId, posts] of groups.entries()) {
  144. const sortedDesc = posts.slice().sort((a, b) => (b.ts || 0) - (a.ts || 0));
  145. const hasReplies = sortedDesc.some(p => getThreadIdFromPost(p) !== safeMsgId(p)) || sortedDesc.length > 1;
  146. if (!hasReplies || sortedDesc.length === 1) {
  147. out.push(sortedDesc[0]);
  148. continue;
  149. }
  150. const latest = sortedDesc[0];
  151. let rootAction = byId.get(threadId);
  152. let rootId = threadId;
  153. if (!rootAction) {
  154. const asc = posts.slice().sort((a, b) => (a.ts || 0) - (b.ts || 0));
  155. rootAction = asc[0] || null;
  156. rootId = safeMsgId(rootAction) || threadId;
  157. } else {
  158. rootId = safeMsgId(rootAction) || threadId;
  159. }
  160. const replies = sortedDesc
  161. .filter(p => safeMsgId(p) !== rootId)
  162. .slice()
  163. .sort((a, b) => (a.ts || 0) - (b.ts || 0));
  164. out.push({
  165. id: `thread:${threadId}`,
  166. type: 'postThread',
  167. author: latest.author,
  168. ts: latest.ts,
  169. content: {
  170. threadId,
  171. root: rootAction
  172. ? {
  173. id: safeMsgId(rootAction),
  174. author: rootAction.author,
  175. text: excerptPostText(rootAction.value?.content || rootAction.content || {}, 240)
  176. }
  177. : null,
  178. replies: replies.map(p => ({
  179. id: safeMsgId(p),
  180. author: p.author,
  181. ts: p.ts,
  182. text: excerptPostText(p.value?.content || p.content || {}, 200)
  183. }))
  184. }
  185. });
  186. }
  187. out.sort((a, b) => (b.ts || 0) - (a.ts || 0));
  188. return out;
  189. }
  190. function renderActionCards(actions, userId, allActions) {
  191. const all = Array.isArray(allActions) ? allActions : actions;
  192. const byIdAll = new Map();
  193. for (const a0 of all) {
  194. const id0 = safeMsgId(a0);
  195. if (id0) byIdAll.set(id0, a0);
  196. }
  197. const profileById = new Map();
  198. for (const a0 of all) {
  199. if (!a0 || a0.type !== 'about') continue;
  200. const c0 = a0.value?.content || a0.content || {};
  201. const id0 = c0.about || a0.author || '';
  202. if (!id0) continue;
  203. const name0 = (typeof c0.name === 'string' && c0.name.trim()) ? c0.name.trim() : id0;
  204. const image0 = (typeof c0.image === 'string' && c0.image.trim()) ? c0.image.trim() : '';
  205. const ts0 = a0.ts || 0;
  206. const prev = profileById.get(id0);
  207. if (!prev) {
  208. profileById.set(id0, { id: id0, name: name0, image: image0, ts: ts0 });
  209. continue;
  210. }
  211. const prevHasImg = !!prev.image;
  212. const newHasImg = !!image0;
  213. if (!prevHasImg && newHasImg) profileById.set(id0, { id: id0, name: name0, image: image0, ts: ts0 });
  214. else if (prevHasImg === newHasImg && ts0 > (prev.ts || 0)) profileById.set(id0, { id: id0, name: name0, image: image0, ts: ts0 });
  215. }
  216. const getProfile = (id) => {
  217. const p0 = profileById.get(id);
  218. return p0 ? { id: p0.id, name: p0.name, image: p0.image } : { id, name: id, image: '' };
  219. };
  220. const validActions = actions
  221. .filter(action => {
  222. const content = action.value?.content || action.content;
  223. if (!content || typeof content !== 'object') return false;
  224. if (content.type === 'tombstone') return false;
  225. if (content.type === 'post' && content.private === true) return false;
  226. if (content.type === 'task' && content.isPublic === "PRIVATE") return false;
  227. if (content.type === 'event' && content.isPublic === "private") return false;
  228. if ((content.type === 'feed' || action.type === 'feed') && !isValidFeedText(content.text)) return false;
  229. if (content.type === 'market') {
  230. if (content.stock === 0 && content.status !== 'SOLD') {
  231. return false;
  232. }
  233. }
  234. return true;
  235. })
  236. .sort((a, b) => b.ts - a.ts);
  237. const terms = validActions.filter(a => a.type === 'parliamentTerm');
  238. let chosenTerm = null;
  239. if (terms.length) chosenTerm = pickActiveParliamentTerm(terms);
  240. const deduped = chosenTerm
  241. ? validActions.filter(a => a.type !== 'parliamentTerm' || a === chosenTerm)
  242. : validActions;
  243. if (!deduped.length) {
  244. return div({ class: "no-actions" }, p(i18n.noActions));
  245. }
  246. const seenDocumentTitles = new Set();
  247. const items = buildActivityItemsWithPostThreads(deduped, all);
  248. const spreadOrdinalById = new Map();
  249. const spreadsByLink = new Map();
  250. for (const a of all) {
  251. if (!a || a.type !== 'spread') continue;
  252. const c = a.value?.content || a.content || {};
  253. const link = normalizeSpreadLink(c.spreadTargetId || c.vote?.link || '');
  254. const aId = safeMsgId(a);
  255. if (!link || !aId) continue;
  256. if (!spreadsByLink.has(link)) spreadsByLink.set(link, []);
  257. spreadsByLink.get(link).push(a);
  258. }
  259. for (const list of spreadsByLink.values()) {
  260. list.sort((a, b) => (a.ts || 0) - (b.ts || 0) || String(safeMsgId(a) || '').localeCompare(String(safeMsgId(b) || '')));
  261. for (let i = 0; i < list.length; i++) {
  262. spreadOrdinalById.set(safeMsgId(list[i]), i + 1);
  263. }
  264. }
  265. const shopTitleById = new Map();
  266. for (const a of all) {
  267. if (!a || a.type !== 'shop') continue;
  268. const c = a.value?.content || a.content || {};
  269. const id = a.id || a.key || '';
  270. if (id && c.title) {
  271. shopTitleById.set(id, c.title);
  272. if (a.rootId) shopTitleById.set(a.rootId, c.title);
  273. }
  274. }
  275. const cards = items.map(action => {
  276. const date = action.ts ? new Date(action.ts).toLocaleString() : "";
  277. const userLink = action.author
  278. ? a({ href: `/author/${encodeURIComponent(action.author)}` }, action.author)
  279. : 'unknown';
  280. const type = action.type || 'unknown';
  281. let skip = false;
  282. let headerText;
  283. if (type.startsWith('parliament')) {
  284. const sub = type.replace('parliament', '');
  285. headerText = `[PARLIAMENT · ${sub.toUpperCase()}]`;
  286. } else if (type.startsWith('courts')) {
  287. const rawSub = type.slice('courts'.length);
  288. const pretty = rawSub
  289. .replace(/^[_\s]+/, '')
  290. .replace(/[_\s]+/g, ' · ')
  291. .replace(/([a-z])([A-Z])/g, '$1 · $2');
  292. const finalSub = pretty || 'EVENT';
  293. headerText = `[COURTS · ${finalSub.toUpperCase()}]`;
  294. } else if (type === 'taskAssignment') {
  295. headerText = `[${String(i18n.typeTask || 'TASK').toUpperCase()} · ASSIGNMENT]`;
  296. } else if (type === 'shopProduct') {
  297. headerText = `[SHOP · PRODUCT]`;
  298. } else if (type === 'chat') {
  299. headerText = `[CHAT \u00b7 NEW]`;
  300. } else if (type === 'pad') {
  301. headerText = `[PAD · ${String(i18n.padNew || 'NEW').toUpperCase()}]`;
  302. } else if (type === 'ubiClaim') {
  303. headerText = `[UBI · CLAIM]`;
  304. } else if (type === 'ubiclaimresult') {
  305. headerText = `[UBI · RESULT]`;
  306. } else {
  307. const typeLabel = i18n[`type${capitalize(type)}`] || type;
  308. headerText = `[${String(typeLabel).toUpperCase()}]`;
  309. }
  310. const content = action.value?.content || action.content || {};
  311. const cardBody = [];
  312. if (type === 'votes') {
  313. const { question, deadline, status, votes, totalVotes } = content;
  314. const commentCount =
  315. typeof action.commentCount === 'number'
  316. ? action.commentCount
  317. : (typeof content.commentCount === 'number' ? content.commentCount : 0);
  318. const votesList = votes && typeof votes === 'object'
  319. ? Object.entries(votes).map(([option, count]) => ({ option, count }))
  320. : [];
  321. cardBody.push(
  322. div({ class: 'card-section votes' },
  323. div(
  324. { class: 'card-field' },
  325. span({ class: 'card-label' }, i18n.question + ':'),
  326. span({ class: 'card-value' }, question)
  327. ),
  328. div(
  329. { class: 'card-field' },
  330. span({ class: 'card-label' }, i18n.deadline + ':'),
  331. span({ class: 'card-value' }, deadline ? new Date(deadline).toLocaleString() : '')
  332. ),
  333. div(
  334. { class: 'card-field' },
  335. span({ class: 'card-label' }, i18n.voteTotalVotes + ':'),
  336. span({ class: 'card-value' }, totalVotes)
  337. ),
  338. div(
  339. { class: 'card-field' },
  340. span({ class: 'card-label' }, i18n.voteCommentsLabel + ':'),
  341. span({ class: 'card-value' }, String(commentCount))
  342. ),
  343. table(
  344. tr(...votesList.map(({ option }) => th(i18n[option] || option))),
  345. tr(...votesList.map(({ count }) => td(count)))
  346. )
  347. )
  348. );
  349. }
  350. if (type === 'transfer') {
  351. const { from, to, concept, amount, deadline, status, confirmedBy } = content;
  352. cardBody.push(
  353. div({ class: 'card-section transfer' },
  354. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.concept + ':'), span({ class: 'card-value' }, concept)),
  355. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.amount + ':'), span({ class: 'card-value' }, amount)),
  356. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.deadline + ':'), span({ class: 'card-value' }, deadline ? new Date(deadline).toLocaleString() : '')),
  357. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.status + ':'), span({ class: 'card-value' }, status))
  358. )
  359. );
  360. }
  361. if (type === 'bankWallet') {
  362. const { address } = content;
  363. cardBody.push(
  364. div({ class: 'card-section banking-wallet' },
  365. div({ class: 'card-field' },
  366. span({ class: 'card-label' }, i18n.bankWalletConnected + ':' ),
  367. span({ class: 'card-value' }, address)
  368. )
  369. )
  370. );
  371. }
  372. if (type === 'bankClaim') {
  373. const { amount, epochId, allocationId, txid } = content;
  374. const amt = Number(amount || 0);
  375. cardBody.push(
  376. div({ class: 'card-section banking-claim' },
  377. div({ class: 'card-field' },
  378. span({ class: 'card-label' }, i18n.bankUbiReceived + ':' ),
  379. span({ class: 'card-value' }, `${amt.toFixed(6)} ECO`)
  380. ),
  381. epochId ? div({ class: 'card-field' },
  382. span({ class: 'card-label' }, i18n.bankEpochShort + ':' ),
  383. span({ class: 'card-value' }, epochId)
  384. ) : "",
  385. allocationId ? div({ class: 'card-field' },
  386. span({ class: 'card-label' }, i18n.bankAllocId + ':' ),
  387. span({ class: 'card-value' }, allocationId)
  388. ) : "",
  389. txid ? div({ class: 'card-field' },
  390. span({ class: 'card-label' }, i18n.bankTx + ':' ),
  391. a({ href: `https://ecoin.03c8.net/blockexplorer/search?q=${txid}`, target: '_blank' }, txid)
  392. ) : ""
  393. )
  394. );
  395. }
  396. if (type === 'ubiClaim') {
  397. const { pubId, amount, epochId, claimedAt } = content;
  398. const amt = Number(amount || 0);
  399. const inhabitantId = action.author || '';
  400. cardBody.push(
  401. div({ class: 'card-section banking-ubi' },
  402. div({ class: 'card-field' },
  403. span({ class: 'card-label' }, i18n.bankUbiInhabitant + ':'),
  404. span({ class: 'card-value' }, a({ href: `/author/${encodeURIComponent(inhabitantId)}`, class: 'user-link' }, inhabitantId))
  405. ),
  406. pubId ? div({ class: 'card-field' },
  407. span({ class: 'card-label' }, i18n.bankUbiPub + ':'),
  408. span({ class: 'card-value' }, a({ href: `/author/${encodeURIComponent(pubId)}`, class: 'user-link' }, pubId))
  409. ) : "",
  410. div({ class: 'card-field' },
  411. span({ class: 'card-label' }, i18n.bankUbiClaimedAmount + ':'),
  412. span({ class: 'card-value' }, `${amt.toFixed(6)} ECO`)
  413. ),
  414. epochId ? div({ class: 'card-field' },
  415. span({ class: 'card-label' }, i18n.bankEpochShort + ':'),
  416. span({ class: 'card-value' }, epochId)
  417. ) : "",
  418. div({ class: 'card-field' },
  419. span({ class: 'card-label' }, i18n.status + ':'),
  420. span({ class: 'card-value' }, 'UNCONFIRMED')
  421. ),
  422. claimedAt ? div({ class: 'card-field' },
  423. span({ class: 'card-label' }, i18n.date + ':'),
  424. span({ class: 'card-value' }, moment(claimedAt).format('YYYY-MM-DD HH:mm:ss'))
  425. ) : ""
  426. )
  427. );
  428. }
  429. if (type === 'ubiclaimresult') {
  430. const { txid, userId: inhabitantId, amount, epochId } = content;
  431. const pubAuthor = action.author || action.value?.author || '';
  432. const amt = Number(amount || 0);
  433. cardBody.push(
  434. div({ class: 'card-section banking-ubi' },
  435. div({ class: 'card-field' },
  436. span({ class: 'card-label' }, i18n.bankUbiPub + ':'),
  437. span({ class: 'card-value' }, pubAuthor)
  438. ),
  439. div({ class: 'card-field' },
  440. span({ class: 'card-label' }, i18n.bankUbiInhabitant + ':'),
  441. span({ class: 'card-value' }, inhabitantId || '')
  442. ),
  443. div({ class: 'card-field' },
  444. span({ class: 'card-label' }, i18n.bankUbiClaimedAmount + ':'),
  445. span({ class: 'card-value' }, `${amt.toFixed(6)} ECO`)
  446. ),
  447. txid ? div({ class: 'card-field' },
  448. span({ class: 'card-label' }, i18n.bankTx + ':'),
  449. a({ href: `https://ecoin.03c8.net/blockexplorer/search?q=${txid}`, target: '_blank' }, txid)
  450. ) : ""
  451. )
  452. );
  453. }
  454. if (type === 'pixelia') {
  455. const { author } = content;
  456. cardBody.push(
  457. div({ class: 'card-section pixelia' },
  458. div({ class: 'card-field' },
  459. a({ href: `/author/${encodeURIComponent(author)}`, class: 'activityVotePost' }, author)
  460. )
  461. )
  462. );
  463. }
  464. if (type === 'tribe') {
  465. const { title, image, description, location, tags, isLARP, inviteMode, isAnonymous, members } = content;
  466. const validTags = Array.isArray(tags) ? tags : [];
  467. cardBody.push(
  468. div({ class: 'card-section tribe' },
  469. h2({ class: 'tribe-title' },
  470. a({ href: `/tribe/${encodeURIComponent(action.id)}`, class: "user-link" }, title)
  471. ),
  472. div({ style: 'display:flex; gap:.6em; flex-wrap:wrap;' },
  473. location ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.tribeLocationLabel.toUpperCase()) + ':'), span({ class: 'card-value' }, ...renderUrl(location))) : "",
  474. typeof isAnonymous === 'boolean' ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.tribeIsAnonymousLabel+ ':'), span({ class: 'card-value' }, isAnonymous ? i18n.tribePrivate : i18n.tribePublic)) : "",
  475. inviteMode ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.tribeModeLabel) + ':'), span({ class: 'card-value' }, inviteMode.toUpperCase())) : "",
  476. typeof isLARP === 'boolean' ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.tribeLARPLabel+ ':'), span({ class: 'card-value' }, isLARP ? i18n.tribeYes : i18n.tribeNo)) : ""
  477. ),
  478. Array.isArray(members) ? h2(`${i18n.tribeMembersCount}: ${members.length}`) : "",
  479. image
  480. ? renderMediaBlob(image, '/assets/images/default-tribe.png')
  481. : img({ src: '/assets/images/default-tribe.png', class: 'feed-image tribe-image' }),
  482. p({ class: 'tribe-description' }, ...renderUrl(description || '')),
  483. validTags.length
  484. ? div({ class: 'card-tags' }, validTags.map(tag =>
  485. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: "tag-link" }, `#${tag}`)))
  486. : ""
  487. )
  488. );
  489. }
  490. if (type === 'curriculum') {
  491. const { author, name, description, photo, personalSkills, oasisSkills, educationalSkills, languages, professionalSkills, status, preferences, createdAt, updatedAt} = content;
  492. cardBody.push(
  493. div({ class: 'card-section curriculum' },
  494. h2(a({ href: `/author/${encodeURIComponent(author)}`, class: "user-link" }, `@`, name)),
  495. div(
  496. { class: 'card-fields-container' },
  497. createdAt ?
  498. div(
  499. { class: 'card-field' },
  500. span({ class: 'card-label' }, i18n.cvCreatedAt + ':'),
  501. span({ class: 'card-value' }, moment(createdAt).format('YYYY-MM-DD HH:mm:ss'))
  502. )
  503. : "",
  504. updatedAt ?
  505. div(
  506. { class: 'card-field' },
  507. span({ class: 'card-label' }, i18n.cvUpdatedAt + ':'),
  508. span({ class: 'card-value' }, moment(updatedAt).format('YYYY-MM-DD HH:mm:ss'))
  509. )
  510. : ""
  511. ),
  512. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.cvStatusLabel + ':'), span({ class: 'card-value' }, status)) : "",
  513. preferences ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.cvPreferencesLabel || 'Preferences') + ':'), span({ class: 'card-value' }, preferences)) : "",
  514. languages ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.cvLanguagesLabel || 'Languages') + ':'), span({ class: 'card-value' }, languages.toUpperCase())) : "",
  515. photo ?
  516. [
  517. br(),
  518. img({ class: "cv-photo", src: `/blob/${encodeURIComponent(photo)}` }),
  519. br()
  520. ]
  521. : "",
  522. p(...renderUrl(description || "")),
  523. personalSkills && personalSkills.length
  524. ? div({ class: 'card-tags' }, personalSkills.map(skill =>
  525. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  526. )) : "",
  527. oasisSkills && oasisSkills.length
  528. ? div({ class: 'card-tags' }, oasisSkills.map(skill =>
  529. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  530. )) : "",
  531. educationalSkills && educationalSkills.length
  532. ? div({ class: 'card-tags' }, educationalSkills.map(skill =>
  533. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  534. )) : "",
  535. professionalSkills && professionalSkills.length
  536. ? div({ class: 'card-tags' }, professionalSkills.map(skill =>
  537. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  538. )) : ""
  539. )
  540. );
  541. }
  542. if (type === 'image') {
  543. const { url } = content;
  544. cardBody.push(
  545. div({ class: 'card-section image' },
  546. img({ src: `/blob/${encodeURIComponent(url)}`, class: 'post-image' })
  547. )
  548. );
  549. }
  550. if (type === 'map') {
  551. const { lat, lng, mapType } = content;
  552. cardBody.push(
  553. div({ class: 'card-section map' },
  554. div({ class: 'map-card-info' },
  555. span({ class: 'map-type-badge' }, mapType || 'SINGLE'),
  556. span({ class: 'map-coords' }, `${(parseFloat(lat) || 0).toFixed(4)}, ${(parseFloat(lng) || 0).toFixed(4)}`)
  557. ),
  558. content.description ? p({ class: 'map-description' }, content.description) : ""
  559. )
  560. );
  561. }
  562. if (type === 'mapMarker') {
  563. const { lat, lng, label, mapId } = content;
  564. cardBody.push(
  565. div({ class: 'card-section map' },
  566. span({ class: 'map-marker-dot' }, "●"),
  567. span(label || i18n.mapMarkerDefault || 'Marker'),
  568. span({ class: 'map-marker-coords' }, ` (${(parseFloat(lat) || 0).toFixed(2)}, ${(parseFloat(lng) || 0).toFixed(2)})`)
  569. )
  570. );
  571. }
  572. if (type === 'audio') {
  573. const { url, mimeType, title } = content;
  574. cardBody.push(
  575. div({ class: 'card-section audio' },
  576. title?.trim() ? h2({ class: 'audio-title' }, title) : "",
  577. url
  578. ? div({ class: "audio-container" },
  579. audioHyperaxe({
  580. controls: true,
  581. src: `/blob/${encodeURIComponent(url)}`,
  582. type: mimeType
  583. })
  584. )
  585. : p(i18n.audioNoFile)
  586. )
  587. );
  588. }
  589. if (type === 'video') {
  590. const { url, mimeType, title } = content;
  591. cardBody.push(
  592. div({ class: 'card-section video' },
  593. title?.trim() ? h2({ class: 'video-title' }, title) : "",
  594. url
  595. ? div({ class: "video-container" },
  596. videoHyperaxe({
  597. controls: true,
  598. src: `/blob/${encodeURIComponent(url)}`,
  599. type: mimeType,
  600. preload: 'metadata',
  601. width: '640',
  602. height: '360'
  603. })
  604. )
  605. : p(i18n.videoNoFile)
  606. )
  607. );
  608. }
  609. if (type === 'torrent') {
  610. const { title } = content;
  611. cardBody.push(
  612. div({ class: 'card-section' },
  613. title ? div({ class: 'card-field' },
  614. span({ class: 'card-label' }, (i18n.torrentTitleLabel || 'Title') + ':'),
  615. span({ class: 'card-value' }, title)
  616. ) : null
  617. )
  618. );
  619. }
  620. if (type === 'document') {
  621. const { url, title, key } = content;
  622. if (title && seenDocumentTitles.has(title.trim())) {
  623. return null;
  624. }
  625. if (title) seenDocumentTitles.add(title.trim());
  626. cardBody.push(
  627. div({ class: 'card-section document' },
  628. title?.trim() ? h2({ class: 'document-title' }, title) : "",
  629. div({
  630. id: `pdf-container-${key || url}`,
  631. class: 'pdf-viewer-container',
  632. 'data-pdf-url': `/blob/${encodeURIComponent(url)}`
  633. })
  634. )
  635. );
  636. }
  637. if (type === 'bookmark') {
  638. const { url } = content;
  639. cardBody.push(
  640. div({ class: 'card-section bookmark' },
  641. h2(url ? p(a({ href: url, target: '_blank', class: "bookmark-url" }, url)) : "")
  642. )
  643. );
  644. }
  645. if (type === 'event') {
  646. const { title, description, date, location, price, attendees, organizer, isPublic } = content;
  647. cardBody.push(
  648. div({ class: 'card-section event' },
  649. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, title)),
  650. date ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.date + ':'), span({ class: 'card-value' }, new Date(date).toLocaleString())) : "",
  651. location ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.location || 'Location') + ':'), span({ class: 'card-value' }, location)) : "",
  652. typeof isPublic === 'boolean' ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.isPublic || 'Public') + ':'), span({ class: 'card-value' }, isPublic ? 'Yes' : 'No')) : "",
  653. price ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.price || 'Price') + ':'), span({ class: 'card-value' }, price + " ECO")) : "",
  654. br(),
  655. organizer ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.organizer || 'Organizer') + ': '), a({ class: "user-link", href: `/author/${encodeURIComponent(organizer)}` }, organizer)) : "",
  656. Array.isArray(attendees) ? h2({ class: 'card-label' }, (i18n.attendees || 'Attendees') + ': ' + attendees.length) : ""
  657. )
  658. );
  659. }
  660. if (type === 'task') {
  661. const { title, startTime, endTime, priority, status, author } = content;
  662. cardBody.push(
  663. div({ class: 'card-section task' },
  664. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, title)),
  665. priority ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.priority || 'Priority') + ':'), span({ class: 'card-value' }, priority)) : "",
  666. startTime ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.taskStartTimeLabel || 'Start') + ':'), span({ class: 'card-value' }, new Date(startTime).toLocaleString())) : "",
  667. endTime ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.taskEndTimeLabel || 'End') + ':'), span({ class: 'card-value' }, new Date(endTime).toLocaleString())) : "",
  668. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.status + ':'), span({ class: 'card-value' }, status)) : ""
  669. )
  670. );
  671. }
  672. if (type === 'taskAssignment') {
  673. const { title, added, removed } = content || {};
  674. const addList = Array.isArray(added) ? added : [];
  675. const remList = Array.isArray(removed) ? removed : [];
  676. const renderUserList = (ids) =>
  677. ids.map((id, i) => [i > 0 ? ', ' : '', a({ class: 'user-link', href: `/author/${encodeURIComponent(id)}` }, id)]).flat();
  678. cardBody.push(
  679. div({ class: 'card-section task' },
  680. div({ class: 'card-field' },
  681. span({ class: 'card-label' }, i18n.title + ':'),
  682. span({ class: 'card-value' }, title || '')
  683. ),
  684. addList.length
  685. ? div({ class: 'card-field' },
  686. span({ class: 'card-label' }, (i18n.taskAssignedTo || 'Assigned to') + ':'),
  687. span({ class: 'card-value' }, ...renderUserList(addList))
  688. )
  689. : '',
  690. remList.length
  691. ? div({ class: 'card-field' },
  692. span({ class: 'card-label' }, (i18n.taskUnassignedFrom || 'Unassigned from') + ':'),
  693. span({ class: 'card-value' }, ...renderUserList(remList))
  694. )
  695. : ''
  696. )
  697. );
  698. }
  699. if (type === 'feed') {
  700. const { renderTextWithStyles } = require('../backend/renderTextWithStyles');
  701. const { text, refeeds } = content;
  702. if (!isValidFeedText(text)) return null;
  703. const safeText = cleanFeedText(text);
  704. const htmlText = safeText ? rewriteHashtagLinks(renderTextWithStyles(safeText)) : '';
  705. const refeedsNum = Number(refeeds || 0) || 0;
  706. cardBody.push(
  707. div({ class: 'card-section feed' },
  708. div({ class: 'feed-text', innerHTML: sanitizeHtml(htmlText) }),
  709. refeedsNum > 0
  710. ? h2({ class: 'card-field' },
  711. span({ class: 'card-label' }, i18n.tribeFeedRefeeds + ': '),
  712. span({ class: 'card-label' }, String(refeedsNum))
  713. )
  714. : null
  715. )
  716. );
  717. }
  718. if (type === 'post') {
  719. const { contentWarning, text } = content || {};
  720. const rawText = text || '';
  721. const POST_TRUNCATE_LEN = 300;
  722. const isTruncated = rawText.length > POST_TRUNCATE_LEN;
  723. const displayText = isTruncated ? rawText.slice(0, POST_TRUNCATE_LEN) + '…' : rawText;
  724. const isHtml = typeof displayText === 'string' && /<\/?[a-z][\s\S]*>/i.test(displayText);
  725. let bodyNode;
  726. if (isHtml) {
  727. const hasAnchor = /<a\b[^>]*>/i.test(displayText);
  728. const linkified = hasAnchor
  729. ? displayText
  730. : displayText.replace(
  731. /(https?:\/\/[^\s<]+)/g,
  732. (url) =>
  733. `<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`
  734. );
  735. bodyNode = div({ class: 'post-text', style: 'max-height:180px;overflow:hidden;', innerHTML: sanitizeHtml(linkified) });
  736. } else {
  737. bodyNode = p({ class: 'post-text post-text-pre', style: 'max-height:180px;overflow:hidden;' }, ...renderUrlPreserveNewlines(displayText));
  738. }
  739. const threadId = getThreadIdFromPost(action);
  740. const replyToId = getReplyToIdFromPost(action, byIdAll);
  741. const isReply = !!(threadId && threadId !== action.id);
  742. const ctxHref = isReply ? `/thread/${encodeURIComponent(threadId)}#${encodeURIComponent(replyToId || threadId)}` : '';
  743. const parent = isReply ? (byIdAll.get(replyToId) || byIdAll.get(threadId)) : null;
  744. const parentContent = parent ? (parent.value?.content || parent.content || {}) : {};
  745. const parentAuthor = parent?.author || '';
  746. const parentName = parent?.authorName || parentAuthor;
  747. const parentText = parent ? excerptPostText(parentContent, 220) : '';
  748. cardBody.push(
  749. div({ class: 'card-section post' },
  750. isReply
  751. ? div(
  752. { class: 'reply-context', style: 'border-left:3px solid #666;padding-left:10px;margin-bottom:8px;opacity:0.85;' },
  753. span({ style: 'font-size:0.85em;' },
  754. a({ href: ctxHref, class: 'tag-link' }, i18n.inReplyTo || 'IN REPLY TO'),
  755. parentAuthor ? span(' ', a({ href: `/author/${encodeURIComponent(parentAuthor)}`, class: 'user-link', style: 'font-weight:bold;' }, parentName)) : ''
  756. ),
  757. parentText ? p({ class: 'post-text reply-context-text post-text-pre', style: 'font-size:0.85em;max-height:80px;overflow:hidden;margin-top:4px;' }, ...renderUrlPreserveNewlines(parentText)) : ''
  758. )
  759. : '',
  760. contentWarning ? h2({ class: 'content-warning' }, contentWarning) : '',
  761. bodyNode,
  762. isTruncated && threadId
  763. ? div({ style: 'margin-top:6px;' },
  764. a({ href: `/thread/${encodeURIComponent(threadId)}#${encodeURIComponent(action.id || threadId)}`, class: 'filter-btn' }, i18n.keepReading || 'Keep reading...')
  765. )
  766. : ''
  767. )
  768. );
  769. }
  770. if (type === 'postThread') {
  771. const c = action.content || {};
  772. const threadId = c.threadId;
  773. const href = `/thread/${encodeURIComponent(threadId)}#${encodeURIComponent(threadId)}`;
  774. const root = c.root;
  775. const replies = Array.isArray(c.replies) ? c.replies : [];
  776. const repliesAsc = replies.slice().sort((a, b) => (a.ts || 0) - (b.ts || 0));
  777. const limit = 5;
  778. const overflow = repliesAsc.length > limit;
  779. const show = repliesAsc.slice(Math.max(0, repliesAsc.length - limit));
  780. const lastId = repliesAsc.length ? repliesAsc[repliesAsc.length - 1].id : threadId;
  781. const viewMoreHref = `/thread/${encodeURIComponent(threadId)}#${encodeURIComponent(lastId)}`;
  782. return div({ class: 'card card-rpg post-thread' },
  783. div({ class: 'card-header' },
  784. h2({ class: 'card-label' }, `[${String(i18n.typePost || 'POST').toUpperCase()} · THREAD]`),
  785. form({ method: 'GET', action: href },
  786. button({ type: 'submit', class: 'filter-btn' }, i18n.viewDetails)
  787. )
  788. ),
  789. div({ class: 'card-body' },
  790. root && root.text
  791. ? div({ class: 'card-section' },
  792. p({ class: 'post-text', style: 'white-space:pre-wrap;' }, ...renderUrlPreserveNewlines(root.text))
  793. )
  794. : '',
  795. div({ class: 'card-section' },
  796. show.map(r => {
  797. const commentHref = `/thread/${encodeURIComponent(threadId)}#${encodeURIComponent(r.id)}`;
  798. const rDate = r.ts ? new Date(r.ts).toLocaleString() : '';
  799. return div({ class: 'thread-reply-item' },
  800. div({ class: 'thread-reply' },
  801. r.text ? p({ class: 'post-text', style: 'white-space:pre-wrap;' }, ...renderUrlPreserveNewlines(r.text)) : ''
  802. ),
  803. div({ class: 'card-footer thread-reply-footer' },
  804. span({ class: 'date-link' }, rDate),
  805. a({ href: `/author/${encodeURIComponent(r.author)}`, class: 'user-link' }, `${r.author}`),
  806. form({ method: 'GET', action: commentHref, class: 'inline-form' },
  807. button({ type: 'submit', class: 'filter-btn' }, i18n.viewDetails)
  808. )
  809. )
  810. );
  811. }),
  812. )
  813. ),
  814. p({ class: 'card-footer' },
  815. span({ class: 'date-link' }, `${action.ts ? new Date(action.ts).toLocaleString() : ''} ${i18n.performed} `),
  816. a({ href: `/author/${encodeURIComponent(action.author)}`, class: 'user-link' }, `${action.author}`)
  817. )
  818. );
  819. }
  820. if (type === 'forum') {
  821. const { root, category, title, text, key, rootTitle, rootKey } = content;
  822. if (!root) {
  823. const linkKey = key || action.id;
  824. const linkText = (title && String(title).trim()) ? title : '';
  825. cardBody.push(
  826. div({ class: 'card-section forum' },
  827. div({ class: 'card-field', style: "font-size:1.12em; margin-bottom:5px;" },
  828. span({ class: 'card-label', style: "font-weight:800;color:#ff9800;" }, i18n.title + ': '),
  829. a({ href: `/forum/${encodeURIComponent(linkKey)}`, style: "font-weight:800;color:#4fc3f7;" }, linkText)
  830. )
  831. )
  832. );
  833. } else {
  834. const rootId = typeof root === 'string' ? root : (root?.key || root?.id || '');
  835. const parentForum = byIdAll.get(rootId) || actions.find(a => a.type === 'forum' && !a.content?.root && (a.id === rootId || a.content?.key === rootId));
  836. const parentContent = parentForum ? (parentForum.value?.content || parentForum.content || {}) : {};
  837. const parentTitle = (parentContent?.title && String(parentContent.title).trim()) ? parentContent.title : ((rootTitle && String(rootTitle).trim()) ? rootTitle : '');
  838. const parentAuthor = parentForum?.author || '';
  839. const parentName = parentForum?.authorName || parentAuthor;
  840. const hrefKey = rootKey || rootId;
  841. cardBody.push(
  842. div({ class: 'card-section forum' },
  843. div(
  844. { class: 'reply-context', style: 'border-left:3px solid #666;padding-left:10px;margin-bottom:8px;opacity:0.85;' },
  845. span({ style: 'font-size:0.85em;' },
  846. a({ href: `/forum/${encodeURIComponent(hrefKey)}`, class: 'tag-link' }, i18n.inReplyTo || 'IN REPLY TO'),
  847. parentAuthor ? span(' ', a({ href: `/author/${encodeURIComponent(parentAuthor)}`, class: 'user-link', style: 'font-weight:bold;' }, parentName)) : ''
  848. ),
  849. parentTitle ? p({ class: 'post-text reply-context-text', style: 'font-size:0.85em;max-height:60px;overflow:hidden;margin-top:4px;font-weight:bold;color:#4fc3f7;' }, parentTitle) : ''
  850. ),
  851. div({ class: 'card-field', style: 'margin-bottom:12px;' },
  852. p({ style: "margin:0 0 8px 0; word-break:break-all;" }, ...renderUrl(text))
  853. )
  854. )
  855. );
  856. }
  857. }
  858. if (type === 'spread') {
  859. const link = normalizeSpreadLink(content?.spreadTargetId || content?.vote?.link || '');
  860. const target = link ? (byIdAll.get(link) || byIdAll.get(decodeMaybe(link)) || byIdAll.get(encodeURIComponent(link))) : null;
  861. const tContent = target ? (target.value?.content || target.content || {}) : {};
  862. const spreadTitle =
  863. (typeof content?.spreadTitle === 'string' && content.spreadTitle.trim())
  864. ? content.spreadTitle.trim()
  865. : (typeof tContent?.title === 'string' && tContent.title.trim())
  866. ? tContent.title.trim()
  867. : (typeof tContent?.name === 'string' && tContent.name.trim())
  868. ? tContent.name.trim()
  869. : '';
  870. const spreadContentWarning =
  871. (typeof content?.spreadContentWarning === 'string' && content.spreadContentWarning.trim())
  872. ? content.spreadContentWarning.trim()
  873. : (typeof tContent?.contentWarning === 'string' && tContent.contentWarning.trim())
  874. ? tContent.contentWarning.trim()
  875. : '';
  876. const spreadText =
  877. (typeof content?.spreadText === 'string' && content.spreadText.trim())
  878. ? content.spreadText.trim()
  879. : excerptPostText(tContent, 700);
  880. const spreadOriginalAuthor =
  881. (typeof content?.spreadOriginalAuthor === 'string' && content.spreadOriginalAuthor.trim())
  882. ? content.spreadOriginalAuthor.trim()
  883. : (target?.author || '');
  884. const ord = spreadOrdinalById.get(safeMsgId(action)) || 0;
  885. const totalChron = link && spreadsByLink.has(link) ? spreadsByLink.get(link).length : 0;
  886. const label = (i18n.spreadChron || 'Spread') + ':';
  887. const value = ord && totalChron ? `${ord}/${totalChron}` : (ord ? String(ord) : '');
  888. const spreadExcerpt = spreadText || excerptPostText(content, 300);
  889. cardBody.push(
  890. div({ class: 'card-section vote' },
  891. spreadTitle ? h2({ class: 'post-title activity-spread-title' }, spreadTitle) : '',
  892. spreadContentWarning ? h2({ class: 'content-warning' }, spreadContentWarning) : '',
  893. spreadExcerpt
  894. ? div({ class: 'post-text activity-spread-text post-text-pre', style: 'max-height:200px;overflow:hidden;' }, ...renderUrlPreserveNewlines(spreadExcerpt))
  895. : div({ class: 'post-text activity-spread-text', style: 'opacity:0.6;font-style:italic;' }, i18n.spreadContentUnavailable || 'Content not yet available (pending replication)'),
  896. spreadOriginalAuthor
  897. ? div({ class: 'card-field' },
  898. span({ class: 'card-label' }, (i18n.spreadBy || 'By') + ': '),
  899. span({ class: 'card-value' }, a({ href: `/author/${encodeURIComponent(spreadOriginalAuthor)}`, class: 'user-link' }, spreadOriginalAuthor))
  900. )
  901. : '',
  902. value
  903. ? div({ class: 'card-field' },
  904. span({ class: 'card-label' }, label),
  905. span({ class: 'card-value' }, value)
  906. )
  907. : '',
  908. link
  909. ? div({ style: 'margin-top:6px;' },
  910. a({ href: `/thread/${encodeURIComponent(link)}#${encodeURIComponent(link)}`, class: 'filter-btn' }, i18n.viewDetails || 'View details')
  911. )
  912. : ''
  913. )
  914. );
  915. }
  916. if (type === 'vote') {
  917. const { vote } = content;
  918. cardBody.push(
  919. div({ class: 'card-section vote' },
  920. p(
  921. a({ href: `/thread/${encodeURIComponent(vote.link)}#${encodeURIComponent(vote.link)}`, class: 'activityVotePost' }, vote.link)
  922. )
  923. )
  924. );
  925. }
  926. if (type === 'about') {
  927. const { about, name, image } = content;
  928. cardBody.push(
  929. div({ class: 'card-section about' },
  930. h2(a({ href: `/author/${encodeURIComponent(about)}`, class: "user-link" }, `@`, name)),
  931. image
  932. ? img({ src: `/blob/${encodeURIComponent(image)}`, alt: name, class: 'activity-avatar' })
  933. : img({ src: '/assets/images/default-avatar.png', alt: name, class: 'activity-avatar' })
  934. )
  935. );
  936. }
  937. if (type === 'contact') {
  938. const { contact } = content || {};
  939. const aId = action.author || '';
  940. const bId = contact || '';
  941. const pa = getProfile(aId);
  942. const pb = getProfile(bId);
  943. const srcA = pa.image ? `/blob/${encodeURIComponent(pa.image)}` : '/assets/images/default-avatar.png';
  944. const srcB = pb.image ? `/blob/${encodeURIComponent(pb.image)}` : '/assets/images/default-avatar.png';
  945. cardBody.push(
  946. div({ class: 'card-section contact' },
  947. div({ class: 'activity-contact' },
  948. a({ href: `/author/${encodeURIComponent(aId)}`, class: 'activity-contact-avatar-link' },
  949. img({ src: srcA, alt: pa.name || pa.id, class: 'activity-contact-avatar' })
  950. ),
  951. span({ class: 'activity-contact-arrow' }, ''),
  952. a({ href: `/author/${encodeURIComponent(bId)}`, class: 'activity-contact-avatar-link' },
  953. img({ src: srcB, alt: pb.name || pb.id, class: 'activity-contact-avatar' })
  954. )
  955. )
  956. )
  957. );
  958. }
  959. if (type === 'pub') {
  960. const { address } = content || {};
  961. const { key } = address || {};
  962. const pr = getProfile(key || '');
  963. const src = pr.image ? `/blob/${encodeURIComponent(pr.image)}` : '/assets/images/default-avatar.png';
  964. cardBody.push(
  965. div({ class: 'card-section pub activity-pub' },
  966. br(),
  967. a({ href: `/author/${encodeURIComponent(pr.id)}`, class: 'user-link' }, pr.name || pr.id),
  968. br(),
  969. img({ src, alt: pr.name || pr.id, class: 'activity-avatar' })
  970. )
  971. );
  972. }
  973. if (type === 'market') {
  974. const { item_type, title, price, status, deadline, stock, image, auctions_poll, seller } = content;
  975. const isSeller = seller && userId && seller === userId;
  976. cardBody.push(
  977. div({ class: 'card-section market' },
  978. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemTitle + ':'), span({ class: 'card-value' }, title)),
  979. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemType + ':'), span({ class: 'card-value' }, item_type.toUpperCase())),
  980. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemStatus + ": " ), span({ class: 'card-value' }, status.toUpperCase())),
  981. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.deadline + ':'), span({ class: 'card-value' }, deadline ? new Date(deadline).toLocaleString() : "")),
  982. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemStock + ':'), span({ class: 'card-value' }, stock)),
  983. br(),
  984. image
  985. ? renderMediaBlob(image, '/assets/images/default-market.png')
  986. : img({ src: '/assets/images/default-market.png', alt: title }),
  987. br(),
  988. div({ class: "market-card price" },
  989. p(`${i18n.marketItemPrice}: ${price} ECO`)
  990. ),
  991. item_type === 'auction' && status !== 'SOLD' && status !== 'DISCARDED' && !isSeller
  992. ? div({ class: "auction-info" },
  993. auctions_poll && auctions_poll.length > 0
  994. ?
  995. table({ class: 'auction-bid-table' },
  996. tr(
  997. th(i18n.marketAuctionBidTime),
  998. th(i18n.marketAuctionUser),
  999. th(i18n.marketAuctionBidAmount)
  1000. ),
  1001. ...(auctions_poll || []).map(bid => {
  1002. const [bidderId, bidAmount, bidTime] = bid.split(':');
  1003. return tr(
  1004. td(moment(bidTime).format('YYYY-MM-DD HH:mm:ss')),
  1005. td(a({ href: `/author/${encodeURIComponent(userId)}` }, userId)),
  1006. td(`${parseFloat(bidAmount).toFixed(6)} ECO`)
  1007. );
  1008. })
  1009. )
  1010. : p(i18n.marketNoBids),
  1011. form({ method: "POST", action: `/market/bid/${encodeURIComponent(action.id)}` },
  1012. input({ type: "number", name: "bidAmount", step: "0.000001", min: "0.000001", placeholder: i18n.marketYourBid, required: true }),
  1013. br(),
  1014. button({ class: "buy-btn", type: "submit" }, i18n.marketPlaceBidButton)
  1015. )
  1016. ) : "",
  1017. item_type === 'exchange' && status !== 'SOLD' && status !== 'DISCARDED' && !isSeller
  1018. ? form({ method: "POST", action: `/market/buy/${encodeURIComponent(action.id)}` },
  1019. button({ class: "buy-btn", type: "submit" }, i18n.marketActionsBuy)
  1020. ) : ""
  1021. )
  1022. );
  1023. }
  1024. if (type === 'shop') {
  1025. const { title, shortDescription, description, visibility, location } = content;
  1026. const shopKey = action.id || action.key || '';
  1027. const displayDesc = shortDescription || (description ? (description.length > 140 ? description.slice(0, 140) + "\u2026" : description) : "");
  1028. cardBody.push(
  1029. div({ class: 'card-section shop' },
  1030. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.shopTitle || 'Shop') + ':'), span({ class: 'card-value' }, shopKey ? a({ href: `/shops/${encodeURIComponent(shopKey)}`, class: 'user-link' }, title || shopKey) : (title || ''))),
  1031. displayDesc ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.description || 'Description') + ':'), span({ class: 'card-value' }, displayDesc)) : "",
  1032. visibility ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.shopVisibility || 'Visibility') + ':'), span({ class: 'card-value' }, visibility)) : "",
  1033. location ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.shopLocation || 'Location') + ':'), span({ class: 'card-value' }, location)) : ""
  1034. )
  1035. );
  1036. }
  1037. if (type === 'shopProduct') {
  1038. const { title, price, stock, shopId, image: prodImage } = content;
  1039. const resolvedShopTitle = shopId ? (shopTitleById.get(shopId) || null) : null;
  1040. const shopLabel = resolvedShopTitle || (shopId ? shopId.slice(0, 10) + '...' : '');
  1041. const prodImageNode = renderMediaBlob(prodImage);
  1042. cardBody.push(
  1043. div({ class: 'card-section shop' },
  1044. shopId ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.shopTitle || 'Shop') + ':'), span({ class: 'card-value' }, a({ href: `/shops/${encodeURIComponent(shopId)}`, class: 'user-link' }, shopLabel))) : '',
  1045. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.shopProductTitle || 'Product') + ':'), span({ class: 'card-value' }, title || '')),
  1046. prodImageNode ? div({ class: 'card-field' }, prodImageNode) : '',
  1047. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.shopProductPrice || 'Price') + ':'), span({ class: 'card-value' }, `${Number(price || 0).toFixed(6)} ECO`)),
  1048. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.shopProductStock || 'Stock') + ':'), span({ class: 'card-value' }, String(stock || 0)))
  1049. )
  1050. );
  1051. }
  1052. if (type === 'chat') {
  1053. const { title, description, image, category, status } = content;
  1054. const chatKey = action.id || action.key || '';
  1055. const displayDesc = description ? (description.length > 140 ? description.slice(0, 140) + "\u2026" : description) : "";
  1056. const chatImageNode = renderMediaBlob(image);
  1057. cardBody.push(
  1058. div({ class: 'card-section chat' },
  1059. div({ class: 'card-field' }, span({ class: 'card-label' }, 'Chat:'), span({ class: 'card-value' }, chatKey ? a({ href: `/chats/${encodeURIComponent(chatKey)}`, class: 'user-link' }, title || chatKey) : (title || ''))),
  1060. displayDesc ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.chatDescription || 'Description') + ':'), span({ class: 'card-value' }, displayDesc)) : '',
  1061. category ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.chatCategoryLabel || 'Category') + ':'), span({ class: 'card-value' }, category)) : '',
  1062. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.chatStatus || 'Status') + ':'), span({ class: 'card-value' }, status)) : ''
  1063. )
  1064. );
  1065. }
  1066. if (type === 'pad') {
  1067. const padKey = action.id || action.key || '';
  1068. const padTitle = content.title || action.title || '';
  1069. cardBody.push(
  1070. div({ class: 'card-section' },
  1071. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.padTitle || 'Pad') + ':'), span({ class: 'card-value' }, padKey ? a({ href: `/pads/${encodeURIComponent(padKey)}`, class: 'user-link' }, padTitle || padKey) : '')),
  1072. content.deadline ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.padDeadlineLabel || 'Deadline') + ':'), span({ class: 'card-value' }, content.deadline)) : ''
  1073. )
  1074. );
  1075. }
  1076. if (type === 'calendar') {
  1077. const calKey = action.id || action.key || '';
  1078. const calTitle = content.title || action.title || '';
  1079. cardBody.push(
  1080. div({ class: 'card-section' },
  1081. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.calendarTitle || 'Calendar') + ':'), span({ class: 'card-value' }, calKey ? a({ href: `/calendars/${encodeURIComponent(calKey)}`, class: 'user-link' }, calTitle || calKey) : '')),
  1082. content.status ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.calendarStatusLabel || 'Status') + ':'), span({ class: 'card-value' }, content.status)) : ''
  1083. )
  1084. );
  1085. }
  1086. if (type === 'report') {
  1087. const { title, confirmations, severity, status } = content;
  1088. cardBody.push(
  1089. div({ class: 'card-section report' },
  1090. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, title)),
  1091. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.status + ':'), span({ class: 'card-value' }, status)) : "",
  1092. severity ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.severity || 'Severity') + ':'), span({ class: 'card-value' }, severity.toUpperCase())) : "",
  1093. Array.isArray(confirmations) ? h2({ class: 'card-label' }, (i18n.transfersConfirmations) + ': ' + confirmations.length) : ""
  1094. )
  1095. );
  1096. }
  1097. if (type === 'project') {
  1098. const {
  1099. title, status, progress, goal, pledged,
  1100. deadline, followers, backers, milestones,
  1101. bounty, bountyAmount, bounty_currency,
  1102. activity, activityActor
  1103. } = content;
  1104. const ratio = goal ? Math.min(100, Math.round((parseFloat(pledged || 0) / parseFloat(goal)) * 100)) : 0;
  1105. const displayStatus = String(status || 'ACTIVE').toUpperCase();
  1106. const followersCount = Array.isArray(followers) ? followers.length : 0;
  1107. const backersCount = Array.isArray(backers) ? backers.length : 0;
  1108. const backersTotal = sumAmounts(backers || []);
  1109. const msCount = Array.isArray(milestones) ? milestones.length : 0;
  1110. const lastMs = Array.isArray(milestones) && milestones.length ? milestones[milestones.length - 1] : null;
  1111. const bountyVal = typeof bountyAmount !== 'undefined'
  1112. ? bountyAmount
  1113. : (typeof bounty === 'number' ? bounty : null);
  1114. if (activity && activity.kind) {
  1115. const tmpl =
  1116. activity.kind === 'follow'
  1117. ? (i18n.activityProjectFollow || '%OASIS% is now %ACTION% this project: %PROJECT%')
  1118. : activity.kind === 'unfollow'
  1119. ? (i18n.activityProjectUnfollow || '%OASIS% is now %ACTION% this project: %PROJECT%')
  1120. : '%OASIS% performed an unknown action on %PROJECT%';
  1121. const actionWord =
  1122. activity.kind === 'follow'
  1123. ? (i18n.following || 'FOLLOWING')
  1124. : activity.kind === 'unfollow'
  1125. ? (i18n.unfollowing || 'UNFOLLOWING')
  1126. : 'ACTION';
  1127. const msgHtml = tmpl
  1128. .replace('%OASIS%', `<a class="user-link" href="/author/${encodeURIComponent(activity.activityActor || '')}">${activity.activityActor || ''}</a>`)
  1129. .replace('%PROJECT%', `<a class="user-link" href="/projects/${encodeURIComponent(action.tipId || action.id)}">${title || ''}</a>`)
  1130. .replace('%ACTION%', `<strong>${actionWord}</strong>`);
  1131. return div({ class: 'card card-rpg' },
  1132. div({ class: 'card-header' },
  1133. h2({ class: 'card-label' }, `[${(i18n.typeProject || 'PROJECT').toUpperCase()}]`),
  1134. form({ method: "GET", action: `/projects/${encodeURIComponent(action.tipId || action.id)}` },
  1135. button({ type: "submit", class: "filter-btn" }, i18n.viewDetails)
  1136. )
  1137. ),
  1138. div(
  1139. p({ innerHTML: sanitizeHtml(msgHtml) })
  1140. ),
  1141. p({ class: 'card-footer' },
  1142. span({ class: 'date-link' }, `${action.ts ? new Date(action.ts).toLocaleString() : ''} ${i18n.performed} `),
  1143. a({ href: `/author/${encodeURIComponent(action.author)}`, class: 'user-link' }, `${action.author}`)
  1144. )
  1145. );
  1146. }
  1147. cardBody.push(
  1148. div({ class: 'card-section project' },
  1149. title ? div({ class: 'card-field' },
  1150. span({ class: 'card-label' }, i18n.title + ':'),
  1151. span({ class: 'card-value' }, title)
  1152. ) : "",
  1153. typeof goal !== 'undefined' ? div({ class: 'card-field' },
  1154. span({ class: 'card-label' }, i18n.projectGoal + ':'),
  1155. span({ class: 'card-value' }, `${goal} ECO`)
  1156. ) : "",
  1157. typeof progress !== 'undefined' ? div({ class: 'card-field' },
  1158. span({ class: 'card-label' }, i18n.projectProgress + ':'),
  1159. span({ class: 'card-value' }, `${progress || 0}%`)
  1160. ) : "",
  1161. deadline ? div({ class: 'card-field' },
  1162. span({ class: 'card-label' }, i18n.projectDeadline + ':'),
  1163. span({ class: 'card-value' }, moment(deadline).format('YYYY/MM/DD HH:mm'))
  1164. ) : "",
  1165. div({ class: 'card-field' },
  1166. span({ class: 'card-label' }, i18n.projectStatus + ':'),
  1167. span({ class: 'card-value' }, i18n['projectStatus' + displayStatus] || displayStatus)
  1168. ),
  1169. div({ class: 'card-field' },
  1170. span({ class: 'card-label' }, i18n.projectFunding + ':'),
  1171. span({ class: 'card-value' }, `${ratio}%`)
  1172. ),
  1173. typeof pledged !== 'undefined' ? div({ class: 'card-field' },
  1174. span({ class: 'card-label' }, i18n.projectPledged + ':'),
  1175. span({ class: 'card-value' }, `${pledged || 0} ECO`)
  1176. ) : "",
  1177. div({ class: 'card-field' },
  1178. span({ class: 'card-label' }, i18n.projectFollowers + ':'),
  1179. span({ class: 'card-value' }, `${followersCount}`)
  1180. ),
  1181. div({ class: 'card-field' },
  1182. span({ class: 'card-label' }, i18n.projectBackers + ':'),
  1183. span({ class: 'card-value' }, `${backersCount} · ${backersTotal} ECO`)
  1184. ),
  1185. msCount ? div({ class: 'card-field' },
  1186. span({ class: 'card-label' }, (i18n.projectMilestones || 'Milestones') + ':'),
  1187. span({ class: 'card-value' }, `${msCount}${lastMs && lastMs.title ? ' · ' + lastMs.title : ''}`)
  1188. ) : "",
  1189. bountyVal != null ? div({ class: 'card-field' },
  1190. span({ class: 'card-label' }, (i18n.projectBounty || 'Bounty') + ':'),
  1191. span({ class: 'card-value' }, `${bountyVal} ${(bounty_currency || 'ECO').toUpperCase()}`)
  1192. ) : ""
  1193. )
  1194. );
  1195. }
  1196. if (type === 'aiExchange') {
  1197. const { ctx } = content;
  1198. cardBody.push(
  1199. div({ class: 'card-section ai-exchange' },
  1200. Array.isArray(ctx) && ctx.length
  1201. ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.aiSnippetsLearned || 'Snippets learned') + ':'), span({ class: 'card-value' }, String(ctx.length)))
  1202. : ""
  1203. )
  1204. );
  1205. }
  1206. if (type === 'karmaScore') {
  1207. const { karmaScore } = content;
  1208. cardBody.push(
  1209. div({ class: 'card-section ai-exchange' },
  1210. div({ class: 'card-field' },
  1211. span({ class: 'card-label' }, i18n.bankingUserEngagementScore + ':'),
  1212. span({ class: 'card-value' }, karmaScore)
  1213. )
  1214. )
  1215. );
  1216. }
  1217. if (type === 'gameScore') {
  1218. const { game, score } = content;
  1219. cardBody.push(
  1220. div({ class: 'card-section ai-exchange' },
  1221. game ? div({ class: 'card-field' },
  1222. span({ class: 'card-label' }, (i18n.gamesTitle || 'Game') + ':'),
  1223. span({ class: 'card-value' }, String(game).toUpperCase())
  1224. ) : null,
  1225. div({ class: 'card-field' },
  1226. span({ class: 'card-label' }, (i18n.gamesHallScore || 'Score') + ':'),
  1227. span({ class: 'card-value' }, String(score || 0))
  1228. )
  1229. )
  1230. );
  1231. }
  1232. if (type === 'job') {
  1233. const { title, job_type, tasks, location, vacants, salary, status, subscribers } = content;
  1234. cardBody.push(
  1235. div({ class: 'card-section report' },
  1236. div({ class: 'card-field' },
  1237. span({ class: 'card-label' }, i18n.title + ':'),
  1238. span({ class: 'card-value' }, title)
  1239. ),
  1240. salary && div({ class: 'card-field' },
  1241. span({ class: 'card-label' }, i18n.jobSalary + ':'),
  1242. span({ class: 'card-value' }, salary + ' ECO')
  1243. ),
  1244. status && div({ class: 'card-field' },
  1245. span({ class: 'card-label' }, i18n.jobStatus + ':'),
  1246. span({ class: 'card-value' }, status.toUpperCase())
  1247. ),
  1248. job_type && div({ class: 'card-field' },
  1249. span({ class: 'card-label' }, i18n.jobType + ':'),
  1250. span({ class: 'card-value' }, job_type.toUpperCase())
  1251. ),
  1252. location && div({ class: 'card-field' },
  1253. span({ class: 'card-label' }, i18n.jobLocation + ':'),
  1254. span({ class: 'card-value' }, location.toUpperCase())
  1255. ),
  1256. vacants && div({ class: 'card-field' },
  1257. span({ class: 'card-label' }, i18n.jobVacants + ':'),
  1258. span({ class: 'card-value' }, vacants)
  1259. ),
  1260. div({ class: 'card-field' },
  1261. span({ class: 'card-label' }, i18n.jobSubscribers + ':'),
  1262. span({ class: 'card-value' },
  1263. Array.isArray(subscribers) && subscribers.length > 0
  1264. ? `${subscribers.length}`
  1265. : i18n.noSubscribers.toUpperCase()
  1266. )
  1267. )
  1268. )
  1269. );
  1270. }
  1271. if (type === 'parliamentCandidature') {
  1272. const { targetType, targetId, targetTitle, method, votes, proposer } = content;
  1273. const link = targetType === 'tribe'
  1274. ? a({ href: `/tribe/${encodeURIComponent(targetId)}`, class: 'user-link' }, targetTitle || targetId)
  1275. : a({ href: `/author/${encodeURIComponent(targetId)}`, class: 'user-link' }, targetId);
  1276. const methodUpper = String(
  1277. i18n['parliamentMethod' + String(method || '').toUpperCase()] || method
  1278. ).toUpperCase();
  1279. cardBody.push(
  1280. div({ class: 'card-section parliament' },
  1281. div({ class: 'card-field' }, span({ class: 'card-label' }, (String(i18n.parliamentCandidatureId || 'Candidature').toUpperCase()) + ':'), span({ class: 'card-value' }, link)),
  1282. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentGovMethod || 'METHOD') + ':'), span({ class: 'card-value' }, methodUpper)),
  1283. typeof votes !== 'undefined'
  1284. ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentVotesReceived || 'VOTES RECEIVED') + ':'), span({ class: 'card-value' }, String(votes)))
  1285. : ''
  1286. )
  1287. );
  1288. }
  1289. if (type === 'parliamentTerm') {
  1290. const { method, powerType, powerId, powerTitle, winnerVotes, totalVotes, startAt, endAt } = content;
  1291. const powerTypeNorm = String(powerType || '').toLowerCase();
  1292. const winnerLink =
  1293. powerTypeNorm === 'tribe'
  1294. ? a({ href: `/tribe/${encodeURIComponent(powerId)}`, class: 'user-link' }, powerTitle || powerId)
  1295. : powerTypeNorm === 'none' || !powerTypeNorm
  1296. ? a({ href: `/parliament?filter=government`, class: 'user-link' }, (i18n.parliamentAnarchy || 'ANARCHY'))
  1297. : a({ href: `/author/${encodeURIComponent(powerId)}`, class: 'user-link' }, powerTitle || powerId);
  1298. const methodUpper = String(
  1299. i18n['parliamentMethod' + String(method || '').toUpperCase()] || method
  1300. ).toUpperCase();
  1301. cardBody.push(
  1302. div({ class: 'card-section parliament' },
  1303. startAt ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentElectionsStart.toUpperCase() || 'Elections start') + ':'), span({ class: 'card-value' }, new Date(startAt).toLocaleString())) : '',
  1304. endAt ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentElectionsEnd.toUpperCase() || 'Elections end') + ':'), span({ class: 'card-value' }, new Date(endAt).toLocaleString())) : '',
  1305. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentCurrentLeader.toUpperCase() || 'Winning candidature') + ':'), span({ class: 'card-value' }, winnerLink)),
  1306. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentGovMethod.toUpperCase() || 'Method') + ':'), span({ class: 'card-value' }, methodUpper)),
  1307. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentVotesReceived.toUpperCase() || 'Votes received') + ':'), span({ class: 'card-value' }, `${Number(winnerVotes || 0)} (${Number(totalVotes || 0)})`))
  1308. )
  1309. );
  1310. }
  1311. if (type === 'parliamentProposal') {
  1312. const { title, description, method, status, voteId, createdAt } = content;
  1313. const methodUpper = String(
  1314. i18n['parliamentMethod' + String(method || '').toUpperCase()] || method
  1315. ).toUpperCase();
  1316. cardBody.push(
  1317. div({ class: 'card-section parliament' },
  1318. title ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentProposalTitle.toUpperCase() || 'Title') + ':'), span({ class: 'card-value' }, title)) : '',
  1319. description ? p({ style: 'margin:.4rem 0' }, description) : '',
  1320. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentGovMethod || 'Method') + ':'), span({ class: 'card-value' }, methodUpper)),
  1321. createdAt ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.createdAt.toUpperCase() || 'Created at') + ':'), span({ class: 'card-value' }, new Date(createdAt).toLocaleString())) : '',
  1322. voteId ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentOpenVote.toUpperCase() || 'Open vote') + ':'), a({ href: `/votes/${encodeURIComponent(voteId)}`, class: 'tag-link' }, i18n.viewDetails || 'View details')) : '',
  1323. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentStatus.toUpperCase() || 'Status') + ':'), span({ class: 'card-value' }, status)) : ''
  1324. )
  1325. );
  1326. }
  1327. if (type === 'parliamentRevocation') {
  1328. const { title, reasons, method, status, voteId, createdAt } = content;
  1329. const methodUpper = String(
  1330. i18n['parliamentMethod' + String(method || '').toUpperCase()] || method
  1331. ).toUpperCase();
  1332. cardBody.push(
  1333. div({ class: 'card-section parliament' },
  1334. title ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentProposalTitle.toUpperCase() || 'Title') + ':'), span({ class: 'card-value' }, title)) : '',
  1335. reasons ? p({ style: 'margin:.4rem 0' }, reasons) : '',
  1336. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentGovMethod || 'Method') + ':'), span({ class: 'card-value' }, methodUpper)),
  1337. createdAt ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.createdAt.toUpperCase() || 'Created at') + ':'), span({ class: 'card-value' }, new Date(createdAt).toLocaleString())) : '',
  1338. voteId ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentOpenVote.toUpperCase() || 'Open vote') + ':'), a({ href: `/votes/${encodeURIComponent(voteId)}`, class: 'tag-link' }, i18n.viewDetails || 'View details')) : '',
  1339. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentStatus.toUpperCase() || 'Status') + ':'), span({ class: 'card-value' }, status)) : ''
  1340. )
  1341. );
  1342. }
  1343. if (type === 'parliamentLaw') {
  1344. const { question, description, method, proposer, enactedAt, votes } = content;
  1345. const yes = Number(votes?.YES || 0);
  1346. const total = Number(votes?.total || votes?.TOTAL || 0);
  1347. const methodUpper = String(
  1348. i18n['parliamentMethod' + String(method || '').toUpperCase()] || method
  1349. ).toUpperCase();
  1350. cardBody.push(
  1351. div({ class: 'card-section parliament' },
  1352. question ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentLawQuestion || 'Question') + ':'), span({ class: 'card-value' }, question)) : '',
  1353. description ? p({ style: 'margin:.4rem 0' }, description) : '',
  1354. div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentLawMethod || 'Method') + ':'), span({ class: 'card-value' }, methodUpper)),
  1355. proposer ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentLawProposer || 'Proposer') + ':'), span({ class: 'card-value' }, a({ href: `/author/${encodeURIComponent(proposer)}`, class: 'user-link' }, proposer))) : '',
  1356. enactedAt ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentLawEnacted || 'Enacted at') + ':'), span({ class: 'card-value' }, new Date(enactedAt).toLocaleString())) : '',
  1357. (total || yes) ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.parliamentLawVotes || 'Votes') + ':'), span({ class: 'card-value' }, `${yes}/${total}`)) : ''
  1358. )
  1359. );
  1360. }
  1361. if (type.startsWith('courts')) {
  1362. if (type === 'courtsCase') {
  1363. const { title, method, accuser, status, answerBy, evidenceBy, decisionBy, needed, yes, total, voteId } = content;
  1364. cardBody.push(
  1365. div({ class: 'card-section courts' },
  1366. title ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsCaseTitle.toUpperCase() + ':'), span({ class: 'card-value' }, title)) : '',
  1367. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsThStatus.toUpperCase() + ':'), span({ class: 'card-value' }, status)) : '',
  1368. method ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsMethod.toUpperCase() + ':'), span({ class: 'card-value' }, String(i18n['courtsMethod' + String(method).toUpperCase()] || method).toUpperCase())) : '',
  1369. answerBy ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsThAnswerBy + ':'), span({ class: 'card-value' }, new Date(answerBy).toLocaleString())) : '',
  1370. evidenceBy ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsThEvidenceBy + ':'), span({ class: 'card-value' }, new Date(evidenceBy).toLocaleString())) : '',
  1371. decisionBy ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsThDecisionBy + ':'), span({ class: 'card-value' }, new Date(decisionBy).toLocaleString())) : '',
  1372. accuser ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsAccuser + ':'), span({ class: 'card-value' }, a({ href: `/author/${encodeURIComponent(accuser)}`, class: 'user-link' }, accuser))) : '',
  1373. typeof needed !== 'undefined' ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsVotesNeeded + ':'), span({ class: 'card-value' }, String(needed))) : '',
  1374. (typeof yes !== 'undefined' || typeof total !== 'undefined') ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsVotesSlashTotal + ':'), span({ class: 'card-value' }, `${Number(yes || 0)}/${Number(total || 0)}`)) : '',
  1375. voteId ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsOpenVote + ':'), a({ href: `/votes/${encodeURIComponent(voteId)}`, class: 'tag-link' }, i18n.viewDetails || 'View details')) : ''
  1376. )
  1377. );
  1378. } else if (type === 'courtsNomination') {
  1379. const { judgeId } = content;
  1380. cardBody.push(
  1381. div({ class: 'card-section courts' },
  1382. judgeId ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.courtsJudge + ':'), span({ class: 'card-value' }, a({ href: `/author/${encodeURIComponent(judgeId)}`, class: 'user-link' }, judgeId))) : ''
  1383. )
  1384. );
  1385. } else {
  1386. skip = true;
  1387. }
  1388. }
  1389. const viewHref = getViewDetailsAction(type, action);
  1390. const isParliamentTarget =
  1391. viewHref === '/parliament?filter=candidatures' ||
  1392. viewHref === '/parliament?filter=government' ||
  1393. viewHref === '/parliament?filter=proposals' ||
  1394. viewHref === '/parliament?filter=revocations' ||
  1395. viewHref === '/parliament?filter=laws';
  1396. const isCourtsTarget =
  1397. viewHref === '/courts?filter=cases' ||
  1398. viewHref === '/courts?filter=mycases' ||
  1399. viewHref === '/courts?filter=actions' ||
  1400. viewHref === '/courts?filter=judges' ||
  1401. viewHref === '/courts?filter=history' ||
  1402. viewHref === '/courts?filter=rules' ||
  1403. viewHref === '/courts?filter=open';
  1404. const parliamentFilter = isParliamentTarget ? (viewHref.split('filter=')[1] || '') : '';
  1405. const courtsFilter = isCourtsTarget ? (viewHref.split('filter=')[1] || '') : '';
  1406. if (skip) {
  1407. return null;
  1408. }
  1409. return div({ class: 'card card-rpg' },
  1410. div({ class: 'card-header' },
  1411. h2({ class: 'card-label' }, headerText),
  1412. type !== 'feed' && type !== 'aiExchange' && type !== 'bankWallet' && (!action.tipId || action.tipId === action.id)
  1413. ? (
  1414. isParliamentTarget
  1415. ? form(
  1416. { method: "GET", action: "/parliament" },
  1417. input({ type: "hidden", name: "filter", value: parliamentFilter }),
  1418. button({ type: "submit", class: "filter-btn" }, i18n.viewDetails)
  1419. )
  1420. : isCourtsTarget
  1421. ? form(
  1422. { method: "GET", action: "/courts" },
  1423. input({ type: "hidden", name: "filter", value: courtsFilter }),
  1424. button({ type: "submit", class: "filter-btn" }, i18n.viewDetails)
  1425. )
  1426. : form(
  1427. { method: "GET", action: viewHref },
  1428. button({ type: "submit", class: "filter-btn" }, i18n.viewDetails)
  1429. )
  1430. )
  1431. : ''
  1432. ),
  1433. div({ class: 'card-body' }, ...cardBody),
  1434. p({ class: 'card-footer' },
  1435. span({ class: 'date-link' }, `${date} ${i18n.performed} `),
  1436. a({ href: `/author/${encodeURIComponent(action.author)}`, class: 'user-link' }, `${action.author}`)
  1437. )
  1438. );
  1439. });
  1440. const filteredCards = cards.filter(Boolean);
  1441. if (!filteredCards.length) {
  1442. return div({ class: "no-actions" }, p(i18n.noActions));
  1443. }
  1444. return filteredCards;
  1445. }
  1446. function getViewDetailsAction(type, action) {
  1447. const id = encodeURIComponent(safeMsgId(action.tipId || action.id || action.key || action));
  1448. switch (type) {
  1449. case 'parliamentCandidature': return `/parliament?filter=candidatures`;
  1450. case 'parliamentTerm': return `/parliament?filter=government`;
  1451. case 'parliamentProposal': return `/parliament?filter=proposals`;
  1452. case 'parliamentRevocation': return `/parliament?filter=revocations`;
  1453. case 'parliamentLaw': return `/parliament?filter=laws`;
  1454. case 'courtsCase': return `/courts/cases/${encodeURIComponent(action.id)}`;
  1455. case 'courtsEvidence': return `/courts?filter=actions`;
  1456. case 'courtsAnswer': return `/courts?filter=actions`;
  1457. case 'courtsVerdict': return `/courts?filter=actions`;
  1458. case 'courtsSettlement': return `/courts?filter=actions`;
  1459. case 'courtsSettlementProposal':return `/courts?filter=actions`;
  1460. case 'courtsSettlementAccepted':return `/courts?filter=actions`;
  1461. case 'courtsNomination': return `/courts?filter=judges`;
  1462. case 'courtsNominationVote': return `/courts?filter=judges`;
  1463. case 'spread': {
  1464. const link = normalizeSpreadLink(action.content?.spreadTargetId || action.content?.vote?.link || '');
  1465. return link ? `/thread/${encodeURIComponent(link)}#${encodeURIComponent(link)}` : `/activity`;
  1466. }
  1467. case 'post': return `/thread/${id}#${id}`;
  1468. case 'vote': return `/thread/${encodeURIComponent(action.content.vote.link)}#${encodeURIComponent(action.content.vote.link)}`;
  1469. case 'votes': return `/votes/${id}`;
  1470. case 'transfer': return `/transfers/${id}`;
  1471. case 'pixelia': return `/pixelia`;
  1472. case 'tribe': return `/tribe/${id}`;
  1473. case 'curriculum': return `/inhabitant/${encodeURIComponent(action.author)}`;
  1474. case 'karmaScore': return `/author/${encodeURIComponent(action.author)}`;
  1475. case 'map': return `/maps/${id}`;
  1476. case 'mapMarker': return `/maps/${encodeURIComponent(action.content?.mapId || id)}`;
  1477. case 'image': return `/images/${id}`;
  1478. case 'audio': return `/audios/${id}`;
  1479. case 'video': return `/videos/${id}`;
  1480. case 'torrent': return `/torrents/${id}`;
  1481. case 'forum': return `/forum/${encodeURIComponent(action.content?.key || action.tipId || action.id)}`;
  1482. case 'document': return `/documents/${id}`;
  1483. case 'bookmark': return `/bookmarks/${id}`;
  1484. case 'event': return `/events/${id}`;
  1485. case 'task': return `/tasks/${id}`;
  1486. case 'taskAssignment': return `/tasks/${encodeURIComponent(action.content?.taskId || action.tipId || action.id)}`;
  1487. case 'about': return `/author/${encodeURIComponent(action.author)}`;
  1488. case 'contact': return `/inhabitants`;
  1489. case 'pub': return `/invites`;
  1490. case 'market': return `/market/${id}`;
  1491. case 'shop': return `/shops/${id}`;
  1492. case 'shopProduct': return `/shops/product/${id}`;
  1493. case 'chat': return `/chats/${id}`;
  1494. case 'pad': return `/pads/${id}`;
  1495. case 'calendar': return `/calendars/${id}`;
  1496. case 'job': return `/jobs/${id}`;
  1497. case 'project': return `/projects/${id}`;
  1498. case 'report': return `/reports/${id}`;
  1499. case 'bankWallet': return `/wallet`;
  1500. case 'bankClaim': return `/banking${action.content?.epochId ? `/epoch/${encodeURIComponent(action.content.epochId)}` : ''}`;
  1501. case 'ubiClaim': return action.content?.transferId ? `/transfers/${encodeURIComponent(action.content.transferId)}` : `/transfers?filter=ubi`;
  1502. case 'gameScore': return `/games?filter=scoring`;
  1503. default: return `/activity`;
  1504. }
  1505. }
  1506. exports.activityView = (actions, filter, userId, q = '') => {
  1507. const title = filter === 'mine' ? i18n.yourActivity : i18n.globalActivity;
  1508. const desc = i18n.activityDesc;
  1509. const activityTypes = [
  1510. { type: 'recent', label: i18n.typeRecent },
  1511. { type: 'all', label: i18n.allButton },
  1512. { type: 'mine', label: i18n.mineButton },
  1513. { type: 'report', label: i18n.typeReport },
  1514. { type: 'karmaScore',label: i18n.typeKarmaScore },
  1515. { type: 'about', label: i18n.typeAbout },
  1516. { type: 'tribe', label: i18n.typeTribe },
  1517. { type: 'parliament',label: i18n.typeParliament },
  1518. { type: 'courts', label: i18n.typeCourts },
  1519. { type: 'votes', label: i18n.typeVotes },
  1520. { type: 'calendar', label: i18n.typeCalendar || 'Calendar' },
  1521. { type: 'event', label: i18n.typeEvent },
  1522. { type: 'task', label: i18n.typeTask },
  1523. { type: 'feed', label: i18n.typeFeed },
  1524. { type: 'post', label: i18n.typePost },
  1525. { type: 'spread', label: i18n.typeSpread },
  1526. { type: 'chat', label: i18n.typeChat },
  1527. { type: 'pad', label: i18n.typePad },
  1528. { type: 'forum', label: i18n.typeForum },
  1529. { type: 'map', label: i18n.typeMap },
  1530. { type: 'banking', label: i18n.typeBanking },
  1531. { type: 'market', label: i18n.typeMarket },
  1532. { type: 'shop', label: i18n.typeShop },
  1533. { type: 'project', label: i18n.typeProject },
  1534. { type: 'job', label: i18n.typeJob },
  1535. { type: 'curriculum',label: i18n.typeCurriculum },
  1536. { type: 'transfer', label: i18n.typeTransfer },
  1537. { type: 'aiExchange',label: i18n.typeAiExchange },
  1538. { type: 'gameScore', label: i18n.typeGameScore },
  1539. { type: 'pixelia', label: i18n.typePixelia },
  1540. { type: 'audio', label: i18n.typeAudio },
  1541. { type: 'bookmark', label: i18n.typeBookmark },
  1542. { type: 'image', label: i18n.typeImage },
  1543. { type: 'document', label: i18n.typeDocument },
  1544. { type: 'video', label: i18n.typeVideo },
  1545. { type: 'torrent', label: i18n.typeTorrent }
  1546. ];
  1547. let filteredActions;
  1548. if (filter === 'mine') {
  1549. filteredActions = actions.filter(action => action.author === userId && action.type !== 'tombstone');
  1550. } else if (filter === 'recent') {
  1551. const now = Date.now();
  1552. filteredActions = actions.filter(action => action.type !== 'tombstone' && action.ts && now - action.ts < 24 * 60 * 60 * 1000);
  1553. } else if (filter === 'banking') {
  1554. filteredActions = actions.filter(action => action.type !== 'tombstone' && (action.type === 'bankWallet' || action.type === 'bankClaim' || action.type === 'ubiClaim' || action.type === 'ubiclaimresult'));
  1555. } else if (filter === 'tribe') {
  1556. filteredActions = actions.filter(action => action.type === 'tribe');
  1557. } else if (filter === 'parliament') {
  1558. filteredActions = actions.filter(action => ['parliamentCandidature','parliamentTerm','parliamentProposal','parliamentRevocation','parliamentLaw'].includes(action.type));
  1559. } else if (filter === 'courts') {
  1560. filteredActions = actions.filter(action => {
  1561. const t = String(action.type || '').toLowerCase();
  1562. return t === 'courtscase' || t === 'courtsnomination' || t === 'courtsnominationvote';
  1563. });
  1564. } else if (filter === 'task') {
  1565. filteredActions = actions.filter(action => action.type !== 'tombstone' && (action.type === 'task' || action.type === 'taskAssignment'));
  1566. } else if (filter === 'spread') {
  1567. filteredActions = actions.filter(action => action.type === 'spread');
  1568. } else if (filter === 'gameScore') {
  1569. filteredActions = actions.filter(action => action.type === 'gameScore');
  1570. } else if (filter === 'torrent') {
  1571. filteredActions = actions.filter(action => action.type === 'torrent');
  1572. } else {
  1573. filteredActions = actions.filter(action => (action.type === filter || filter === 'all' || (filter === 'shop' && action.type === 'shopProduct')) && action.type !== 'tombstone');
  1574. }
  1575. const qs = String(q || '').trim();
  1576. if (qs) {
  1577. const qn = qs.toLowerCase();
  1578. filteredActions = filteredActions.filter(a0 => {
  1579. const t = String(a0.type || '').toLowerCase();
  1580. const author = String(a0.author || '').toLowerCase();
  1581. const id0 = String(a0.id || '').toLowerCase();
  1582. const c0 = a0.value?.content || a0.content || {};
  1583. const blob = [
  1584. t, author, id0,
  1585. c0.text, c0.title, c0.name, c0.description, c0.contentWarning,
  1586. c0.about, c0.contact,
  1587. c0.spreadTitle, c0.spreadText, c0.spreadOriginalAuthor,
  1588. c0.vote?.link,
  1589. c0.address?.host, c0.address?.key
  1590. ].filter(Boolean).join(' ').toLowerCase();
  1591. return blob.includes(qn);
  1592. });
  1593. }
  1594. let html = template(
  1595. title,
  1596. section(
  1597. div({ class: 'tags-header' },
  1598. h2(i18n.activityList),
  1599. p(desc)
  1600. ),
  1601. div({ class: 'activity-filter-grid' },
  1602. ...[
  1603. activityTypes.slice(0, 4),
  1604. activityTypes.slice(4, 12),
  1605. activityTypes.slice(12, 19),
  1606. activityTypes.slice(19, 26),
  1607. activityTypes.slice(26, 29),
  1608. activityTypes.slice(29)
  1609. ].map(col =>
  1610. div({ class: 'activity-filter-col' },
  1611. col.map(({ type, label }) =>
  1612. form({ method: 'GET', action: '/activity' },
  1613. input({ type: 'hidden', name: 'filter', value: type }),
  1614. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  1615. )
  1616. )
  1617. )
  1618. )
  1619. ),
  1620. section({ class: 'feed-container' }, renderActionCards(filteredActions, userId, actions))
  1621. )
  1622. );
  1623. const hasDocument = actions.some(a => a && a.type === 'document');
  1624. if (hasDocument) {
  1625. html += `
  1626. <script type="module" src="/js/pdf.min.mjs"></script>
  1627. <script src="/js/pdf-viewer.js"></script>
  1628. `;
  1629. }
  1630. return html;
  1631. };