git ssb

10+

Matt McKegg / patchwork



Commit a397d2b2add6be261bf7ddda868de8161e8ae5f3

allow searching backlinks and add to context menu

search by prefixing ID with `?`
Matt McKegg committed on 4/20/2018, 11:36:42 AM
Parent: 10f58a04da1ab33c03a561753d15c0f77098cbbb

Files changed

lib/context-menu-and-spellcheck.jschanged
locales/en.jsonchanged
main-window.jschanged
modules/page/html/render/search.jschanged
plugs/message/html/layout/mini.jschanged
plugs/message/html/render/vote.jsadded
lib/context-menu-and-spellcheck.jsView
@@ -2,11 +2,13 @@
22 var {SpellCheckHandler, ContextMenuListener, ContextMenuBuilder} = require('electron-spellchecker')
33 var {MenuItem, Menu} = remote
44 var ref = require('ssb-ref')
55
6+var navigateHandler = null
67 module.exports = setupContextMenuAndSpellCheck
78
8-function setupContextMenuAndSpellCheck (config) {
9+function setupContextMenuAndSpellCheck (config, navigate) {
10+ navigateHandler = navigate
911 window.spellCheckHandler = new SpellCheckHandler()
1012 window.spellCheckHandler.attachToInput()
1113
1214 // Start off as US English, America #1 (lol)
@@ -40,8 +42,17 @@
4042 menu.append(openLink)
4143 }
4244
4345 if (extractedRef) {
46+ if (navigateHandler) {
47+ menu.append(new MenuItem({
48+ label: 'Find Link References',
49+ click: function () {
50+ navigateHandler('?' + extractedRef)
51+ }
52+ }))
53+ this.addSeparator(menu)
54+ }
4455 var copyRef = new MenuItem({
4556 label: `Copy Link Ref (${extractedRef.slice(0, 10)}...)`,
4657 click: () => {
4758 // Omit the mailto: portion of the link; we just want the address
@@ -61,9 +72,9 @@
6172
6273 return menu
6374 }
6475
65- module.exports = new ContextMenuListener((info) => {
76+ module.exports.menu = new ContextMenuListener((info) => {
6677 contextMenuBuilder.buildMenuForElement(info).then((menu) => {
6778 var element = document.elementFromPoint(info.x, info.y)
6879 while (element && !element.msg) {
6980 element = element.parentNode
locales/en.jsonView
@@ -190,6 +190,7 @@
190190 "Choose a title": "Choose a title",
191191 "Choose date and time": "Choose date and time",
192192 "Choose Banner Image...": "Choose Banner Image...",
193193 "Describe the gathering (if you want)": "Describe the gathering (if you want)",
194- "Create Gathering": "Create Gathering"
194+ "Create Gathering": "Create Gathering",
195+ "liked": "liked"
195196 }
main-window.jsView
@@ -45,9 +45,9 @@
4545 'settings.obs.get': 'first',
4646 'intl.sync.i18n': 'first'
4747 }))
4848
49- setupContextMenuAndSpellCheck(api.config.sync.load())
49+ setupContextMenuAndSpellCheck(api.config.sync.load(), navigate)
5050
5151 const i18n = api.intl.sync.i18n
5252
5353 var id = api.keys.sync.id()
modules/page/html/render/search.jsView
@@ -5,14 +5,16 @@
55 var pullAbortable = require('pull-abortable')
66 var Scroller = require('../../../../lib/scroller')
77 var nest = require('depnest')
88 var Proxy = require('mutant/proxy')
9+var ref = require('ssb-ref')
910
1011 exports.needs = nest({
1112 'sbot.pull.stream': 'first',
1213 'keys.sync.id': 'first',
1314 'message.html.render': 'first',
14- 'intl.sync.i18n': 'first'
15+ 'intl.sync.i18n': 'first',
16+ 'sbot.pull.backlinks': 'first'
1517 })
1618
1719 exports.gives = nest('page.html.render')
1820
@@ -56,9 +58,9 @@
5658
5759 var realtimeAborter = pullAbortable()
5860
5961 pull(
60- api.sbot.pull.stream(sbot => sbot.patchwork.linearSearch({old: false, query: query.split(whitespace)})),
62+ getStream(query, true),
6163 realtimeAborter,
6264 pull.drain(msg => {
6365 updates.set(updates() + 1)
6466 })
@@ -100,17 +102,17 @@
100102 done.set(true)
101103 })
102104
103105 pull(
104- api.sbot.pull.stream(sbot => sbot.search.query({query})),
106+ getStream(query, false),
105107 pull.through(() => count.set(count() + 1)),
106108 aborter,
107109 pull.filter(msg => msg.value),
108110 scroller
109111 )
110112
111113 loading.set(computed([done, scroller.queue], (done, queue) => {
112- return !done && queue < 5
114+ return !done
113115 }))
114116 }
115117
116118 function renderMsg (msg) {
@@ -118,8 +120,25 @@
118120 highlight(el, createOrRegExp(query.split(whitespace)))
119121 return el
120122 }
121123 })
124+
125+ function getStream (query, realtime = false) {
126+ if (ref.isLink(query) || query.startsWith('#')) {
127+ return api.sbot.pull.backlinks({
128+ query: [ {$filter: { dest: query }} ],
129+ reverse: true,
130+ old: !realtime,
131+ index: 'DTA' // use asserted timestamps
132+ })
133+ } else {
134+ if (realtime) {
135+ return api.sbot.pull.stream(sbot => sbot.patchwork.linearSearch({old: false, query: query.split(whitespace)}))
136+ } else {
137+ return api.sbot.pull.stream(sbot => sbot.search.query({query}))
138+ }
139+ }
140+ }
122141 }
123142
124143 function createOrRegExp (ary) {
125144 return new RegExp(ary.map(function (e) {
plugs/message/html/layout/mini.jsView
@@ -32,9 +32,9 @@
3232 })
3333
3434 return nest('message.html.layout', layout)
3535
36- function layout (msg, {layout, previousId, priority, miniContent, content, includeReferences, includeForks = true}) {
36+ function layout (msg, {layout, previousId, priority, miniContent, content, includeReferences, includeForks = true, actions = true}) {
3737 if (!(layout === 'mini')) return
3838
3939 var classList = ['Message -mini']
4040
@@ -66,10 +66,10 @@
6666 messageHeader(msg, {
6767 replyInfo, priority, miniContent
6868 }),
6969 h('section', [content]),
70- computed(msg.key, (key) => {
71- if (ref.isMsg(key)) {
70+ computed([msg.key, actions], (key, actions) => {
71+ if (ref.isMsg(key) && actions) {
7272 return h('footer', [
7373 h('div.actions', [
7474 api.message.html.action(msg)
7575 ])
plugs/message/html/render/vote.jsView
@@ -1,0 +1,51 @@
1+var nest = require('depnest')
2+var extend = require('xtend')
3+
4+exports.needs = nest({
5+ 'message.html': {
6+ decorate: 'reduce',
7+ layout: 'first',
8+ link: 'first'
9+ },
10+ 'intl.sync.i18n': 'first'
11+})
12+
13+exports.gives = nest('message.html', {
14+ canRender: true,
15+ render: true
16+})
17+
18+exports.create = function (api) {
19+ const i18n = api.intl.sync.i18n
20+ return nest('message.html', {
21+ canRender: isRenderable,
22+ render: function (msg, opts) {
23+ if (!isRenderable(msg)) return
24+
25+ var element = api.message.html.layout(msg, extend({
26+ miniContent: messageContent(msg),
27+ layout: 'mini',
28+ actions: false
29+ }, opts))
30+
31+ return api.message.html.decorate(element, {
32+ msg
33+ })
34+ }
35+ })
36+
37+ function messageContent (msg) {
38+ var liked = msg.value.content.vote.value > 0
39+ var link = msg.value.content.vote.link
40+
41+ if (liked) {
42+ return [ i18n('liked'), ' ', api.message.html.link(link) ]
43+ } else {
44+ return [ i18n('unliked'), ' ', api.message.html.link(link) ]
45+ }
46+ }
47+
48+ function isRenderable (msg) {
49+ return (msg.value.content.type === 'vote' ? true : undefined) && msg.value.content.vote
50+ }
51+}

Built with git-ssb-web