git ssb

16+

Dominic / patchbay



Commit 7d91615511c10dc2290684814abc7dd43da98917

re-add user filter, add root-only filter

mix irving committed on 3/17/2018, 2:50:23 AM
Parent: 763857ca6f3f257c3bef51274852277c073fadf8

Files changed

app/html/filter.jschanged
app/html/filter.mcsschanged
app/html/filter.jsView
@@ -3,15 +3,15 @@
33 const Abort = require('pull-abortable')
44 const pull = require('pull-stream')
55 const addSuggest = require('suggest-box')
66 const { isFeed } = require('ssb-ref')
7-const some = require('lodash/some')
87 const get = require('lodash/get')
98 const isEqual = require('lodash/isEqual')
109
1110 exports.gives = nest('app.html.filter')
1211
1312 exports.needs = nest({
13 + 'about.async.suggest': 'first',
1414 'channel.async.suggest': 'first',
1515 'contact.obs.following': 'first',
1616 'keys.sync.id': 'first',
1717 'settings.obs.get': 'first',
@@ -28,30 +28,29 @@
2828
2929 const myId = api.keys.sync.id()
3030 const peopleIFollow = api.contact.obs.following(myId)
3131
32- const { set } = api.settings.sync
33-
3432 const filterSettings = api.settings.obs.get('filter', {exclude: {}})
3533
36- const channelInput = h('input',
37- { value: filterSettings().exclude.channels,
38- 'ev-keyup': (ev) => {
39- var text = ev.target.value
40- if (text.length == 0 || ev.which == 13) {
41- api.settings.sync.set({
42- filter: {
43- exclude: {
44- channels: text
45- }
34 + const channelInput = h('input', {
35 + value: filterSettings().exclude.channels,
36 + 'ev-keyup': (ev) => {
37 + var text = ev.target.value
38 + if (text.length === 0 || ev.which === 13) {
39 + api.settings.sync.set({
40 + filter: {
41 + exclude: {
42 + channels: text
4643 }
47- })
48- draw()
49- }
44 + }
45 + })
46 + draw()
5047 }
5148 }
52- )
49 + })
5350
51 + const userInput = h('input')
52 +
5453 const isFiltered = computed(filterSettings, (filterSettings) => {
5554 const _settings = Object.assign({}, filterSettings)
5655 delete _settings.defaults
5756
@@ -70,13 +69,19 @@
7069 'Filter',
7170 h('i.fa.fa-filter')
7271 ]),
7372 h('section', [
73 + h('div.users', [
74 + toggle({ type: 'peopleIFollow', filterGroup: 'only', label: 'Only people I follow' }),
75 + h('div.user-filter', [
76 + h('label', 'Only this user (temporary filter):'),
77 + userInput
78 + ])
79 + ]),
7480 h('div.channels', [
7581 h('label', 'Exclude channels'),
7682 channelInput
7783 ]),
78- toggle({ type: 'peopleIFollow', filterGroup: 'only', label: 'Only people I follow' }),
7984 h('div.message-types', [
8085 h('header', 'Show messages'),
8186 toggle({ type: 'post' }),
8287 toggle({ type: 'like' }),
@@ -84,8 +89,11 @@
8489 toggle({ type: 'contact' }),
8590 toggle({ type: 'channel' }),
8691 toggle({ type: 'pub' }),
8792 toggle({ type: 'chess' })
93 + ]),
94 + h('div.root-messages', [
95 + toggle({ type: 'rootMessages', filterGroup: 'only', label: 'Root messages only' })
8896 ])
8997 ])
9098 ])
9199 ])
@@ -129,14 +137,39 @@
129137
130138 draw()
131139 })
132140
141 + var userId
142 + const getAboutSuggestions = api.about.async.suggest()
143 + addSuggest(userInput, (inputText, cb) => {
144 + inputText = inputText.replace(/^@/, '')
145 + cb(null, getAboutSuggestions(inputText.slice(1)))
146 + }, {cls: 'PatchSuggest'})
147 + userInput.addEventListener('suggestselect', ev => {
148 + userId = ev.detail.id
149 + userInput.value = userId
150 +
151 + draw()
152 + })
153 +
133154 function followFilter (msg) {
134155 if (!filterSettings().only.peopleIFollow) return true
135156
136157 return Array.from(peopleIFollow()).concat(myId).includes(msg.value.author)
137158 }
138159
160 + function userFilter (msg) {
161 + if (!userId) return true
162 +
163 + return msg.value.author === userId
164 + }
165 +
166 + function rootFilter (msg) {
167 + if (!filterSettings().only.rootMessages) return true
168 +
169 + return !msg.value.content.root
170 + }
171 +
139172 function channelFilter (msg) {
140173 var filters = filterSettings().exclude.channels
141174 if (!filters) return true
142175 filters = filters.split(' ').map(c => c.slice(1))
@@ -158,8 +191,10 @@
158191 function filterDownThrough () {
159192 return pull(
160193 downScrollAborter,
161194 pull.filter(followFilter),
195 + pull.filter(userFilter),
196 + pull.filter(rootFilter),
162197 pull.filter(channelFilter),
163198 pull.filter(messageFilter)
164199 )
165200 }
@@ -169,8 +204,10 @@
169204 function filterUpThrough () {
170205 return pull(
171206 upScrollAborter,
172207 pull.filter(followFilter),
208 + pull.filter(userFilter),
209 + pull.filter(rootFilter),
173210 pull.filter(channelFilter),
174211 pull.filter(messageFilter)
175212 )
176213 }
app/html/filter.mcssView
@@ -56,9 +56,32 @@
5656 flex-wrap: wrap
5757 justify-content: space-between
5858 align-items: center
5959
60- div.channels {
60 + div.users {
61 + flex-basis: 100%
62 + margin-bottom: .5rem
63 +
64 + display: flex
65 + align-items: center
66 +
67 + div.FilterToggle {
68 + flex-grow: 1
69 + }
70 + div.user-filter {
71 + label {
72 + margin-right: .4rem
73 + }
74 + input {
75 + border: 1px gainsboro solid
76 + font-size: 1rem
77 + }
78 + }
79 + }
80 +
81 + div.channels {
82 + display: flex
83 +
6184 label {
6285 margin-right: .4rem
6386 }
6487 input {
@@ -67,15 +90,20 @@
6790 }
6891 }
6992
7093 div.message-types {
94 + flex-basis: 100%
95 +
7196 margin: .6rem 0
7297 display: flex
7398
7499 header {
75100 margin-right: 1rem
76101 }
77102 }
103 +
104 + div.root-messages {
105 + }
78106 }
79107
80108 }
81109 }

Built with git-ssb-web