activity_view.js 87 KB

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