activity_view.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. const { div, h2, p, section, button, form, a, input, img, textarea, br, span, video: videoHyperaxe, audio: audioHyperaxe, table, tr, td, th } = require("../server/node_modules/hyperaxe");
  2. const { template, i18n } = require('./main_views');
  3. const moment = require("../server/node_modules/moment");
  4. const { renderUrl } = require('../backend/renderUrl');
  5. function capitalize(str) {
  6. return typeof str === 'string' && str.length ? str[0].toUpperCase() + str.slice(1) : '';
  7. }
  8. function renderActionCards(actions, userId) {
  9. const validActions = actions
  10. .filter(action => {
  11. const content = action.value?.content || action.content;
  12. if (!content || typeof content !== 'object') return false;
  13. if (content.type === 'tombstone') return false;
  14. if (content.type === 'post' && content.private === true) return false;
  15. if (content.type === 'tribe' && content.isAnonymous === true) return false;
  16. if (content.type === 'task' && content.isPublic === "PRIVATE") return false;
  17. if (content.type === 'event' && content.isPublic === "private") return false;
  18. if (content.type === 'market') {
  19. if (content.stock === 0 && content.status !== 'SOLD') {
  20. return false;
  21. }
  22. }
  23. return true;
  24. })
  25. .sort((a, b) => b.ts - a.ts);
  26. if (!validActions.length) {
  27. return div({ class: "no-actions" }, p(i18n.noActions));
  28. }
  29. const seenDocumentTitles = new Set();
  30. return validActions.map(action => {
  31. const date = action.ts ? new Date(action.ts).toLocaleString() : "";
  32. const userLink = action.author
  33. ? a({ href: `/author/${encodeURIComponent(action.author)}` }, action.author)
  34. : 'unknown';
  35. const type = action.type || 'unknown';
  36. const typeLabel = i18n[`type${capitalize(type)}`] || type;
  37. const content = action.content || {};
  38. const cardBody = [];
  39. if (type === 'votes') {
  40. const { question, deadline, status, votes, totalVotes } = content;
  41. const votesList = votes && typeof votes === 'object'
  42. ? Object.entries(votes).map(([option, count]) => ({ option, count }))
  43. : [];
  44. cardBody.push(
  45. div({ class: 'card-section votes' },
  46. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.question + ':'), span({ class: 'card-value' }, question)),
  47. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.deadline + ':'), span({ class: 'card-value' }, deadline ? new Date(deadline).toLocaleString() : '')),
  48. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.voteTotalVotes + ':'), span({ class: 'card-value' }, totalVotes)),
  49. table(
  50. tr(...votesList.map(({ option }) => th(i18n[option] || option))),
  51. tr(...votesList.map(({ count }) => td(count)))
  52. )
  53. )
  54. );
  55. }
  56. if (type === 'transfer') {
  57. const { from, to, concept, amount, deadline, status, confirmedBy } = content;
  58. cardBody.push(
  59. div({ class: 'card-section transfer' },
  60. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.concept + ':'), span({ class: 'card-value' }, concept)),
  61. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.amount + ':'), span({ class: 'card-value' }, amount)),
  62. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.deadline + ':'), span({ class: 'card-value' }, deadline ? new Date(deadline).toLocaleString() : '')),
  63. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.status + ':'), span({ class: 'card-value' }, status))
  64. )
  65. );
  66. }
  67. if (type === 'pixelia') {
  68. const { author } = content;
  69. cardBody.push(
  70. div({ class: 'card-section pixelia' },
  71. div({ class: 'card-field' },
  72. a({ href: `/author/${encodeURIComponent(author)}`, class: 'activityVotePost' }, author)
  73. )
  74. )
  75. );
  76. }
  77. if (type === 'tribe') {
  78. const { title, image, description, tags, isLARP, inviteMode, isAnonymous, members } = content;
  79. const validTags = Array.isArray(tags) ? tags : [];
  80. cardBody.push(
  81. div({ class: 'card-section tribe' },
  82. h2({ class: 'tribe-title' },
  83. a({ href: `/tribe/${encodeURIComponent(action.id)}`, class: "user-link" }, title)
  84. ),
  85. typeof isAnonymous === 'boolean' ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.tribeIsAnonymousLabel+ ':'), span({ class: 'card-value' }, isAnonymous ? i18n.tribePrivate : i18n.tribePublic)) : "",
  86. inviteMode ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.tribeModeLabel) + ':'), span({ class: 'card-value' }, inviteMode.toUpperCase())) : "",
  87. typeof isLARP === 'boolean' ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.tribeLARPLabel+ ':'), span({ class: 'card-value' }, isLARP ? i18n.tribeYes : i18n.tribeNo)) : "",
  88. Array.isArray(members) ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.tribeMembersCount) + ':'), span({ class: 'card-value' }, members.length)) : "",
  89. br(),
  90. image
  91. ? img({ src: `/blob/${encodeURIComponent(image)}`, class: 'feed-image tribe-image' })
  92. : img({ src: '/assets/images/default-tribe.png', class: 'feed-image tribe-image' }),
  93. p({ class: 'tribe-description' }, ...renderUrl(description || '')),
  94. validTags.length
  95. ? div({ class: 'card-tags' }, validTags.map(tag =>
  96. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: "tag-link" }, `#${tag}`)))
  97. : ""
  98. )
  99. );
  100. }
  101. if (type === 'curriculum') {
  102. const { author, name, description, photo, personalSkills, oasisSkills, educationalSkills, languages, professionalSkills, status, preferences, createdAt, updatedAt} = content;
  103. cardBody.push(
  104. div({ class: 'card-section curriculum' },
  105. h2(a({ href: `/author/${encodeURIComponent(author)}`, class: "user-link" }, `@`, name)),
  106. div(
  107. { class: 'card-fields-container' },
  108. createdAt ?
  109. div(
  110. { class: 'card-field' },
  111. span({ class: 'card-label' }, i18n.cvCreatedAt + ':'),
  112. span({ class: 'card-value' }, moment(createdAt).format('YYYY-MM-DD HH:mm:ss'))
  113. )
  114. : "",
  115. updatedAt ?
  116. div(
  117. { class: 'card-field' },
  118. span({ class: 'card-label' }, i18n.cvUpdatedAt + ':'),
  119. span({ class: 'card-value' }, moment(updatedAt).format('YYYY-MM-DD HH:mm:ss'))
  120. )
  121. : ""
  122. ),
  123. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.cvStatusLabel + ':'), span({ class: 'card-value' }, status)) : "",
  124. preferences ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.cvPreferencesLabel || 'Preferences') + ':'), span({ class: 'card-value' }, preferences)) : "",
  125. languages ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.cvLanguagesLabel || 'Languages') + ':'), span({ class: 'card-value' }, languages.toUpperCase())) : "",
  126. photo ?
  127. [
  128. br(),
  129. img({ class: "cv-photo", src: `/blob/${encodeURIComponent(photo)}` }),
  130. br()
  131. ]
  132. : "",
  133. p(...renderUrl(description || "")),
  134. personalSkills && personalSkills.length
  135. ? div({ class: 'card-tags' }, personalSkills.map(skill =>
  136. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  137. )) : "",
  138. oasisSkills && oasisSkills.length
  139. ? div({ class: 'card-tags' }, oasisSkills.map(skill =>
  140. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  141. )) : "",
  142. educationalSkills && educationalSkills.length
  143. ? div({ class: 'card-tags' }, educationalSkills.map(skill =>
  144. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  145. )) : "",
  146. professionalSkills && professionalSkills.length
  147. ? div({ class: 'card-tags' }, professionalSkills.map(skill =>
  148. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  149. )) : "",
  150. )
  151. );
  152. }
  153. if (type === 'image') {
  154. const { url } = content;
  155. cardBody.push(
  156. div({ class: 'card-section image' },
  157. img({ src: `/blob/${encodeURIComponent(url)}`, class: 'feed-image img-content' })
  158. )
  159. );
  160. }
  161. if (content.type === 'audio') {
  162. const { url, mimeType, title } = content;
  163. cardBody.push(
  164. div({ class: 'card-section audio' },
  165. title?.trim() ? h2({ class: 'audio-title' }, title) : "",
  166. url
  167. ? div({ class: "audio-container" },
  168. audioHyperaxe({
  169. controls: true,
  170. src: `/blob/${encodeURIComponent(url)}`,
  171. type: mimeType
  172. })
  173. )
  174. : p(i18n.audioNoFile),
  175. )
  176. );
  177. }
  178. if (type === 'video') {
  179. const { url, mimeType, title } = content;
  180. cardBody.push(
  181. div({ class: 'card-section video' },
  182. title?.trim() ? h2({ class: 'video-title' }, title) : "",
  183. url
  184. ? div({ class: "video-container" },
  185. videoHyperaxe({
  186. controls: true,
  187. src: `/blob/${encodeURIComponent(url)}`,
  188. type: mimeType,
  189. preload: 'metadata',
  190. width: '640',
  191. height: '360'
  192. })
  193. )
  194. : p(i18n.videoNoFile)
  195. )
  196. );
  197. }
  198. if (type === 'document') {
  199. const { url, title, key } = content;
  200. if (title && seenDocumentTitles.has(title.trim())) {
  201. return null;
  202. }
  203. if (title) seenDocumentTitles.add(title.trim());
  204. cardBody.push(
  205. div({ class: 'card-section document' },
  206. title?.trim() ? h2({ class: 'document-title' }, title) : "",
  207. div({
  208. id: `pdf-container-${key || url}`,
  209. class: 'pdf-viewer-container',
  210. 'data-pdf-url': `/blob/${encodeURIComponent(url)}`
  211. })
  212. )
  213. );
  214. }
  215. if (type === 'bookmark') {
  216. const { url } = content;
  217. cardBody.push(
  218. div({ class: 'card-section bookmark' },
  219. h2(url ? p(a({ href: url, target: '_blank', class: "bookmark-url" }, url)) : "")
  220. )
  221. );
  222. }
  223. if (type === 'event') {
  224. const { title, description, date, location, price, attendees, organizer, isPublic } = content;
  225. cardBody.push(
  226. div({ class: 'card-section event' },
  227. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, title)),
  228. date ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.date + ':'), span({ class: 'card-value' }, new Date(date).toLocaleString())) : "",
  229. location ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.location || 'Location') + ':'), span({ class: 'card-value' }, location)) : "",
  230. typeof isPublic === 'boolean' ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.isPublic || 'Public') + ':'), span({ class: 'card-value' }, isPublic ? 'Yes' : 'No')) : "",
  231. price ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.price || 'Price') + ':'), span({ class: 'card-value' }, price + " ECO")) : "",
  232. br,
  233. organizer ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.organizer || 'Organizer') + ': '), a({ class: "user-link", href: `/author/${encodeURIComponent(organizer)}` }, organizer)) : "",
  234. Array.isArray(attendees) ? h2({ class: 'card-label' }, (i18n.attendees || 'Attendees') + ': ' + attendees.length) : "",
  235. )
  236. );
  237. }
  238. if (type === 'task') {
  239. const { title, startTime, endTime, priority, status, author } = content;
  240. cardBody.push(
  241. div({ class: 'card-section task' },
  242. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, title)),
  243. priority ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.priority || 'Priority') + ':'), span({ class: 'card-value' }, priority)) : "",
  244. startTime ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.taskStartTimeLabel || 'Start') + ':'), span({ class: 'card-value' }, new Date(startTime).toLocaleString())) : "",
  245. endTime ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.taskEndTimeLabel || 'End') + ':'), span({ class: 'card-value' }, new Date(endTime).toLocaleString())) : "",
  246. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.status + ':'), span({ class: 'card-value' }, status)) : "",
  247. )
  248. );
  249. }
  250. if (type === 'feed') {
  251. const { renderTextWithStyles } = require('../backend/renderTextWithStyles');
  252. const { text, refeeds } = content;
  253. cardBody.push(
  254. div({ class: 'card-section feed' },
  255. div({ class: 'feed-text', innerHTML: renderTextWithStyles(text) }),
  256. h2({ class: 'card-field' }, span({ class: 'card-label' }, i18n.tribeFeedRefeeds + ': '), span({ class: 'card-label' }, refeeds))
  257. )
  258. );
  259. }
  260. if (type === 'post') {
  261. const { contentWarning, text } = content;
  262. cardBody.push(
  263. div({ class: 'card-section post' },
  264. contentWarning ? h2({ class: 'content-warning' }, contentWarning) : '',
  265. p({ innerHTML: text })
  266. )
  267. );
  268. }
  269. if (type === 'forum') {
  270. const { root, category, title, text, key } = content;
  271. if (!root) {
  272. cardBody.push(
  273. div({ class: 'card-section forum' },
  274. div({ class: 'card-field', style: "font-size:1.12em; margin-bottom:5px;" },
  275. span({ class: 'card-label', style: "font-weight:800;color:#ff9800;" }, i18n.title + ': '),
  276. a({ href: `/forum/${encodeURIComponent(key || action.id)}`, style: "font-weight:800;color:#4fc3f7;" }, title)
  277. ),
  278. )
  279. )
  280. } else {
  281. let parentForum = actions.find(a => a.type === 'forum' && !a.content.root && (a.id === root || a.content.key === root));
  282. let parentCategory = parentForum?.content?.category || '';
  283. let parentTitle = parentForum?.content?.title || '';
  284. cardBody.push(
  285. div({ class: 'card-section forum' },
  286. div({ class: 'card-field', style: "font-size:1.12em; margin-bottom:5px;" },
  287. span({ class: 'card-label', style: "font-weight:800;color:#ff9800;" }, i18n.title + ': '),
  288. a({ href: `/forum/${encodeURIComponent(root)}`, style: "font-weight:800;color:#4fc3f7;" }, parentTitle)
  289. ),
  290. br(),
  291. div({ class: 'card-field', style: 'margin-bottom:12px;' },
  292. p({ style: "margin:0 0 8px 0; word-break:break-all;" }, ...renderUrl(text))
  293. )
  294. )
  295. )
  296. }
  297. }
  298. if (type === 'vote') {
  299. const { vote } = content;
  300. cardBody.push(
  301. div({ class: 'card-section vote' },
  302. p(
  303. a({ href: `/thread/${encodeURIComponent(vote.link)}#${encodeURIComponent(vote.link)}`, class: 'activityVotePost' }, vote.link)
  304. )
  305. )
  306. );
  307. }
  308. if (type === 'about') {
  309. const { about, name, image } = content;
  310. cardBody.push(
  311. div({ class: 'card-section about' },
  312. h2(a({ href: `/author/${encodeURIComponent(about)}`, class: "user-link" }, `@`, name)),
  313. image
  314. ? img({ src: `/blob/${encodeURIComponent(image)}` })
  315. : img({ src: '/assets/images/default-avatar.png', alt: name })
  316. )
  317. );
  318. }
  319. if (type === 'contact') {
  320. const { contact } = content;
  321. cardBody.push(
  322. div({ class: 'card-section contact' },
  323. p({ class: 'card-field' },
  324. a({ href: `/author/${encodeURIComponent(contact)}`, class: 'activitySpreadInhabitant2' }, contact)
  325. )
  326. )
  327. );
  328. }
  329. if (type === 'pub') {
  330. const { address } = content;
  331. const { host, key } = address;
  332. cardBody.push(
  333. div({ class: 'card-section pub' },
  334. p({ class: 'card-field' },
  335. a({ href: `/author/${encodeURIComponent(key)}`, class: 'activitySpreadInhabitant2' }, key)
  336. )
  337. )
  338. );
  339. }
  340. if (type === 'market') {
  341. const { item_type, title, price, status, deadline, stock, image, auctions_poll, seller } = content;
  342. const isSeller = seller && userId && seller === userId;
  343. cardBody.push(
  344. div({ class: 'card-section market' },
  345. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemTitle + ':'), span({ class: 'card-value' }, title)),
  346. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemType + ':'), span({ class: 'card-value' }, item_type.toUpperCase())),
  347. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemStatus + ": " ), span({ class: 'card-value' }, status.toUpperCase())),
  348. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.deadline + ':'), span({ class: 'card-value' }, deadline ? new Date(deadline).toLocaleString() : "")),
  349. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemStock + ':'), span({ class: 'card-value' }, stock)),
  350. br,
  351. image
  352. ? img({ src: `/blob/${encodeURIComponent(image)}` })
  353. : img({ src: '/assets/images/default-market.png', alt: title }),
  354. br,
  355. div({ class: "market-card price" },
  356. p(`${i18n.marketItemPrice}: ${price} ECO`)
  357. ),
  358. item_type === 'auction' && status !== 'SOLD' && status !== 'DISCARDED' && !isSeller
  359. ? div({ class: "auction-info" },
  360. auctions_poll && auctions_poll.length > 0
  361. ? [
  362. p({ class: "auction-bid-text" }, i18n.marketAuctionBids),
  363. table({ class: 'auction-bid-table' },
  364. tr(
  365. th(i18n.marketAuctionBidTime),
  366. th(i18n.marketAuctionUser),
  367. th(i18n.marketAuctionBidAmount)
  368. ),
  369. ...auctions_poll.map(bid => {
  370. const [bidderId, bidAmount, bidTime] = bid.split(':');
  371. return tr(
  372. td(moment(bidTime).format('YYYY-MM-DD HH:mm:ss')),
  373. td(a({ href: `/author/${encodeURIComponent(userId)}` }, userId)),
  374. td(`${parseFloat(bidAmount).toFixed(6)} ECO`)
  375. );
  376. })
  377. )
  378. ]
  379. : p(i18n.marketNoBids),
  380. form({ method: "POST", action: `/market/bid/${encodeURIComponent(action.id)}` },
  381. input({ type: "number", name: "bidAmount", step: "0.000001", min: "0.000001", placeholder: i18n.marketYourBid, required: true }),
  382. br(),
  383. button({ class: "buy-btn", type: "submit" }, i18n.marketPlaceBidButton)
  384. )
  385. ) : "",
  386. item_type === 'exchange' && status !== 'SOLD' && status !== 'DISCARDED' && !isSeller
  387. ? form({ method: "POST", action: `/market/buy/${encodeURIComponent(action.id)}` },
  388. button({ class: "buy-btn", type: "submit" }, i18n.marketActionsBuy)
  389. ) : ""
  390. )
  391. );
  392. }
  393. if (type === 'report') {
  394. const { title, confirmations, severity, status } = content;
  395. cardBody.push(
  396. div({ class: 'card-section report' },
  397. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, title)),
  398. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.status + ':'), span({ class: 'card-value' }, status)) : "",
  399. severity ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.severity || 'Severity') + ':'), span({ class: 'card-value' }, severity.toUpperCase())) : "",
  400. Array.isArray(confirmations) ? h2({ class: 'card-label' }, (i18n.transfersConfirmations) + ': ' + confirmations.length) : "",
  401. )
  402. );
  403. }
  404. if (type === 'job') {
  405. const { title, job_type, tasks, location, vacants, salary, status, subscribers } = content;
  406. cardBody.push(
  407. div({ class: 'card-section report' },
  408. div({ class: 'card-field' },
  409. span({ class: 'card-label' }, i18n.title + ':'),
  410. span({ class: 'card-value' }, title)
  411. ),
  412. salary && div({ class: 'card-field' },
  413. span({ class: 'card-label' }, i18n.jobSalary + ':'),
  414. span({ class: 'card-value' }, salary + ' ECO')
  415. ),
  416. status && div({ class: 'card-field' },
  417. span({ class: 'card-label' }, i18n.jobStatus + ':'),
  418. span({ class: 'card-value' }, status.toUpperCase())
  419. ),
  420. job_type && div({ class: 'card-field' },
  421. span({ class: 'card-label' }, i18n.jobType + ':'),
  422. span({ class: 'card-value' }, job_type.toUpperCase())
  423. ),
  424. location && div({ class: 'card-field' },
  425. span({ class: 'card-label' }, i18n.jobLocation + ':'),
  426. span({ class: 'card-value' }, location.toUpperCase())
  427. ),
  428. vacants && div({ class: 'card-field' },
  429. span({ class: 'card-label' }, i18n.jobVacants + ':'),
  430. span({ class: 'card-value' }, vacants)
  431. ),
  432. div({ class: 'card-field' },
  433. span({ class: 'card-label' }, i18n.jobSubscribers + ':'),
  434. span({ class: 'card-value' },
  435. Array.isArray(subscribers) && subscribers.length > 0
  436. ? `${subscribers.length}`
  437. : i18n.noSubscribers.toUpperCase()
  438. )
  439. ),
  440. )
  441. );
  442. }
  443. return div({ class: 'card card-rpg' },
  444. div({ class: 'card-header' },
  445. h2({ class: 'card-label' }, `[${typeLabel}]`),
  446. type !== 'feed' && (!action.tipId || action.tipId === action.id)
  447. ? form({ method: "GET", action: getViewDetailsAction(type, action) },
  448. button({ type: "submit", class: "filter-btn" }, i18n.viewDetails)
  449. )
  450. : ''
  451. ),
  452. div({ class: 'card-body' }, ...cardBody),
  453. p({ class: 'card-footer' },
  454. span({ class: 'date-link' }, `${date} ${i18n.performed} `),
  455. a({ href: `/author/${encodeURIComponent(action.author)}`, class: 'user-link' }, `${action.author}`)
  456. )
  457. );
  458. });
  459. }
  460. function getViewDetailsAction(type, action) {
  461. const id = encodeURIComponent(action.tipId || action.id);
  462. switch (type) {
  463. case 'votes': return `/votes/${id}`;
  464. case 'transfer': return `/transfers/${id}`;
  465. case 'pixelia': return `/pixelia`;
  466. case 'tribe': return `/tribe/${id}`;
  467. case 'curriculum': return `/inhabitant/${encodeURIComponent(action.author)}`;
  468. case 'image': return `/images/${id}`;
  469. case 'audio': return `/audios/${id}`;
  470. case 'video': return `/videos/${id}`;
  471. case 'forum':
  472. return `/forum/${encodeURIComponent(action.content?.key || action.tipId || action.id)}`;
  473. case 'document': return `/documents/${id}`;
  474. case 'bookmark': return `/bookmarks/${id}`;
  475. case 'event': return `/events/${id}`;
  476. case 'task': return `/tasks/${id}`;
  477. case 'about': return `/author/${encodeURIComponent(action.author)}`;
  478. case 'post': return `/thread/${id}#${id}`;
  479. case 'vote': return `/thread/${encodeURIComponent(action.content.vote.link)}#${encodeURIComponent(action.content.vote.link)}`;
  480. case 'contact': return `/inhabitants`;
  481. case 'pub': return `/invites`;
  482. case 'market': return `/market/${id}`;
  483. case 'job': return `/jobs/${id}`;
  484. case 'report': return `/reports/${id}`;
  485. }
  486. }
  487. exports.activityView = (actions, filter, userId) => {
  488. const title = filter === 'mine' ? i18n.yourActivity : i18n.globalActivity;
  489. const desc = i18n.activityDesc;
  490. const activityTypes = [
  491. { type: 'recent', label: i18n.typeRecent },
  492. { type: 'all', label: i18n.allButton },
  493. { type: 'mine', label: i18n.mineButton },
  494. { type: 'votes', label: i18n.typeVotes },
  495. { type: 'event', label: i18n.typeEvent },
  496. { type: 'task', label: i18n.typeTask },
  497. { type: 'report', label: i18n.typeReport },
  498. { type: 'tribe', label: i18n.typeTribe },
  499. { type: 'about', label: i18n.typeAbout },
  500. { type: 'curriculum', label: i18n.typeCurriculum },
  501. { type: 'market', label: i18n.typeMarket },
  502. { type: 'job', label: i18n.typeJob },
  503. { type: 'transfer', label: i18n.typeTransfer },
  504. { type: 'feed', label: i18n.typeFeed },
  505. { type: 'post', label: i18n.typePost },
  506. { type: 'pixelia', label: i18n.typePixelia },
  507. { type: 'forum', label: i18n.typeForum },
  508. { type: 'bookmark', label: i18n.typeBookmark },
  509. { type: 'image', label: i18n.typeImage },
  510. { type: 'video', label: i18n.typeVideo },
  511. { type: 'audio', label: i18n.typeAudio },
  512. { type: 'document', label: i18n.typeDocument }
  513. ];
  514. let filteredActions;
  515. if (filter === 'mine') {
  516. filteredActions = actions.filter(action => actions.author === userId && action.type !== 'tombstone');
  517. } else if (filter === 'recent') {
  518. const now = Date.now();
  519. filteredActions = actions.filter(action =>
  520. action.type !== 'tombstone' && action.ts && now - action.ts < 24 * 60 * 60 * 1000
  521. );
  522. } else {
  523. filteredActions = actions.filter(action => (action.type === filter || filter === 'all') && action.type !== 'tombstone');
  524. }
  525. let html = template(
  526. title,
  527. section(
  528. div({ class: 'tags-header' },
  529. h2(i18n.activityList),
  530. p(desc)
  531. ),
  532. form({ method: 'GET', action: '/activity' },
  533. div({ class: 'mode-buttons', style: 'display:grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 24px;' },
  534. div({
  535. style: 'display: flex; flex-direction: column; gap: 8px;'
  536. },
  537. activityTypes.slice(0, 3).map(({ type, label }) =>
  538. form({ method: 'GET', action: '/activity' },
  539. input({ type: 'hidden', name: 'filter', value: type }),
  540. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  541. )
  542. )
  543. ),
  544. div({
  545. style: 'display: flex; flex-direction: column; gap: 8px;'
  546. },
  547. activityTypes.slice(3, 7).map(({ type, label }) =>
  548. form({ method: 'GET', action: '/activity' },
  549. input({ type: 'hidden', name: 'filter', value: type }),
  550. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  551. )
  552. )
  553. ),
  554. div({
  555. style: 'display: flex; flex-direction: column; gap: 8px;'
  556. },
  557. activityTypes.slice(7, 11).map(({ type, label }) =>
  558. form({ method: 'GET', action: '/activity' },
  559. input({ type: 'hidden', name: 'filter', value: type }),
  560. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  561. )
  562. )
  563. ),
  564. div({
  565. style: 'display: flex; flex-direction: column; gap: 8px;'
  566. },
  567. activityTypes.slice(11, 16).map(({ type, label }) =>
  568. form({ method: 'GET', action: '/activity' },
  569. input({ type: 'hidden', name: 'filter', value: type }),
  570. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  571. )
  572. )
  573. ),
  574. div({
  575. style: 'display: flex; flex-direction: column; gap: 8px;'
  576. },
  577. activityTypes.slice(16, 22).map(({ type, label }) =>
  578. form({ method: 'GET', action: '/activity' },
  579. input({ type: 'hidden', name: 'filter', value: type }),
  580. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  581. )
  582. )
  583. )
  584. )
  585. ),
  586. section({ class: 'feed-container' }, renderActionCards(filteredActions, userId))
  587. )
  588. );
  589. const hasDocument = actions.some(a => a && a.type === 'document');
  590. if (hasDocument) {
  591. html += `
  592. <script type="module" src="/js/pdf.min.mjs"></script>
  593. <script src="/js/pdf-viewer.js"></script>
  594. `;
  595. }
  596. return html;
  597. };