activity_view.js 72 KB

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