Commit 932b0cb6e9a66f9391fcabd909a1b0becb5809f9
fixes after review
andre alves garzia committed on 4/24/2018, 6:51:05 PMParent: bd34a8d22b29ba32048c072fecfaaa2d0fb0af0f
Files changed
message/html/shares.js | changed |
message/html/subject.js | changed |
message/html/webshares.js | changed |
message/obs/shares.js | changed |
message/obs/webshares.js | changed |
message/html/shares.js | ||
---|---|---|
@@ -1,7 +1,8 @@ | ||
1 | 1 | var { h, computed, when, Value, resolve } = require('mutant') |
2 | 2 | var nest = require('depnest') |
3 | 3 | |
4 | + | |
4 | 5 | exports.needs = nest({ |
5 | 6 | 'keys.sync.id': 'first', |
6 | 7 | 'message.obs.shares': 'first', |
7 | 8 | 'sbot.async.publish': 'first', |
@@ -19,20 +20,15 @@ | ||
19 | 20 | var iShared = computed(shares, shares => shares.includes(id)) |
20 | 21 | var count = computed(shares, shares => shares.length ? shares.length : '') |
21 | 22 | var isOpen = Value(false) |
22 | 23 | var strings = api.translations.sync.strings() |
23 | - var publishAndClose = (msg) => { | |
24 | - publishShare(msg, resolve(captionRaw)) | |
25 | - isOpen.set(false) | |
26 | - } | |
27 | - | |
28 | 24 | var captionRaw = Value('') |
29 | 25 | var captionInput = h('textarea#caption', { |
30 | 26 | style: { |
31 | 27 | width: '90%' |
32 | 28 | }, |
33 | 29 | placeholder: strings.share.captionPlaceholder, |
34 | - value: computed(captionRaw, t => t), | |
30 | + value: captionRaw, | |
35 | 31 | 'ev-input': () => captionRaw.set(captionInput.value), |
36 | 32 | }) |
37 | 33 | |
38 | 34 | var confirmationDialog = h('div.dialog', [ |
@@ -43,34 +39,33 @@ | ||
43 | 39 | captionInput |
44 | 40 | ]), |
45 | 41 | h('div.actions', [ |
46 | 42 | h('Button', { 'ev-click': () => isOpen.set(false) }, strings.userShow.action.cancel), |
47 | - h('Button -primary', { 'ev-click': () => publishAndClose(msg, true) }, strings.share.action.share) | |
43 | + h('Button -primary', { 'ev-click': () => publishShare(msg, resolve(captionRaw), () => isOpen.set(false)) }, strings.share.action.share) | |
48 | 44 | ]) |
49 | 45 | ]) |
50 | 46 | |
51 | 47 | var lb = api.app.html.lightbox(confirmationDialog, isOpen) |
52 | 48 | |
53 | 49 | |
54 | 50 | return h('Shares', { 'ev-click': () => isOpen.set(!iShared()) }, [ |
55 | - h('i.fa', { className: when(iShared, 'fa-retweet', 'fa-retweet faint') }), | |
51 | + h('i.fa.fa-retweet', { className: when(iShared, '', 'faint') }), | |
56 | 52 | h('div.count', count), |
57 | 53 | lb |
58 | 54 | ]) |
59 | 55 | }) |
60 | 56 | |
61 | - function publishShare(msg, text, status = true) { | |
62 | - if (status) { | |
63 | - var share = { | |
64 | - type: 'share', | |
65 | - share: { link: msg.key, content: "blog", text: text } | |
66 | - } | |
67 | - if (msg.value.content.recps) { | |
68 | - share.recps = msg.value.content.recps.map(function (e) { | |
69 | - return e && typeof e !== 'string' ? e.link : e | |
70 | - }) | |
71 | - share.private = true | |
72 | - } | |
73 | - api.sbot.async.publish(share) | |
57 | + function publishShare(msg, text, cb) { | |
58 | + var share = { | |
59 | + type: 'share', | |
60 | + share: { link: msg.key, content: "blog", text: text } | |
74 | 61 | } |
62 | + if (msg.value.content.recps) { | |
63 | + share.recps = msg.value.content.recps.map(function (e) { | |
64 | + return e && typeof e !== 'string' ? e.link : e | |
65 | + }) | |
66 | + share.private = true | |
67 | + } | |
68 | + console.log("publishing share", share) | |
69 | + api.sbot.async.publish(share, cb) | |
75 | 70 | } |
76 | 71 | } |
message/html/subject.js | ||
---|---|---|
@@ -16,9 +16,8 @@ | ||
16 | 16 | |
17 | 17 | return nest('message.html.subject', subject) |
18 | 18 | |
19 | 19 | function subject(msg) { |
20 | - if (msg === undefined) debugger | |
21 | 20 | // test if it's a message ref, or a full message object |
22 | 21 | // a message ref is generally passed in if we're fetching the subject of a root message |
23 | 22 | if (isMsg(msg)) { |
24 | 23 | if (subjectCache[msg]) return subjectCache[msg] |
message/html/webshares.js | ||
---|---|---|
@@ -1,8 +1,7 @@ | ||
1 | 1 | var { h, computed, when, Value, resolve } = require('mutant') |
2 | 2 | var nest = require('depnest') |
3 | -var { clipboard } = require('electron') | |
4 | -var { shell } = require('electron') | |
3 | +var { clipboard, shell } = require('electron') | |
5 | 4 | |
6 | 5 | exports.needs = nest({ |
7 | 6 | 'keys.sync.id': 'first', |
8 | 7 | 'message.obs.webshares': 'first', |
message/obs/shares.js | ||
---|---|---|
@@ -14,8 +14,18 @@ | ||
14 | 14 | 'sbot.hook.publish': true, |
15 | 15 | 'message.obs.shares': true |
16 | 16 | }) |
17 | 17 | |
18 | +function isShare(c) { | |
19 | + if (c.type !== 'share') return false | |
20 | + | |
21 | + if (!c.share || !c.share.link || !ref.isMsg(c.share.link) || !c.share.hasOwnProperty('text')) { | |
22 | + return false | |
23 | + } | |
24 | + | |
25 | + return true | |
26 | +} | |
27 | + | |
18 | 28 | exports.create = function (api) { |
19 | 29 | var activeShares = new Set() |
20 | 30 | return nest({ |
21 | 31 | 'sbot.hook.publish': (msg) => { |
@@ -26,9 +36,9 @@ | ||
26 | 36 | } |
27 | 37 | |
28 | 38 | var c = msg.value.content |
29 | 39 | if (c.type !== 'share') return |
30 | - if (!c.share || !c.share.link || !c.share.text) return | |
40 | + if (!isShare(c)) return | |
31 | 41 | |
32 | 42 | activeShares.forEach((shares) => { |
33 | 43 | if (shares.id === c.share.link) { |
34 | 44 | shares.push(msg) |
@@ -56,9 +66,9 @@ | ||
56 | 66 | var shares = computed([backlinks.sync, concat([backlinks, merge])], (sync, backlinks) => { |
57 | 67 | if (sync) { |
58 | 68 | return backlinks.reduce((result, msg) => { |
59 | 69 | var c = msg.value.content |
60 | - if (c.type === 'share' && c.share && c.share.text && c.share.link === id) { | |
70 | + if (isShare(c) && c.share.link === id) { | |
61 | 71 | var value = result[msg.value.author] |
62 | 72 | if (!value || value[0] < msg.value.timestamp) { |
63 | 73 | result[msg.value.author] = [msg.value.timestamp, c.share.text] |
64 | 74 | } |
message/obs/webshares.js | ||
---|---|---|
@@ -14,8 +14,20 @@ | ||
14 | 14 | 'sbot.hook.publish': true, |
15 | 15 | 'message.obs.webshares': true |
16 | 16 | }) |
17 | 17 | |
18 | + | |
19 | +function isShare(c) { | |
20 | + if (c.type !== 'share') return false | |
21 | + | |
22 | + if (!c.share || !c.share.link || !ref.isMsg(c.share.link) || !c.share.hasOwnProperty('url')) { | |
23 | + return false | |
24 | + } | |
25 | + | |
26 | + return true | |
27 | +} | |
28 | + | |
29 | + | |
18 | 30 | exports.create = function (api) { |
19 | 31 | var activeShares = new Set() |
20 | 32 | return nest({ |
21 | 33 | 'sbot.hook.publish': (msg) => { |
@@ -25,11 +37,11 @@ | ||
25 | 37 | if (!msg) return |
26 | 38 | } |
27 | 39 | |
28 | 40 | var c = msg.value.content |
29 | - if (c.type !== 'share') return | |
30 | - if (!c.share || !c.share.link || !c.share.url) return | |
31 | 41 | |
42 | + if (!isShare(c)) return | |
43 | + | |
32 | 44 | activeShares.forEach((shares) => { |
33 | 45 | if (shares.id === c.share.link) { |
34 | 46 | shares.push(msg) |
35 | 47 | } |
@@ -56,9 +68,9 @@ | ||
56 | 68 | var shares = computed([backlinks.sync, concat([backlinks, merge])], (sync, backlinks) => { |
57 | 69 | if (sync) { |
58 | 70 | return backlinks.reduce((result, msg) => { |
59 | 71 | var c = msg.value.content |
60 | - if (c.type === 'share' && c.share && c.share.url && c.share.link === id) { | |
72 | + if (isShare(c) && c.share.link === id) { | |
61 | 73 | var value = result[msg.value.author] |
62 | 74 | if (!value || value[0] < msg.value.timestamp) { |
63 | 75 | result[msg.value.author] = [msg.value.timestamp, c.share.url] |
64 | 76 | } |
Built with git-ssb-web