[IMP] mail, hr: access messaging without env in remaining places

Part of task-2582313
This commit is contained in:
Sébastien Theys
2021-08-19 13:55:28 +00:00
parent 512740a900
commit 41445f2ae6
11 changed files with 37 additions and 43 deletions
+3 -3
View File
@@ -23,11 +23,11 @@ const ChatMixin = {
return this._super();
},
_onOpenChat: function (ev) {
async _onOpenChat(ev) {
ev.preventDefault();
ev.stopImmediatePropagation();
const env = Component.env;
env.messaging.openChat({ employeeId: this.state.data.id });
const messaging = await Component.env.services.messaging.get();
messaging.openChat({ employeeId: this.state.data.id });
return true;
},
};
@@ -50,7 +50,7 @@ export class ChatterContainer extends Component {
* @private
*/
async _insertFromProps(props) {
const messaging = await this.env.services.messaging.modelManager.getMessaging();
const messaging = await this.env.services.messaging.get();
if (this.__owl__.status === 5 /* destroyed */) {
return;
}
+13 -10
View File
@@ -2,22 +2,25 @@
import { TranslationDataBase } from 'web.translation';
const { Component } = owl;
TranslationDataBase.include({
/**
* @override
*/
set_bundle() {
const res = this._super(...arguments);
if (Component.env.messaging) {
// Update messaging locale whenever the translation bundle changes.
// In particular if messaging is created before the end of the
// `load_translations` RPC, the default values have to be
// updated by the received ones.
Component.env.messaging.locale.update({
language: this.parameters.code,
textDirection: this.parameters.direction,
if (owl.Component.env.services && owl.Component.env.services.messaging) {
// During boot `env.services` might not even be set yet, in this
// case this can safely be ignored as messaging will then load
// locale information during its initialization.
owl.Component.env.services.messaging.get().then(messaging => {
// Update messaging locale whenever the translation bundle changes.
// In particular if messaging is created before the end of the
// `load_translations` RPC, the default values have to be
// updated by the received ones.
messaging.locale.update({
language: this.parameters.code,
textDirection: this.parameters.direction,
});
});
}
return res;
+3 -3
View File
@@ -43,9 +43,9 @@ const M2XAvatarMixin = {
* @param {Object} params
* @returns {Promise}
*/
_openChat(params) {
const env = Component.env;
return env.messaging.openChat(params);
async _openChat(params) {
const messaging = await Component.env.services.messaging.get();
return messaging.openChat(params);
},
};
-5
View File
@@ -16,10 +16,5 @@ Object.assign(env, {
);
},
});
Object.defineProperty(env, 'messaging', {
get() {
return this.services.messaging.modelManager.messaging;
},
});
serviceRegistry.add('messaging', MessagingService);
@@ -21,4 +21,14 @@ export const MessagingService = AbstractService.extend({
this._super();
this.modelManager.start(this.messagingValues);
},
/**
* Returns the messaging record once it is initialized. This method should
* be considered the main entry point to the messaging system for outside
* code.
*
* @returns {mail.messaging}
**/
async get() {
return this.modelManager.getMessaging();
}
});
@@ -6,7 +6,7 @@ export const newMessageService = {
dependencies: ["command"],
start(newEnv, { command }) {
command.add("Message a user", async () => {
const messaging = await owl.Component.env.services.messaging.modelManager.getMessaging();
const messaging = await owl.Component.env.services.messaging.get();
if (messaging.discuss.isOpen) {
messaging.discuss.update({
isAddingChannel: false,
@@ -542,21 +542,6 @@ async function start(param0 = {}) {
loadingBaseDelayDuration,
messagingBus,
},
/**
* Override to bind the getters on the actual env that is given,
* because the env in the scope of this test might only serve as
* template and not be the one actually used.
*
* @override
*/
init(env) {
Object.defineProperty(env, 'messaging', {
get() {
return this.services.messaging.modelManager.messaging;
},
});
this._super(env);
},
/**
* Override:
* - to ensure the test setup is complete before starting otherwise
@@ -18,7 +18,7 @@ const commandProviderRegistry = registry.category("command_provider");
commandProviderRegistry.add("partner", {
nameSpace: "@",
async provide(newEnv, options) {
const messaging = await Component.env.services.messaging.modelManager.getMessaging();
const messaging = await Component.env.services.messaging.get();
const suggestions = [];
await messaging.models['mail.partner'].imSearch({
callback(partners) {
@@ -45,7 +45,7 @@ commandProviderRegistry.add("partner", {
commandProviderRegistry.add("channel", {
nameSpace: "#",
async provide(newEnv, options) {
const messaging = await Component.env.services.messaging.modelManager.getMessaging();
const messaging = await Component.env.services.messaging.get();
const channels = await messaging.models['mail.thread'].searchChannelsToOpen({
limit: 10,
searchTerm: options.searchValue,
@@ -33,11 +33,12 @@ const DiscussWidget = AbstractAction.extend({
this._lastPushStateActiveThread = null;
this.env = Component.env;
Component.env.services.messaging.modelManager.messagingCreatedPromise.then(() => {
const messaging = Component.env.services.messaging.modelManager.messaging;
const initActiveId = this.options.active_id ||
(this.action.context && this.action.context.active_id) ||
(this.action.params && this.action.params.default_active_id) ||
'mail.box_inbox';
this.discuss = this.env.messaging.discuss;
this.discuss = messaging.discuss;
this.discuss.update({ initActiveId });
});
},
+2 -2
View File
@@ -252,7 +252,7 @@ QUnit.test('list activity widget: open dropdown', async function (assert) {
}
);
const { env, widget: list } = await start({
const { widget: list } = await start({
hasView: true,
View: ListView,
model: 'res.users',
@@ -266,7 +266,7 @@ QUnit.test('list activity widget: open dropdown', async function (assert) {
assert.step(args.method || route);
if (args.method === 'action_feedback') {
const currentUser = this.data['res.users'].records.find(user =>
user.id === env.messaging.currentUser.id
user.id === this.currentUserId
);
Object.assign(currentUser, {
activity_ids: [4],