git ssb

2+

mixmix / ticktack



Commit 1c54b79b5ab38e97cc88860bb05c5820ed84ec85

make the suggest mentioner awesome and extendable

mix irving committed on 1/31/2018, 11:05:58 AM
Parent: f4097436ca51813b562fc191008b76f8bcb6c71b

Files changed

app/html/comments.jschanged
app/page/addressBook.jschanged
app/page/blogShow.jschanged
app/page/threadShow.jschanged
message/html/compose.jschanged
styles/patchSuggest.mcsschanged
app/html/comments.jsView
@@ -21,10 +21,10 @@
2121 exports.create = (api) => {
2222 return nest('app.html.comments', comments)
2323
2424 function comments (thread) {
25+ const strings = api.translations.sync.strings()
2526 const { messages, channel, lastId: branch } = thread
26- const strings = api.translations.sync.strings()
2727
2828 // TODO - move this up into Patchcore
2929 const messagesTree = computed(throttle(messages, 200), msgs => {
3030 return msgs
@@ -48,13 +48,16 @@
4848 // return messages.length > 5
4949 // })
5050 const { compose } = api.message.html
5151
52+ const feedIdsInThread = computed(thread.messages, msgs => {
53+ return msgs.map(m => m.value.author)
54+ })
5255
5356 return h('Comments', [
5457 // when(twoComposers, compose({ meta, shrink: true, canAttach: false })),
5558 map(messagesTree, msg => Comment(msg, root, branch)),
56- compose({ meta, shrink: false, canAttach: true, placeholder: strings.writeComment }),
59+ compose({ meta, feedIdsInThread, shrink: false, canAttach: true, placeholder: strings.writeComment }),
5760 ])
5861 }
5962
6063 function Comment (msgObs, root, branch) {
app/page/addressBook.jsView
@@ -44,13 +44,17 @@
4444 if (section === SEARCH)
4545 return suggester(input)
4646 else {
4747 const sectionRels = relationships[section]
48- if (!input) return sectionRels // show all e.g. friends
49- .reverse()
50- .map(id => { return { id, title: api.about.obs.name(id) } })
51- else // show suggestions, and filter just the ones we want e.g. friends
52- return suggester(input).filter(user => sectionRels.includes(user.id))
48+ if (!input) {
49+ return sectionRels // show all e.g. friends
50+ .reverse()
51+ .map(id => { return { id, title: api.about.obs.name(id) } })
52+ }
53+ else { // show suggestions, and filter just the ones we want e.g. friends
54+ return suggester(input, relationships.followers) // add extraIds to suggester
55+ .filter(user => sectionRels.includes(user.id))
56+ }
5357 }
5458 })
5559
5660 const goTo = (loc) => () => api.history.sync.push(loc)
app/page/blogShow.jsView
@@ -36,9 +36,9 @@
3636 const thread = api.feed.obs.thread(blogMsg.key)
3737 const comments = api.app.html.comments(thread)
3838 const branch = thread.lastId
3939
40- const { timeago, channel, markdown, compose } = api.message.html
40+ const { timeago, channel, markdown } = api.message.html
4141
4242 return h('Page -blogShow', [
4343 api.app.html.sideNav({ page: 'blogShow' }), // HACK to highlight discover
4444 h('Scroller.content', [
app/page/threadShow.jsView
@@ -29,11 +29,11 @@
2929 type: 'post',
3030 root,
3131 branch: thread.lastId,
3232 channel,
33- recps: get(location, 'value.content.recps')
33+ recps: get(location, 'value.content.recps'),
3434 }
35- const composer = api.message.html.compose({ meta, shrink: false })
35+ const composer = api.message.html.compose({ meta, thread, shrink: false })
3636
3737 return h('Page -threadShow', [
3838 api.app.html.sideNav(location),
3939 h('div.content', [
message/html/compose.jsView
@@ -1,6 +1,6 @@
11 const nest = require('depnest')
2-const { h, when, send, resolve, Value, computed } = require('mutant')
2+const { h, when, send, resolve, Value, computed, map } = require('mutant')
33 const assign = require('lodash/assign')
44 const ssbMentions = require('ssb-mentions')
55 const addSuggest = require('suggest-box')
66
@@ -24,16 +24,17 @@
2424
2525 function compose (options, cb) {
2626 var {
2727 meta, // required
28+ feedIdsInThread = [],
2829 placeholder,
2930 shrink = true,
3031 canAttach = true, canPreview = true,
31- prepublish
32+ prepublish,
3233 } = options
3334
3435 const strings = api.translations.sync.strings()
35- const getProfileSuggestions = api.about.async.suggest()
36+ const getUserSuggestions = api.about.async.suggest()
3637 const getChannelSuggestions = api.channel.async.suggest()
3738 const getEmojiSuggestions = api.emoji.async.suggest()
3839
3940 placeholder = placeholder || strings.writeMessage
@@ -71,11 +72,11 @@
7172 fileInput = api.blob.html.input(file => {
7273 files.push(file)
7374 filesById[file.link] = file
7475
75- var embed = file.type.match(/^image/) ? '!' : ''
76- var spacer = embed ? '\n' : ' '
77- var insertLink = spacer + embed + '[' + file.name + ']' + '(' + file.link + ')' + spacer
76+ var imgPrefix = file.type.match(/^image/) ? '!' : ''
77+ var spacer = imgPrefix ? '\n' : ' '
78+ var insertLink = spacer + imgPrefix + '[' + file.name + ']' + '(' + file.link + ')' + spacer
7879
7980 var pos = textArea.selectionStart
8081 var newText = textRaw().slice(0, pos) + insertLink + textRaw().slice(pos)
8182 textArea.value = newText
@@ -90,16 +91,20 @@
9091 // and we don't want that.
9192 else
9293 fileInput = h('input', { style: {visibility: 'hidden'} })
9394
94- var showPreview = Value(false)
95- var previewBtn = h('Button',
96- {
97- className: when(showPreview, '-strong', '-subtle'),
98- 'ev-click': () => showPreview.set(!showPreview())
99- },
100- when(showPreview, strings.blogNew.actions.edit, strings.blogNew.actions.preview)
101- )
95+ function PreviewSetup (strings) {
96+ var showPreview = Value(false)
97+ var previewBtn = h('Button',
98+ {
99+ className: when(showPreview, '-strong', '-subtle'),
100+ 'ev-click': () => showPreview.set(!showPreview())
101+ },
102+ when(showPreview, strings.blogNew.actions.edit, strings.blogNew.actions.preview)
103+ )
104+ return { previewBtn, showPreview }
105+ }
106+ var { previewBtn, showPreview } = PreviewSetup(strings)
102107 var preview = computed(textRaw, text => api.message.html.markdown(text))
103108
104109 var publishBtn = h('Button -primary', { 'ev-click': publish }, strings.sendMessage)
105110
@@ -119,9 +124,9 @@
119124 addSuggest(textArea, (inputText, cb) => {
120125 const char = inputText[0]
121126 const wordFragment = inputText.slice(1)
122127
123- if (char === '@') cb(null, getProfileSuggestions(wordFragment))
128+ if (char === '@') cb(null, getUserSuggestions(wordFragment, feedIdsInThread))
124129 if (char === '#') cb(null, getChannelSuggestions(wordFragment))
125130 if (char === ':') cb(null, getEmojiSuggestions(wordFragment))
126131 }, {cls: 'PatchSuggest'})
127132
styles/patchSuggest.mcssView
@@ -5,8 +5,9 @@
55 li {
66 img { $circleSmall }
77
88 small {
9+ div.aliases { max-width: 14.5rem }
910 div.key { font-size: 1rem }
1011 }
1112 }
1213 }

Built with git-ssb-web