Files: 8b4e456e87cad1c31bf2022137e937fe3a47c2ad / modules / message / html / missing.js
1980 bytesRaw
1 | var h = require('mutant/h') |
2 | var Value = require('mutant/value') |
3 | var when = require('mutant/when') |
4 | var ref = require('ssb-ref') |
5 | |
6 | var nest = require('depnest') |
7 | |
8 | exports.needs = nest({ |
9 | 'sbot.async.get': 'first', |
10 | 'profile.html.person': 'first', |
11 | 'message.html.meta': 'first', |
12 | 'intl.sync.i18n': 'first' |
13 | }) |
14 | |
15 | exports.gives = nest('message.html.missing') |
16 | |
17 | exports.create = function (api) { |
18 | const i18n = api.intl.sync.i18n |
19 | return nest('message.html.missing', function (id, hintMessage) { |
20 | var result = Value() |
21 | if (ref.isMsg(id)) { |
22 | api.sbot.async.get(id, function (_, value) { |
23 | if (!value) { |
24 | result.set(messageMissing(id, hintMessage)) |
25 | } |
26 | }) |
27 | } |
28 | |
29 | return result |
30 | }) |
31 | |
32 | function messageMissing (id, hintMessage) { |
33 | var possibleAuthor = only(hintMessage.value.content.reply) |
34 | var msg = { |
35 | key: id, |
36 | value: { |
37 | missing: true, |
38 | author: ref.isFeed(possibleAuthor) ? possibleAuthor : null |
39 | } |
40 | } |
41 | var element = h('Message -missing -reply', [ |
42 | h('header', [ |
43 | h('div.main', [ |
44 | h('div.main', [ |
45 | h('div.name', [ |
46 | '⚠️ ', |
47 | msg.value.author |
48 | ? [api.profile.html.person(msg.value.author), ' ', i18n('(missing message)')] |
49 | : h('strong', i18n('Missing message')), |
50 | i18n(' via '), api.profile.html.person(hintMessage.value.author)]), |
51 | h('div.meta', [h('a', {href: id}, id)]) |
52 | ]) |
53 | ]), |
54 | h('div.meta', [ |
55 | api.message.html.meta(msg) |
56 | ]) |
57 | ]), |
58 | h('section', [ |
59 | h('p', [i18n(`The author of this message could be outside of your follow range or they may be blocked.`)]) |
60 | ]) |
61 | ]) |
62 | |
63 | element.msg = msg |
64 | return element |
65 | } |
66 | } |
67 | |
68 | function only (arrayOrString) { |
69 | if (Array.isArray(arrayOrString) && arrayOrString.length === 1) { |
70 | return arrayOrString[0] |
71 | } else if (typeof arrayOrString === 'string') { |
72 | return arrayOrString |
73 | } |
74 | } |
75 |
Built with git-ssb-web