git ssb

16+

Dominic / patchbay



Commit c2ad0e976a7bf704bd9348e463c24a5a2edb2f01

implement private messages

Dominic Tarr committed on 5/25/2016, 10:09:07 AM
Parent: 40f1bbca24bebf52de76487a678082890d30d057

Files changed

modules/compose.jschanged
modules/private.jschanged
modules/tabs.jschanged
modules/compose.jsView
@@ -10,9 +10,14 @@
1010 exports.message_content = []
1111 exports.message_confirm = []
1212
1313 //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
1520 meta = meta || {}
1621 if(!meta.type) throw new Error('message must have type')
1722 var ta = h('textarea')
1823 //h('pre.editable.fixed', 'HELLO')
@@ -36,8 +41,13 @@
3641 h('div', h('div.column', ta,
3742 h('button', 'publish', {onclick: function () {
3843 meta.text = ta.value
3944 meta.mentions = mentions(ta.value)
45+ try {
46+ meta = prepublish(meta)
47+ } catch (err) {
48+ return alert(err.message)
49+ }
4050 u.firstPlug(exports.message_confirm, meta, sbot)
4151 }})))
4252
4353 suggest(ta, function (word, cb) {
modules/private.jsView
@@ -2,9 +2,14 @@
22 var ui = require('../ui')
33 var u = require('../util')
44 var pull = require('pull-stream')
55 var Scroller = require('pull-scroll')
6+var ref = require('ssb-ref')
67
8+exports.message_render = []
9+exports.message_compose = []
10+exports.message_unbox = []
11+
712 function unbox () {
813 return pull(
914 pull.filter(function (msg) {
1015 return 'string' == typeof msg.value.content
@@ -17,12 +22,27 @@
1722 }
1823
1924 exports.screen_view = function (path, sbot) {
2025 if(path === '/private') {
21-
26+ SBOT = sbot
2227 var content = h('div.column')
28+ var id = null
29+ sbot.whoami(function (err, me) {
30+ id = me.id
31+ })
2332
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)
2545 var render = ui.createRenderers(exports.message_render, sbot)
2646
2747 pull(
2848 sbot.createLogStream({old: false}),
@@ -41,19 +61,7 @@
4161 return div
4262 }
4363 }
4464
45-exports.message_render = []
46-exports.message_compose = []
47-exports.message_unbox = []
4865
4966
5067
51-
52-
53-
54-
55-
56-
57-
58-
59-
modules/tabs.jsView
@@ -33,9 +33,11 @@
3333
3434 ev.preventDefault()
3535 ev.stopPropagation()
3636
37- if(!path)
37+ //open external links.
38+ //this ought to be made into something more runcible
39+ if(/^https?/.test(link.href))
3840 return require('shell').openExternal(link.href)
3941
4042 if(tabs.has(path)) return tabs.select(path)
4143
@@ -51,4 +53,5 @@
5153 exports.screen_view = []
5254
5355
5456
57+

Built with git-ssb-web