git ssb

10+

Matt McKegg / patchwork



Commit 85d9ae042b27a93cc430e3c2ca805da1d89bd739

profile suggest: prioritize thread participants, highlight following

Matt McKegg committed on 2/12/2018, 8:58:56 PM
Parent: 2a20acf33d2e0b90142c3b19c1a1fa74d59d32da

Files changed

modules/message/html/compose.jschanged
modules/page/html/render/message.jschanged
modules/profile/async/suggest.jschanged
styles/dark/suggest-box.mcsschanged
styles/light/suggest-box.mcsschanged
modules/message/html/compose.jsView
@@ -23,9 +23,9 @@
2323 exports.gives = nest('message.html.compose')
2424
2525 exports.create = function (api) {
2626 const i18n = api.intl.sync.i18n
27- return nest('message.html.compose', function ({shrink = true, isPrivate, meta, hooks, prepublish, placeholder = 'Write a message'}, cb) {
27+ return nest('message.html.compose', function ({shrink = true, isPrivate, participants, meta, hooks, prepublish, placeholder = 'Write a message'}, cb) {
2828 var files = []
2929 var filesById = {}
3030 var focused = Value(false)
3131 var hasContent = Value(false)
@@ -133,9 +133,9 @@
133133 }
134134
135135 addSuggest(textArea, (inputText, cb) => {
136136 if (inputText[0] === '@') {
137- cb(null, getProfileSuggestions(inputText.slice(1)))
137+ cb(null, getProfileSuggestions(inputText.slice(1), resolve(participants)))
138138 } else if (inputText[0] === '#') {
139139 cb(null, getChannelSuggestions(inputText.slice(1)))
140140 } else if (inputText[0] === ':') {
141141 // suggest emojis
modules/page/html/render/message.jsView
@@ -26,8 +26,9 @@
2626 var loader = h('div', {className: 'Loading -large'})
2727
2828 var result = Proxy(loader)
2929 var anchor = Value()
30+ var participants = Proxy([])
3031
3132 var meta = Struct({
3233 type: 'post',
3334 root: Proxy(id),
@@ -40,8 +41,9 @@
4041 var compose = api.message.html.compose({
4142 meta,
4243 isPrivate: when(meta.recps, true),
4344 shrink: false,
45+ participants,
4446 hooks: [
4547 AnchorHook('reply', anchor, (el) => el.focus())
4648 ],
4749 placeholder: when(meta.recps, i18n('Write a private reply'), i18n('Write a public reply'))
@@ -80,8 +82,12 @@
8082
8183 // if root thread, reply to last post
8284 meta.branch.set(isReply ? thread.branchId : thread.lastId)
8385
86+ participants.set(computed(thread.messages, messages => {
87+ return messages.map(msg => msg && msg.value && msg.value.author)
88+ }))
89+
8490 var container = h('Thread', [
8591 h('div.messages', [
8692 when(thread.branchId, h('a.full', {href: thread.rootId, anchor: id}, [i18n('View full thread')])),
8793 map(thread.messages, (msg) => {
modules/profile/async/suggest.jsView
@@ -13,26 +13,51 @@
1313
1414 exports.create = function (api) {
1515 var suggestions = null
1616 var recentSuggestions = null
17+ var following = null
1718
1819 return nest('profile.async.suggest', function () {
1920 loadSuggestions()
20- return function (word) {
21+ return function (word, defaultItems) {
22+ var defaultSuggestions = Array.isArray(defaultItems) && defaultItems.length ? suggestions().filter((item) => {
23+ return matches(item.title, word) && defaultItems.includes(item.id)
24+ }) : null
25+
2126 if (!word) {
22- return recentSuggestions()
27+ return defaultSuggestions || recentSuggestions()
2328 } else {
24- return suggestions().filter((item) => {
25- return item.title.toLowerCase().startsWith(word.toLowerCase())
29+ var result = defaultSuggestions || []
30+
31+ // prioritize people you follow
32+ suggestions().forEach((item) => {
33+ if (following().includes(item.id) && matches(item.title, word) && !result.some(v => v.id === item.id)) {
34+ result.push(item)
35+ }
2636 })
37+
38+ // next most recently active profiles
39+ recentSuggestions().forEach((item) => {
40+ if (matches(item.title, word) && !result.some(v => v.id === item.id)) {
41+ result.push(item)
42+ }
43+ })
44+
45+ // fallback to everyone
46+ suggestions().forEach((item) => {
47+ if (matches(item.title, word) && !result.some(v => v.id === item.id)) {
48+ result.push(item)
49+ }
50+ })
51+ return result
2752 }
2853 }
2954 })
3055
3156 function loadSuggestions () {
3257 if (!suggestions) {
3358 var id = api.keys.sync.id()
34- var following = api.contact.obs.following(id)
59+ following = api.contact.obs.following(id)
3560 var recentlyUpdated = api.profile.obs.recentlyUpdated()
3661 var contacts = computed([following, recentlyUpdated], function (a, b) {
3762 var result = Array.from(a)
3863 b.forEach((item, i) => {
@@ -42,9 +67,9 @@
4267 })
4368 return result
4469 })
4570
46- recentSuggestions = map(computed(recentlyUpdated, (items) => Array.from(items).slice(0, 10)), suggestion, {idle: true})
71+ recentSuggestions = map(computed(recentlyUpdated, (items) => Array.from(items).slice(0, 40)), suggestion, {idle: true})
4772 suggestions = map(contacts, suggestion, {idle: true})
4873 watch(recentSuggestions)
4974 watch(suggestions)
5075 }
@@ -55,9 +80,10 @@
5580 return Struct({
5681 title: name,
5782 id,
5883 subtitle: id.substring(0, 10),
59- value: computed([name, id], mention),
84+ value: computed([name, id], mention, {idle: true}),
85+ cls: computed([id, following], followingClass, {idle: true}),
6086 image: api.about.obs.imageUrl(id),
6187 showBoth: true
6288 })
6389 }
@@ -65,4 +91,15 @@
6591
6692 function mention (name, id) {
6793 return `[@${name}](${id})`
6894 }
95+
96+function followingClass (id, following) {
97+ if (following.includes(id)) {
98+ return 'following'
99+ }
100+}
101+
102+function matches (title, match) {
103+ if (!match) return true
104+ return title.toLowerCase().startsWith(match.toLowerCase())
105+}
styles/dark/suggest-box.mcssView
@@ -13,8 +13,17 @@
1313 ul {
1414 list-style-type: none;
1515 padding: 0;
1616
17+ li.following {
18+ font-weight: bold
19+
20+ strong {
21+ font-weight: bold
22+ $following
23+ }
24+ }
25+
1726 li {
1827 display: flex;
1928 align-items: center;
2029
styles/light/suggest-box.mcssView
@@ -12,8 +12,17 @@
1212 ul {
1313 list-style-type: none;
1414 padding: 0;
1515
16+ li.following {
17+ font-weight: bold
18+
19+ strong {
20+ font-weight: bold
21+ $following
22+ }
23+ }
24+
1625 li {
1726 display: flex;
1827 align-items: center;
1928

Built with git-ssb-web