git ssb

2+

mixmix / ticktack



Commit 932b0cb6e9a66f9391fcabd909a1b0becb5809f9

fixes after review

andre alves garzia committed on 4/24/2018, 6:51:05 PM
Parent: bd34a8d22b29ba32048c072fecfaaa2d0fb0af0f

Files changed

message/html/shares.jschanged
message/html/subject.jschanged
message/html/webshares.jschanged
message/obs/shares.jschanged
message/obs/webshares.jschanged
message/html/shares.jsView
@@ -1,7 +1,8 @@
11 var { h, computed, when, Value, resolve } = require('mutant')
22 var nest = require('depnest')
33
4+
45 exports.needs = nest({
56 'keys.sync.id': 'first',
67 'message.obs.shares': 'first',
78 'sbot.async.publish': 'first',
@@ -19,20 +20,15 @@
1920 var iShared = computed(shares, shares => shares.includes(id))
2021 var count = computed(shares, shares => shares.length ? shares.length : '')
2122 var isOpen = Value(false)
2223 var strings = api.translations.sync.strings()
23- var publishAndClose = (msg) => {
24- publishShare(msg, resolve(captionRaw))
25- isOpen.set(false)
26- }
27-
2824 var captionRaw = Value('')
2925 var captionInput = h('textarea#caption', {
3026 style: {
3127 width: '90%'
3228 },
3329 placeholder: strings.share.captionPlaceholder,
34- value: computed(captionRaw, t => t),
30+ value: captionRaw,
3531 'ev-input': () => captionRaw.set(captionInput.value),
3632 })
3733
3834 var confirmationDialog = h('div.dialog', [
@@ -43,34 +39,33 @@
4339 captionInput
4440 ]),
4541 h('div.actions', [
4642 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)
4844 ])
4945 ])
5046
5147 var lb = api.app.html.lightbox(confirmationDialog, isOpen)
5248
5349
5450 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') }),
5652 h('div.count', count),
5753 lb
5854 ])
5955 })
6056
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 }
7461 }
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)
7570 }
7671 }
message/html/subject.jsView
@@ -16,9 +16,8 @@
1616
1717 return nest('message.html.subject', subject)
1818
1919 function subject(msg) {
20- if (msg === undefined) debugger
2120 // test if it's a message ref, or a full message object
2221 // a message ref is generally passed in if we're fetching the subject of a root message
2322 if (isMsg(msg)) {
2423 if (subjectCache[msg]) return subjectCache[msg]
message/html/webshares.jsView
@@ -1,8 +1,7 @@
11 var { h, computed, when, Value, resolve } = require('mutant')
22 var nest = require('depnest')
3-var { clipboard } = require('electron')
4-var { shell } = require('electron')
3+var { clipboard, shell } = require('electron')
54
65 exports.needs = nest({
76 'keys.sync.id': 'first',
87 'message.obs.webshares': 'first',
message/obs/shares.jsView
@@ -14,8 +14,18 @@
1414 'sbot.hook.publish': true,
1515 'message.obs.shares': true
1616 })
1717
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+
1828 exports.create = function (api) {
1929 var activeShares = new Set()
2030 return nest({
2131 'sbot.hook.publish': (msg) => {
@@ -26,9 +36,9 @@
2636 }
2737
2838 var c = msg.value.content
2939 if (c.type !== 'share') return
30- if (!c.share || !c.share.link || !c.share.text) return
40+ if (!isShare(c)) return
3141
3242 activeShares.forEach((shares) => {
3343 if (shares.id === c.share.link) {
3444 shares.push(msg)
@@ -56,9 +66,9 @@
5666 var shares = computed([backlinks.sync, concat([backlinks, merge])], (sync, backlinks) => {
5767 if (sync) {
5868 return backlinks.reduce((result, msg) => {
5969 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) {
6171 var value = result[msg.value.author]
6272 if (!value || value[0] < msg.value.timestamp) {
6373 result[msg.value.author] = [msg.value.timestamp, c.share.text]
6474 }
message/obs/webshares.jsView
@@ -14,8 +14,20 @@
1414 'sbot.hook.publish': true,
1515 'message.obs.webshares': true
1616 })
1717
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+
1830 exports.create = function (api) {
1931 var activeShares = new Set()
2032 return nest({
2133 'sbot.hook.publish': (msg) => {
@@ -25,11 +37,11 @@
2537 if (!msg) return
2638 }
2739
2840 var c = msg.value.content
29- if (c.type !== 'share') return
30- if (!c.share || !c.share.link || !c.share.url) return
3141
42+ if (!isShare(c)) return
43+
3244 activeShares.forEach((shares) => {
3345 if (shares.id === c.share.link) {
3446 shares.push(msg)
3547 }
@@ -56,9 +68,9 @@
5668 var shares = computed([backlinks.sync, concat([backlinks, merge])], (sync, backlinks) => {
5769 if (sync) {
5870 return backlinks.reduce((result, msg) => {
5971 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) {
6173 var value = result[msg.value.author]
6274 if (!value || value[0] < msg.value.timestamp) {
6375 result[msg.value.author] = [msg.value.timestamp, c.share.url]
6476 }

Built with git-ssb-web