Files: 5ad997b45961f9143176e86d336daddac8c2aa0f / modules_core / message-confirm.js
1716 bytesRaw
1 | var lightbox = require('hyperlightbox') |
2 | var h = require('hyperscript') |
3 | var u = require('../util') |
4 | var self_id = require('../keys').id |
5 | //publish or add |
6 | |
7 | var plugs = require('../plugs') |
8 | |
9 | exports.needs = { |
10 | publish: 'first', message_content: 'first', avatar: 'first', |
11 | message_meta: 'map' |
12 | } |
13 | |
14 | exports.gives = 'message_confirm' |
15 | |
16 | //var publish = plugs.first(exports.sbot_publish = []) |
17 | //var message_content = plugs.first(exports.message_content = []) |
18 | //var avatar = plugs.first(exports.avatar = []) |
19 | //var message_meta = plugs.map(exports.message_meta = []) |
20 | // |
21 | exports.create = function (api) { |
22 | return function (content, cb) { |
23 | |
24 | cb = cb || function () {} |
25 | |
26 | var lb = lightbox() |
27 | document.body.appendChild(lb) |
28 | |
29 | var msg = { |
30 | key: "DRAFT", |
31 | value: { |
32 | author: self_id, |
33 | previous: null, |
34 | sequence: null, |
35 | timestamp: Date.now(), |
36 | content: content |
37 | } |
38 | } |
39 | |
40 | var okay = h('button.btn.btn-primary', 'Send', {onclick: function () { |
41 | lb.remove() |
42 | api.publish(content, cb) |
43 | }}) |
44 | |
45 | var cancel = h('button.btn.btn-default', 'Cancel', {onclick: function () { |
46 | lb.remove() |
47 | cb(null) |
48 | }}) |
49 | |
50 | okay.addEventListener('keydown', function (ev) { |
51 | if(ev.keyCode === 27) cancel.click() //escape |
52 | }) |
53 | |
54 | lb.show(h('div.column.message-confirm', |
55 | h('div.panel.panel-default', |
56 | h('div.panel-heading', |
57 | h('div.message_meta.pull-right', api.message_meta(msg)), |
58 | h('div.avatar', api.avatar(msg.value.author, 'avatar')) |
59 | ), |
60 | h('div.panel-body', api.message_content(msg) |
61 | || h('pre', JSON.stringify(msg, null, 2))) |
62 | ), |
63 | h('div.btn-group', okay, cancel) |
64 | )) |
65 | |
66 | okay.focus() |
67 | } |
68 | } |
69 |
Built with git-ssb-web