git ssb

2+

mixmix / ticktack



Commit 6c2d62189f2bd14a50a90b56b6e4b20393233a56

integrate unread state

Dominic Tarr committed on 8/17/2017, 5:11:57 AM
Parent: c98c520dc293d99e6462eda47eb8183248adcf78

Files changed

app/html/thread-card.jschanged
app/html/thread-card.mcsschanged
app/html/thread.jschanged
app/page/home.jschanged
app/html/thread-card.jsView
@@ -10,9 +10,10 @@
1010 'history.sync.push': 'first',
1111 'about.obs.name': 'first',
1212 'about.html.image': 'first',
1313 'message.html.markdown': 'first',
14- 'translations.sync.strings': 'first'
14+ 'translations.sync.strings': 'first',
15+ 'unread.sync.isUnread': 'first'
1516 })
1617
1718 function firstLine (text) {
1819 if(text.length < 80 && !~text.indexOf('\n')) return text
@@ -88,9 +89,11 @@
8889 const onClick = opts.onClick || function () { api.history.sync.push(thread) }
8990 const id = `${thread.key}-${JSON.stringify(opts)}`
9091 // id is only here to help morphdom morph accurately
9192
92- return h('ThreadCard', { 'ev-click': onClick, id }, [
93+ var unread = thread.unread ? ' -unread': ''
94+
95+ return h('ThreadCard' + unread, { 'ev-click': onClick, id}, [
9396 h('div.context', threadIcon(thread)),
9497 h('div.content', [
9598 subjectEl,
9699 replySample ? h('div.reply', [
app/html/thread-card.mcssView
@@ -6,9 +6,9 @@
66
77 div.context {
88 display: flex
99 margin-right: 1rem
10-
10+ font-weight: inherit
1111 img {
1212 $smallAvatar
1313 margin-right: .5rem
1414 }
@@ -38,5 +38,14 @@
3838
3939 $smallMarkdown
4040 }
4141 }
42+ -unread {
43+ //why does this only work on the channel name?
44+ font-weight: bold
45+ }
4246 }
47+
48+
49+
50+
51+
app/html/thread.jsView
@@ -7,9 +7,11 @@
77 exports.needs = nest({
88 'about.html.image': 'first',
99 'feed.obs.thread': 'first',
1010 'keys.sync.id': 'first',
11- 'message.html.markdown': 'first'
11+ 'message.html.markdown': 'first',
12+ 'unread.sync.markRead': 'first',
13+ 'unread.sync.isUnread': 'first'
1214 })
1315
1416 exports.create = (api) => {
1517 return nest('app.html.thread', thread)
@@ -35,8 +37,11 @@
3537 ])
3638 : h('div.other-chunk', [
3739 h('div.avatar', when(author, api.about.html.image(author()))),
3840 h('div.msgs', map(chunk, msg => {
41+ console.log('markRead', msg.key)
42+// if(root.replies)
43+// thread.replies.forEach(api.unread.sync.markRead)
3944 return h('div.msg-row', [
4045 message(msg),
4146 h('div.spacer')
4247 ])
@@ -46,10 +51,11 @@
4651 )
4752
4853 function message (msg) {
4954 const raw = get(msg, 'value.content.text')
50-
51- return h('div.msg', api.message.html.markdown(raw))
55+ var unread = api.unread.sync.isUnread(msg) ? ' -unread' : ' -read'
56+ api.unread.sync.markRead(msg)
57+ return h('div.msg'+unread, api.message.html.markdown(raw))
5258 }
5359
5460 return threadView
5561 }
@@ -82,4 +88,12 @@
8288 function isSameAuthor (msgA, msgB) {
8389 // TODO (mix) use lodash/get
8490 return msgA.value.author === msgB.value.author
8591 }
92+
93+
94+
95+
96+
97+
98+
99+
app/page/home.jsView
@@ -11,9 +11,10 @@
1111 'history.sync.push': 'first',
1212 'keys.sync.id': 'first',
1313 'translations.sync.strings': 'first',
1414 'state.obs.threads': 'first',
15- 'app.html.threadCard': 'first'
15+ 'app.html.threadCard': 'first',
16+ 'unread.sync.isUnread': 'first'
1617 })
1718
1819 function toRecpGroup(msg) {
1920 //cannocialize
@@ -72,19 +73,8 @@
7273 var threadsHtmlObs = More(
7374 threadsObsDebounced,
7475 function render (threads) {
7576
76- var groupedThreads =
77- roots(threads.private)
78- .concat(roots(threads.channels))
79- .concat(roots(threads.groups))
80- .filter(function (thread) {
81- return thread.value.content.recps || thread.value.content.channel
82- })
83- .sort(function (a, b) {
84- return latestUpdate(b) - latestUpdate(a)
85- })
86-
8777 function latestUpdate(thread) {
8878 var m = thread.timestamp
8979 if(!thread.replies) return m
9080
@@ -100,9 +90,34 @@
10090 return e && e.value
10191 })
10292 }
10393
94+ var groupedThreads =
95+ roots(threads.private)
96+ .concat(roots(threads.channels))
97+ .concat(roots(threads.groups))
98+ .filter(function (thread) {
99+ return thread.value.content.recps || thread.value.content.channel
100+ })
101+ .map(function (thread) {
102+ var unread = 0
103+ if(api.unread.sync.isUnread(thread))
104+ unread ++
105+ ;(thread.replies || []).forEach(function (msg) {
106+ if(api.unread.sync.isUnread(msg)) unread ++
107+ })
108+ thread.unread = unread
109+// console.log('unread', thread.unread, +!!thread.unread)
110+ return thread
111+ })
112+ .sort(function (a, b) {
113+ return ((!!b.unread) - (!!a.unread)) || (latestUpdate(b) - latestUpdate(a))
114+ })
104115
116+// console.log(groupedThreads.map(function (thread) {
117+// return {ch: thread.value.content.channel, unread: thread.unread, thread: thread}
118+// }))
119+//
105120 morphdom(container,
106121 // LEGACY: some of these containers could be removed
107122 // but they are here to be compatible with the old MCSS.
108123 h('div.container', [
@@ -120,10 +135,9 @@
120135 )
121136 ])
122137 ])
123138 )
124-
125- return container
139+ return container
126140 }
127141 )
128142 return h('Page -home', {title: strings.home}, [
129143 threadsHtmlObs,
@@ -133,4 +147,14 @@
133147 }
134148
135149
136150
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+

Built with git-ssb-web