git ssb

16+

Dominic / patchbay



Commit 645ea1809f02b239e03e301a0c96fe35bb731f01

add aliases to suggest mention

mix irving committed on 9/12/2017, 7:49:19 AM
Parent: 916bd66722dcbec3a08c1049de38ed0d17a92cc6

Files changed

about/async/suggest.jschanged
app/html/suggest-box.mcsschanged
channel/async/suggest.jschanged
message/html/compose.jschanged
about/async/suggest.jsView
@@ -1,12 +1,15 @@
11 var nest = require('depnest')
2-var { Struct, map, concat, dictToCollection, computed, lookup, watch, keys, resolve } = require('mutant')
2 +var { h, Struct, map, concat, dictToCollection, computed, lookup, watch, keys, resolve } = require('mutant')
33
4 +var KEY_SAMPLE_LENGTH = 10 // includes @
5 +
46 exports.gives = nest('about.async.suggest')
57
68 exports.needs = nest({
79 'about.obs.groupedValues': 'first',
810 'about.obs.name': 'first',
11 + 'about.obs.names': 'first',
912 'about.obs.imageUrl': 'first',
1013 'contact.obs.following': 'first',
1114 'feed.obs.recent': 'first',
1215 'keys.sync.id': 'first'
@@ -22,11 +25,42 @@
2225 loadSuggestions()
2326 return function (word) {
2427 if (!word) return recentSuggestions()
2528
26- return suggestions()
27- .filter(item => ~item.title.indexOf(word))
28- .reverse()
29 + wordLower = word.toLowerCase()
30 + const nameMatches = suggestions()
31 + .filter(item => {
32 + // if (item.title) return ~item.title.toLowerCase().indexOf(wordLower)
33 + if (item._name) return ~item._name.toLowerCase().indexOf(wordLower)
34 + return ~item.subtitle.toLowerCase().indexOf(wordLower)
35 + })
36 +
37 +
38 + return nameMatches
39 + .sort((a, b) => { // sort primary aliases to top
40 + if (a._name.indexOf(word) === 0) return -1
41 + if (b._name.indexOf(word) === 0) return +1
42 +
43 + if (a._name.toLowerCase().indexOf(word) === 0) return -1
44 + if (b._name.toLowerCase().indexOf(word) === 0) return +1
45 + })
46 + .sort((a, b) => { // sort into blocks of id
47 + if (a.id === b.id) return 0
48 + if (a.id > b.id) return -1
49 + if (a.id < b.id) return +1
50 + })
51 + .reduce((sofar, match) => {
52 + // prune to the first instance of each id
53 + // this presumes if you were typing e.g. "dino" you don't need "ahdinosaur" as well
54 + if (sofar.find(el => el.id === match.id)) return sofar
55 +
56 + return [...sofar, match]
57 + }, [])
58 + // .sort((a, b) => { // sort isTopAlias avatar to top
59 + // if (a.id !== b.id) return 0
60 + // if (a.image) return -1
61 + // if (b.image) return +1
62 + // })
2963 }
3064 }
3165
3266 function loadSuggestions () {
@@ -61,39 +95,50 @@
6195 }
6296
6397 function pluralSuggestions (item) {
6498 const id = resolve(item.key)
65- return map(item.value, name => {
66- return Struct({
67- id,
68- title: name,
69- subtitle: subtitle(id, name),
70- value: computed([name, id], mention),
71- image: api.about.obs.imageUrl(id),
72- showBoth: true
99 +
100 + return computed([api.about.obs.name(id)], myNameForThem => {
101 + return map(item.value, name => {
102 + const isTopAlias = name === myNameForThem
103 + const names = item.value()
104 +
105 + const aliases = names
106 + .filter(n => n != name)
107 + .map(name => h('div.alias',
108 + { className: name === myNameForThem ? '-bold' : '' },
109 + name
110 + ))
111 +
112 + return Struct({
113 + id,
114 + title: name,
115 + subtitle: [
116 + h('div.aliases', aliases),
117 + h('div.key', id.substring(0, KEY_SAMPLE_LENGTH))
118 + ],
119 + value: mention(name, id),
120 + image: api.about.obs.imageUrl(id),
121 + showBoth: true,
122 + _name: name // TODO change code above if not needed
123 + })
73124 })
74125 })
126 +
75127 }
76128
129 + // feeds recentSuggestions
77130 function suggestion (id) {
78131 var name = api.about.obs.name(id)
79132 return Struct({
133 + id,
80134 title: name,
81- id,
82- subtitle: id.substring(0, 10),
135 + subtitle: h('div.key', id.substring(0, KEY_SAMPLE_LENGTH)),
83136 value: computed([name, id], mention),
84137 image: api.about.obs.imageUrl(id),
85138 showBoth: true
86139 })
87140 }
88-
89- function subtitle (id, name) {
90- return computed([api.about.obs.name(id)], commonName => {
91- return name.toLowerCase() === commonName.toLowerCase()
92- ? id.substring(0, 10)
93- : `${commonName} ${id.substring(0, 10)}`
94- })
95- }
96141 }
97142
98143 function mention (name, id) {
99144 return `[@${name}](${id})`
app/html/suggest-box.mcssView
@@ -1,12 +1,15 @@
1 +// SuggestBox
12 body {
23 div.suggest-box {
34 width: max-content
45 background-color: #fff
5- border: 1px gainsboro solid
66
7 + min-width: 20rem
8 + max-width: 35rem
79 padding: .2rem .5rem
810 margin-top: .35rem
11 + border: 1px gainsboro solid
912
1013 ul {
1114 list-style-type: none
1215 padding: 0
@@ -21,20 +24,56 @@
2124 img {
2225 height: 36px
2326 width: 36px
2427 padding: .2rem
25- /* TODO make smaller emoji thumbnails */
2628 }
29 +
2730 strong {
28- flex-grow: 1
31 + font-weight: 300
32 + min-width: 7rem
2933 margin-left: .5rem
30- font-weight: 300
34 + margin-right: .5rem
35 +
36 + span.subtle {
37 + color: #aaa
38 + }
3139 }
40 +
3241 small {
33- font-family: monospace
42 + flex-grow: 1
43 +
3444 margin-left: .5rem
3545 padding-right: .2rem
3646 font-size: 1rem
47 +
48 + display: flex
49 + justify-content: flex-end
50 +
51 + div.aliases {
52 + flex-grow: 1
53 +
54 + font-size: .8rem
55 + color: #666
56 + margin-right: .5rem
57 +
58 + display: flex
59 + flex-wrap: wrap
60 +
61 + div.alias {
62 + margin-right: .4rem
63 + -bold {
64 + font-weight: 600
65 + }
66 + }
67 + }
68 +
69 + div.key {
70 + align-self: flex-end
71 +
72 + font-family: monospace
73 + font-size: .8rem
74 + min-width: 5rem
75 + }
3776 }
3877 }
3978
4079 li.selected {
channel/async/suggest.jsView
@@ -20,10 +20,11 @@
2020 return function (word) {
2121 if (!word) {
2222 return suggestions().slice(0, 100)
2323 } else {
24 + word = word.toLowerCase()
2425 return suggestions()
25- .filter(item => ~item.title.indexOf(word))
26 + .filter(item => ~item.title.toLowerCase().indexOf(word))
2627 }
2728 }
2829 })
2930
message/html/compose.jsView
@@ -136,8 +136,9 @@
136136 var word = inputText.slice(1)
137137 if (word[word.length - 1] === ':') {
138138 word = word.slice(0, -1)
139139 }
140 + word = word.toLowerCase()
140141 // TODO: when no emoji typed, list some default ones
141142
142143 const suggestions = api.emoji.sync.names()
143144 .filter(name => ~name.indexOf(word))

Built with git-ssb-web