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
290
291
292
293
294
295
296
|
odoo.define('mail/static/src/models/thread_viewer/thread_viewer.js', function (require) {
'use strict';
const { registerNewModel } = require('mail/static/src/model/model_core.js');
const { attr, many2one, one2one } = require('mail/static/src/model/model_field.js');
function factory(dependencies) {
class ThreadViewer extends dependencies['mail.model'] {
//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
/**
* @param {integer} scrollHeight
* @param {mail.thread_cache} threadCache
*/
saveThreadCacheScrollHeightAsInitial(scrollHeight, threadCache) {
threadCache = threadCache || this.threadCache;
if (!threadCache) {
return;
}
if (this.chatter) {
// Initial scroll height is disabled for chatter because it is
// too complex to handle correctly and less important
// functionally.
return;
}
this.update({
threadCacheInitialScrollHeights: Object.assign({}, this.threadCacheInitialScrollHeights, {
[threadCache.localId]: scrollHeight,
}),
});
}
/**
* @param {integer} scrollTop
* @param {mail.thread_cache} threadCache
*/
saveThreadCacheScrollPositionsAsInitial(scrollTop, threadCache) {
threadCache = threadCache || this.threadCache;
if (!threadCache) {
return;
}
if (this.chatter) {
// Initial scroll position is disabled for chatter because it is
// too complex to handle correctly and less important
// functionally.
return;
}
this.update({
threadCacheInitialScrollPositions: Object.assign({}, this.threadCacheInitialScrollPositions, {
[threadCache.localId]: scrollTop,
}),
});
}
//----------------------------------------------------------------------
// Private
//----------------------------------------------------------------------
/**
* @private
* @returns {boolean}
*/
_computeHasThreadView() {
if (this.chatter) {
return this.chatter.hasThreadView;
}
if (this.chatWindow) {
return this.chatWindow.hasThreadView;
}
if (this.discuss) {
return this.discuss.hasThreadView;
}
return this.hasThreadView;
}
/**
* @private
* @returns {string}
*/
_computeStringifiedDomain() {
if (this.chatter) {
return '[]';
}
if (this.chatWindow) {
return '[]';
}
if (this.discuss) {
return this.discuss.stringifiedDomain;
}
return this.stringifiedDomain;
}
/**
* @private
* @returns {mail.thread|undefined}
*/
_computeThread() {
if (this.chatter) {
if (!this.chatter.thread) {
return [['unlink']];
}
return [['link', this.chatter.thread]];
}
if (this.chatWindow) {
if (!this.chatWindow.thread) {
return [['unlink']];
}
return [['link', this.chatWindow.thread]];
}
if (this.discuss) {
if (!this.discuss.thread) {
return [['unlink']];
}
return [['link', this.discuss.thread]];
}
return [];
}
/**
* @private
* @returns {mail.thread_cache|undefined}
*/
_computeThreadCache() {
if (!this.thread) {
return [['unlink']];
}
return [['link', this.thread.cache(this.stringifiedDomain)]];
}
/**
* @private
* @returns {mail.thread_viewer|undefined}
*/
_computeThreadView() {
if (!this.hasThreadView) {
return [['unlink']];
}
if (this.threadView) {
return [];
}
return [['create']];
}
}
ThreadViewer.fields = {
/**
* States the `mail.chatter` managing `this`. This field is computed
* through the inverse relation and should be considered read-only.
*/
chatter: one2one('mail.chatter', {
inverse: 'threadViewer',
}),
/**
* Serves as compute dependency.
*/
chatterHasThreadView: attr({
related: 'chatter.hasThreadView',
}),
/**
* Serves as compute dependency.
*/
chatterThread: many2one('mail.thread', {
related: 'chatter.thread',
}),
/**
* States the `mail.chat_window` managing `this`. This field is computed
* through the inverse relation and should be considered read-only.
*/
chatWindow: one2one('mail.chat_window', {
inverse: 'threadViewer',
}),
/**
* Serves as compute dependency.
*/
chatWindowHasThreadView: attr({
related: 'chatWindow.hasThreadView',
}),
/**
* Serves as compute dependency.
*/
chatWindowThread: many2one('mail.thread', {
related: 'chatWindow.thread',
}),
/**
* States the `mail.discuss` managing `this`. This field is computed
* through the inverse relation and should be considered read-only.
*/
discuss: one2one('mail.discuss', {
inverse: 'threadViewer',
}),
/**
* Serves as compute dependency.
*/
discussHasThreadView: attr({
related: 'discuss.hasThreadView',
}),
/**
* Serves as compute dependency.
*/
discussStringifiedDomain: attr({
related: 'discuss.stringifiedDomain',
}),
/**
* Serves as compute dependency.
*/
discussThread: many2one('mail.thread', {
related: 'discuss.thread',
}),
/**
* Determines whether `this.thread` should be displayed.
*/
hasThreadView: attr({
compute: '_computeHasThreadView',
default: false,
dependencies: [
'chatterHasThreadView',
'chatWindowHasThreadView',
'discussHasThreadView',
],
}),
/**
* Determines the domain to apply when fetching messages for `this.thread`.
*/
stringifiedDomain: attr({
compute: '_computeStringifiedDomain',
default: '[]',
dependencies: [
'discussStringifiedDomain',
],
}),
/**
* Determines the `mail.thread` that should be displayed by `this`.
*/
thread: many2one('mail.thread', {
compute: '_computeThread',
dependencies: [
'chatterThread',
'chatWindowThread',
'discussThread',
],
}),
/**
* States the `mail.thread_cache` that should be displayed by `this`.
*/
threadCache: many2one('mail.thread_cache', {
compute: '_computeThreadCache',
dependencies: [
'stringifiedDomain',
'thread',
],
}),
/**
* Determines the initial scroll height of thread caches, which is the
* scroll height at the time the last scroll position was saved.
* Useful to only restore scroll position when the corresponding height
* is available, otherwise the restore makes no sense.
*/
threadCacheInitialScrollHeights: attr({
default: {},
}),
/**
* Determines the initial scroll positions of thread caches.
* Useful to restore scroll position on changing back to this
* thread cache. Note that this is only applied when opening
* the thread cache, because scroll position may change fast so
* save is already throttled.
*/
threadCacheInitialScrollPositions: attr({
default: {},
}),
/**
* States the `mail.thread_view` currently displayed and managed by `this`.
*/
threadView: one2one('mail.thread_view', {
compute: '_computeThreadView',
dependencies: [
'hasThreadView',
],
inverse: 'threadViewer',
isCausal: true,
}),
};
ThreadViewer.modelName = 'mail.thread_viewer';
return ThreadViewer;
}
registerNewModel('mail.thread_viewer', factory);
});
|