1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
<template>
<AppContentDetails id="mail-message">
<Loading v-if="loading" />
<template v-else>
<div id="mail-thread-header">
<div id="mail-thread-header-fields">
<h2 :title="threadSubject">
{{ threadSubject }}
</h2>
<p class="transparency">
<AddressList :entries="threadParticipants" />
</p>
</div>
</div>
<ThreadEnvelope v-for="env in thread"
:key="env.databaseId"
:envelope="env"
:mailbox-id="$route.params.mailboxId"
:expanded="expandedThreads.includes(env.databaseId)"
@toggleExpand="toggleExpand(env.databaseId)" />
</template>
</AppContentDetails>
</template>
<script>
import AppContentDetails from '@nextcloud/vue/dist/Components/AppContentDetails'
import { prop, uniqBy } from 'ramda'
import AddressList from './AddressList'
import { getRandomMessageErrorMessage } from '../util/ErrorMessageFactory'
import Loading from './Loading'
import logger from '../logger'
import ThreadEnvelope from './ThreadEnvelope'
export default {
name: 'Thread',
components: {
AddressList,
AppContentDetails,
Loading,
ThreadEnvelope,
},
data() {
return {
loading: true,
message: undefined,
errorMessage: '',
error: undefined,
expandedThreads: [],
}
},
computed: {
thread() {
return this.$store.getters.getEnvelopeThread(this.$route.params.threadId)
},
threadParticipants() {
const recipients = this.thread.flatMap(envelope => {
return envelope.from.concat(envelope.to).concat(envelope.cc)
})
return uniqBy(prop('email'), recipients)
},
threadSubject() {
const thread = this.thread
if (thread.length === 0) {
console.warn('thread is empty')
return ''
}
return thread[0].subject
},
},
watch: {
$route(to, from) {
if (
from.name === to.name
&& from.params.mailboxId === to.params.mailboxId
&& from.params.threadId === to.params.threadId
&& from.params.filter === to.params.filter
) {
logger.debug('navigated but the thread is still the same')
return
}
logger.debug('navigated to another thread', { to, from })
this.fetchThread()
},
},
created() {
this.fetchThread()
},
methods: {
toggleExpand(threadId) {
if (!this.expandedThreads.includes(threadId)) {
console.debug(`expand thread ${threadId}`)
this.expandedThreads.push(threadId)
} else {
console.debug(`collapse thread ${threadId}`)
this.expandedThreads = this.expandedThreads.filter(t => t !== threadId)
}
},
async fetchThread() {
this.loading = true
this.errorMessage = ''
this.error = undefined
const threadId = parseInt(this.$route.params.threadId, 10)
this.expandedThreads = [threadId]
try {
const thread = await this.$store.dispatch('fetchThread', threadId)
logger.debug(`thread for envelope ${threadId} fetched`, { thread })
// TODO: add timeout so that envelope isn't flagged when only viewed
// for a few seconds
if (threadId !== parseInt(this.$route.params.threadId, 10)) {
logger.debug("User navigated away, loaded envelope won't be shown nor flagged as seen", {
oldId: threadId,
newId: this.$route.params.threadId,
})
return
}
if (thread.length === 0) {
logger.info('thread could not be found and is empty', { threadId })
this.errorMessage = getRandomMessageErrorMessage()
this.loading = false
return
}
this.loading = false
} catch (error) {
logger.error('could not load envelope thread', { threadId, error })
if (error.isError) {
this.errorMessage = t('mail', 'Could not load your message thread')
this.error = error
this.loading = false
}
}
},
},
}
</script>
<style lang="scss">
#mail-message {
flex-grow: 1;
}
.mail-message-body {
flex: 1;
margin-bottom: 10px;
position: relative;
}
#mail-thread-header {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 30px 0;
// somehow ios doesn't care about this !important rule
// so we have to manually set left/right padding to chidren
// for 100% to be used
box-sizing: content-box !important;
height: 44px;
width: 100%;
z-index: 100;
position: fixed; // ie fallback
position: -webkit-sticky; // ios/safari fallback
position: sticky;
top: var(--header-height);
background: -webkit-linear-gradient(var(--color-main-background), var(--color-main-background) 80%, rgba(255,255,255,0));
background: -o-linear-gradient(var(--color-main-background), var(--color-main-background) 80%, rgba(255,255,255,0));
background: -moz-linear-gradient(var(--color-main-background), var(--color-main-background) 80%, rgba(255,255,255,0));
background: linear-gradient(var(--color-main-background), var(--color-main-background) 80%, rgba(255,255,255,0));
}
#mail-thread-header-fields {
// initial width
width: 0;
padding-left: 38px;
// grow and try to fill 100%
flex: 1 1 auto;
h2,
p {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding-bottom: 7px;
margin-bottom: 0;
}
.transparency {
opacity: 0.6;
a {
font-weight: bold;
}
}
}
.attachment-popover {
position: sticky;
bottom: 12px;
text-align: center;
}
.tooltip-inner {
text-align: left;
}
#mail-content {
margin: 10px 38px 50px 38px;
.mail-message-body-html & {
margin-bottom: -44px; // accounting for the sticky attachment button
}
}
#mail-content iframe {
width: 100%;
}
#show-images-text {
display: none;
}
#mail-content a,
.mail-signature a {
color: #07d;
border-bottom: 1px dotted #07d;
text-decoration: none;
word-wrap: break-word;
}
.icon-reply-white,
.icon-reply-all-white {
height: 44px;
min-width: 44px;
margin: 0;
padding: 9px 18px 10px 32px;
}
/* Show action button label and move icon to the left
on screens larger than 600px */
@media only screen and (max-width: 600px) {
.action-label {
display: none;
}
}
@media only screen and (min-width: 600px) {
.icon-reply-white,
.icon-reply-all-white {
background-position: 12px center;
}
}
::v-deep .modal-container {
overflow-y: scroll !important;
}
@media print {
#mail-thread-header-fields {
position: relative;
}
#header,
.app-navigation,
#reply-composer,
#forward-button,
#mail-message-has-blocked-content,
.app-content-list,
.message-composer,
.mail-message-attachments {
display: none !important;
}
.app-content {
margin-left: 0 !important;
}
.mail-message-body {
margin-bottom: 0 !important;
}
}
.message-source {
font-family: monospace;
white-space: pre-wrap;
user-select: text;
}
.app-content-list-item-star.icon-starred {
display: none;
}
</style>
|