Commit c2ad0e976a7bf704bd9348e463c24a5a2edb2f01
implement private messages
Dominic Tarr committed on 5/25/2016, 10:09:07 AMParent: 40f1bbca24bebf52de76487a678082890d30d057
Files changed
modules/compose.js | changed |
modules/private.js | changed |
modules/tabs.js | changed |
modules/compose.js | ||
---|---|---|
@@ -10,9 +10,14 @@ | ||
10 | 10 | exports.message_content = [] |
11 | 11 | exports.message_confirm = [] |
12 | 12 | |
13 | 13 | //this decorator expects to be the first |
14 | -exports.message_compose = function (meta, sbot) { | |
14 | + | |
15 | +function id (e) { return e } | |
16 | + | |
17 | +exports.message_compose = function (meta, prepublish, sbot) { | |
18 | + if('function' !== typeof prepublish) | |
19 | + sbot = prepublish, prepublish = id | |
15 | 20 | meta = meta || {} |
16 | 21 | if(!meta.type) throw new Error('message must have type') |
17 | 22 | var ta = h('textarea') |
18 | 23 | //h('pre.editable.fixed', 'HELLO') |
@@ -36,8 +41,13 @@ | ||
36 | 41 | h('div', h('div.column', ta, |
37 | 42 | h('button', 'publish', {onclick: function () { |
38 | 43 | meta.text = ta.value |
39 | 44 | meta.mentions = mentions(ta.value) |
45 | + try { | |
46 | + meta = prepublish(meta) | |
47 | + } catch (err) { | |
48 | + return alert(err.message) | |
49 | + } | |
40 | 50 | u.firstPlug(exports.message_confirm, meta, sbot) |
41 | 51 | }}))) |
42 | 52 | |
43 | 53 | suggest(ta, function (word, cb) { |
modules/private.js | ||
---|---|---|
@@ -2,9 +2,14 @@ | ||
2 | 2 | var ui = require('../ui') |
3 | 3 | var u = require('../util') |
4 | 4 | var pull = require('pull-stream') |
5 | 5 | var Scroller = require('pull-scroll') |
6 | +var ref = require('ssb-ref') | |
6 | 7 | |
8 | +exports.message_render = [] | |
9 | +exports.message_compose = [] | |
10 | +exports.message_unbox = [] | |
11 | + | |
7 | 12 | function unbox () { |
8 | 13 | return pull( |
9 | 14 | pull.filter(function (msg) { |
10 | 15 | return 'string' == typeof msg.value.content |
@@ -17,12 +22,27 @@ | ||
17 | 22 | } |
18 | 23 | |
19 | 24 | exports.screen_view = function (path, sbot) { |
20 | 25 | if(path === '/private') { |
21 | - | |
26 | + SBOT = sbot | |
22 | 27 | var content = h('div.column') |
28 | + var id = null | |
29 | + sbot.whoami(function (err, me) { | |
30 | + id = me.id | |
31 | + }) | |
23 | 32 | |
24 | - var div = h('div.column', {style: {'overflow':'auto'}}, content) | |
33 | + var div = h('div.column', {style: {'overflow':'auto'}}, | |
34 | + u.firstPlug(exports.message_compose, {type: 'post', recps: [], private: true}, | |
35 | + function (msg) { | |
36 | + msg.recps = [id].concat(msg.mentions).filter(function (e) { | |
37 | + return ref.isFeed('string' === typeof e ? e : e.link) | |
38 | + }) | |
39 | + if(!msg.recps.length) | |
40 | + throw new Error('cannot make private message without recipients - just mention them in the message') | |
41 | + return msg | |
42 | + }, | |
43 | + sbot), | |
44 | + content) | |
25 | 45 | var render = ui.createRenderers(exports.message_render, sbot) |
26 | 46 | |
27 | 47 | pull( |
28 | 48 | sbot.createLogStream({old: false}), |
@@ -41,19 +61,7 @@ | ||
41 | 61 | return div |
42 | 62 | } |
43 | 63 | } |
44 | 64 | |
45 | -exports.message_render = [] | |
46 | -exports.message_compose = [] | |
47 | -exports.message_unbox = [] | |
48 | 65 | |
49 | 66 | |
50 | 67 | |
51 | - | |
52 | - | |
53 | - | |
54 | - | |
55 | - | |
56 | - | |
57 | - | |
58 | - | |
59 | - |
modules/tabs.js | ||
---|---|---|
@@ -33,9 +33,11 @@ | ||
33 | 33 | |
34 | 34 | ev.preventDefault() |
35 | 35 | ev.stopPropagation() |
36 | 36 | |
37 | - if(!path) | |
37 | + //open external links. | |
38 | + //this ought to be made into something more runcible | |
39 | + if(/^https?/.test(link.href)) | |
38 | 40 | return require('shell').openExternal(link.href) |
39 | 41 | |
40 | 42 | if(tabs.has(path)) return tabs.select(path) |
41 | 43 | |
@@ -51,4 +53,5 @@ | ||
51 | 53 | exports.screen_view = [] |
52 | 54 | |
53 | 55 | |
54 | 56 | |
57 | + |
Built with git-ssb-web