git ssb

16+

Dominic / patchbay



Tree: 682c62ee009cae46f4f5328ce86d4c2b938b2eb2

Files: 682c62ee009cae46f4f5328ce86d4c2b938b2eb2 / modules / compose.js

1847 bytesRaw
1var h = require('hyperscript')
2var u = require('../util')
3var suggest = require('suggest-box')
4var cont = require('cont')
5var mentions = require('ssb-mentions')
6var lightbox = require('hyperlightbox')
7
8exports.suggest = []
9exports.publish = []
10exports.message_content = []
11exports.message_confirm = []
12
13//this decorator expects to be the first
14
15function id (e) { return e }
16
17exports.message_compose = function (meta, prepublish, sbot) {
18 if('function' !== typeof prepublish)
19 sbot = prepublish, prepublish = id
20 meta = meta || {}
21 if(!meta.type) throw new Error('message must have type')
22 var ta = h('textarea')
23 //h('pre.editable.fixed', 'HELLO')
24 //ta.setAttribute('contenteditable', '')
25
26 var blur
27 ta.addEventListener('focus', function () {
28 clearTimeout(blur)
29 ta.style.height = '200px'
30 })
31 ta.addEventListener('blur', function () {
32 //don't shrink right away, so there is time
33 //to click the publish button.
34 clearTimeout(blur)
35 blur = setTimeout(function () {
36 ta.style.height = '50px'
37 }, 200)
38 })
39
40 var composer =
41 h('div', h('div.column', ta,
42 h('button', 'publish', {onclick: function () {
43 meta.text = ta.value
44 meta.mentions = mentions(ta.value)
45 try {
46 meta = prepublish(meta)
47 } catch (err) {
48 return alert(err.message)
49 }
50 u.firstPlug(exports.message_confirm, meta, sbot)
51 }})))
52
53 suggest(ta, function (word, cb) {
54 cont.para(exports.suggest.map(function (fn) {
55 return function (cb) { fn(word, sbot, cb) }
56 }))
57 (function (err, results) {
58 if(err) console.error(err)
59 results = results.reduce(function (ary, item) {
60 return ary.concat(item)
61 }, []).sort(function (a, b) {
62 return b.rank - a.rank
63 }).filter(Boolean)
64
65 cb(null, results)
66 })
67 }, {})
68
69 return composer
70
71}
72
73
74
75
76
77

Built with git-ssb-web