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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
odoo.define('mail/static/src/components/discuss/discuss.js', function (require) {
'use strict';
const components = {
AutocompleteInput: require('mail/static/src/components/autocomplete_input/autocomplete_input.js'),
Composer: require('mail/static/src/components/composer/composer.js'),
DiscussMobileMailboxSelection: require('mail/static/src/components/discuss_mobile_mailbox_selection/discuss_mobile_mailbox_selection.js'),
DiscussSidebar: require('mail/static/src/components/discuss_sidebar/discuss_sidebar.js'),
MobileMessagingNavbar: require('mail/static/src/components/mobile_messaging_navbar/mobile_messaging_navbar.js'),
ModerationDiscardDialog: require('mail/static/src/components/moderation_discard_dialog/moderation_discard_dialog.js'),
ModerationRejectDialog: require('mail/static/src/components/moderation_reject_dialog/moderation_reject_dialog.js'),
NotificationList: require('mail/static/src/components/notification_list/notification_list.js'),
ThreadView: require('mail/static/src/components/thread_view/thread_view.js'),
};
const useShouldUpdateBasedOnProps = require('mail/static/src/component_hooks/use_should_update_based_on_props/use_should_update_based_on_props.js');
const useStore = require('mail/static/src/component_hooks/use_store/use_store.js');
const patchMixin = require('web.patchMixin');
const { Component } = owl;
const { useRef } = owl.hooks;
class Discuss extends Component {
/**
* @override
*/
constructor(...args) {
super(...args);
useShouldUpdateBasedOnProps();
useStore((...args) => this._useStoreSelector(...args), {
compareDepth: {
checkedMessages: 1,
uncheckedMessages: 1,
},
});
this._updateLocalStoreProps();
/**
* Reference of the composer. Useful to focus it.
*/
this._composerRef = useRef('composer');
/**
* Reference of the ThreadView. Useful to focus it.
*/
this._threadViewRef = useRef('threadView');
// bind since passed as props
this._onMobileAddItemHeaderInputSelect = this._onMobileAddItemHeaderInputSelect.bind(this);
this._onMobileAddItemHeaderInputSource = this._onMobileAddItemHeaderInputSource.bind(this);
}
mounted() {
this.discuss.update({ isOpen: true });
if (this.discuss.thread) {
this.trigger('o-push-state-action-manager');
} else if (this.env.isMessagingInitialized()) {
this.discuss.openInitThread();
}
this._updateLocalStoreProps();
}
patched() {
this.trigger('o-update-control-panel');
if (this.discuss.thread) {
this.trigger('o-push-state-action-manager');
}
if (
this.discuss.thread &&
this.discuss.thread === this.env.messaging.inbox &&
this.discuss.threadView &&
this._lastThreadCache === this.discuss.threadView.threadCache.localId &&
this._lastThreadCounter > 0 && this.discuss.thread.counter === 0
) {
this.trigger('o-show-rainbow-man');
}
this._activeThreadCache = this.discuss.threadView && this.discuss.threadView.threadCache;
this._updateLocalStoreProps();
}
willUnmount() {
if (this.discuss) {
this.discuss.close();
}
}
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/**
* @returns {string}
*/
get addChannelInputPlaceholder() {
return this.env._t("Create or search channel...");
}
/**
* @returns {string}
*/
get addChatInputPlaceholder() {
return this.env._t("Search user...");
}
/**
* @returns {mail.discuss}
*/
get discuss() {
return this.env.messaging && this.env.messaging.discuss;
}
/**
* @returns {Object[]}
*/
mobileNavbarTabs() {
return [{
icon: 'fa fa-inbox',
id: 'mailbox',
label: this.env._t("Mailboxes"),
}, {
icon: 'fa fa-user',
id: 'chat',
label: this.env._t("Chat"),
}, {
icon: 'fa fa-users',
id: 'channel',
label: this.env._t("Channel"),
}];
}
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @private
*/
_updateLocalStoreProps() {
/**
* Locally tracked store props `activeThreadCache`.
* Useful to set scroll position from last stored one and to display
* rainbox man on inbox.
*/
this._lastThreadCache = (
this.discuss.threadView &&
this.discuss.threadView.threadCache &&
this.discuss.threadView.threadCache.localId
);
/**
* Locally tracked store props `threadCounter`.
* Useful to display the rainbow man on inbox.
*/
this._lastThreadCounter = (
this.discuss.thread &&
this.discuss.thread.counter
);
}
/**
* Returns data selected from the store.
*
* @private
* @param {Object} props
* @returns {Object}
*/
_useStoreSelector(props) {
const discuss = this.env.messaging && this.env.messaging.discuss;
const thread = discuss && discuss.thread;
const threadView = discuss && discuss.threadView;
const replyingToMessage = discuss && discuss.replyingToMessage;
const replyingToMessageOriginThread = replyingToMessage && replyingToMessage.originThread;
const checkedMessages = threadView ? threadView.checkedMessages : [];
return {
checkedMessages,
checkedMessagesIsModeratedByCurrentPartner: checkedMessages && checkedMessages.some(message => message.isModeratedByCurrentPartner), // for widget
discuss,
discussActiveId: discuss && discuss.activeId, // for widget
discussActiveMobileNavbarTabId: discuss && discuss.activeMobileNavbarTabId,
discussHasModerationDiscardDialog: discuss && discuss.hasModerationDiscardDialog,
discussHasModerationRejectDialog: discuss && discuss.hasModerationRejectDialog,
discussIsAddingChannel: discuss && discuss.isAddingChannel,
discussIsAddingChat: discuss && discuss.isAddingChat,
discussIsDoFocus: discuss && discuss.isDoFocus,
discussReplyingToMessageOriginThreadComposer: replyingToMessageOriginThread && replyingToMessageOriginThread.composer,
inbox: this.env.messaging.inbox,
isDeviceMobile: this.env.messaging && this.env.messaging.device.isMobile,
isMessagingInitialized: this.env.isMessagingInitialized(),
replyingToMessage,
starred: this.env.messaging.starred, // for widget
thread,
threadCache: threadView && threadView.threadCache,
threadChannelType: thread && thread.channel_type, // for widget
threadDisplayName: thread && thread.displayName, // for widget
threadCounter: thread && thread.counter,
threadModel: thread && thread.model,
threadPublic: thread && thread.public, // for widget
threadView,
threadViewMessagesLength: threadView && threadView.messages.length, // for widget
uncheckedMessages: threadView ? threadView.uncheckedMessages : [], // for widget
};
}
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* @private
*/
_onDialogClosedModerationDiscard() {
this.discuss.update({ hasModerationDiscardDialog: false });
}
/**
* @private
*/
_onDialogClosedModerationReject() {
this.discuss.update({ hasModerationRejectDialog: false });
}
/**
* @private
* @param {CustomEvent} ev
*/
_onFocusinComposer(ev) {
this.discuss.update({ isDoFocus: false });
}
/**
* @private
* @param {CustomEvent} ev
*/
_onHideMobileAddItemHeader(ev) {
ev.stopPropagation();
this.discuss.clearIsAddingItem();
}
/**
* @private
* @param {Event} ev
* @param {Object} ui
* @param {Object} ui.item
* @param {integer} ui.item.id
*/
_onMobileAddItemHeaderInputSelect(ev, ui) {
const discuss = this.discuss;
if (discuss.isAddingChannel) {
discuss.handleAddChannelAutocompleteSelect(ev, ui);
} else {
discuss.handleAddChatAutocompleteSelect(ev, ui);
}
}
/**
* @private
* @param {Object} req
* @param {string} req.term
* @param {function} res
*/
_onMobileAddItemHeaderInputSource(req, res) {
if (this.discuss.isAddingChannel) {
this.discuss.handleAddChannelAutocompleteSource(req, res);
} else {
this.discuss.handleAddChatAutocompleteSource(req, res);
}
}
/**
* @private
*/
_onReplyingToMessageMessagePosted() {
this.env.services['notification'].notify({
message: _.str.sprintf(
this.env._t(`Message posted on "%s"`),
owl.utils.escape(this.discuss.replyingToMessage.originThread.displayName)
),
type: 'warning',
});
this.discuss.clearReplyingToMessage();
}
/**
* @private
* @param {CustomEvent} ev
* @param {Object} ev.detail
* @param {string} ev.detail.tabId
*/
_onSelectMobileNavbarTab(ev) {
ev.stopPropagation();
if (this.discuss.activeMobileNavbarTabId === ev.detail.tabId) {
return;
}
this.discuss.clearReplyingToMessage();
this.discuss.update({ activeMobileNavbarTabId: ev.detail.tabId });
}
/**
* @private
* @param {CustomEvent} ev
*/
_onThreadRendered(ev) {
this.trigger('o-update-control-panel');
}
}
Object.assign(Discuss, {
components,
props: {},
template: 'mail.Discuss',
});
return patchMixin(Discuss);
});
|