[FIX] mail: check existence of component records

- remove useless check (record should now always exist on update hooks)
- adapt check to use exists() when necessary (async code)

task-2849688

closes odoo/odoo#90973

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Sébastien Theys
2022-05-11 12:44:41 +02:00
parent a3904dc603
commit dc178821ba
14 changed files with 18 additions and 46 deletions
@@ -93,7 +93,7 @@ export class AttachmentViewer extends Component {
* @private
*/
_handleImageLoad() {
if (!this.attachmentViewer || !this.attachmentViewer.attachment) {
if (!this.attachmentViewer.exists() || !this.attachmentViewer.attachment) {
return;
}
const refs = this._getRefs();
@@ -213,7 +213,7 @@ export class AttachmentViewer extends Component {
* @param {MouseEvent} ev
*/
_onClickGlobal(ev) {
if (!this.attachmentViewer) {
if (!this.attachmentViewer.exists()) {
return;
}
if (!this.attachmentViewer.isDragging) {
@@ -297,7 +297,7 @@ export class AttachmentViewer extends Component {
* @param {DragEvent} ev
*/
_onMousedownImage(ev) {
if (!this.attachmentViewer) {
if (!this.attachmentViewer.exists()) {
return;
}
if (this.attachmentViewer.isDragging) {
@@ -317,7 +317,7 @@ export class AttachmentViewer extends Component {
* @param {DragEvent}
*/
_onMousemoveView(ev) {
if (!this.attachmentViewer) {
if (!this.attachmentViewer.exists()) {
return;
}
if (!this.attachmentViewer.isDragging) {
@@ -41,10 +41,6 @@ export class ChatWindow extends Component {
* @private
*/
_update() {
if (!this.chatWindow) {
// chat window is being deleted
return;
}
if (!this.root.el) {
return;
}
@@ -47,9 +47,6 @@ export class Chatter extends LegacyComponent {
* @private
*/
_update() {
if (!this.chatter) {
return;
}
if (this.chatter.thread) {
this._notifyRendered();
}
@@ -83,7 +83,7 @@ export class ComposerSuggestedRecipient extends Component {
* @private
*/
_update() {
if (this._checkboxRef.el && this.suggestedRecipientInfo) {
if (this._checkboxRef.el) {
this._checkboxRef.el.checked = this.suggestedRecipientInfo.isSelected;
}
}
@@ -116,7 +116,7 @@ export class ComposerSuggestedRecipient extends Component {
* @private
*/
_onDialogSaved() {
const thread = this.suggestedRecipientInfo && this.suggestedRecipientInfo.thread;
const thread = this.suggestedRecipientInfo.exists() && this.suggestedRecipientInfo.thread;
if (!thread) {
return;
}
@@ -36,8 +36,6 @@ export class ComposerSuggestion extends Component {
_update() {
if (
this.root.el &&
this.composerSuggestion &&
this.composerSuggestion.composerViewOwner &&
this.composerSuggestion.composerViewOwner.hasToScrollToActiveSuggestion &&
this.composerSuggestion.isActive
) {
@@ -53,9 +53,6 @@ export class ComposerTextInput extends Component {
* @private
*/
_update() {
if (!this.composerView) {
return;
}
if (!this.root.el) {
return;
}
@@ -98,7 +95,7 @@ export class ComposerTextInput extends Component {
* @private
*/
_onInputTextarea() {
if (!this.composerView) {
if (!this.composerView.exists()) {
return;
}
this.composerView.saveStateInStore();
@@ -16,9 +16,6 @@ export class Discuss extends LegacyComponent {
}
_update() {
if (!this.discussView) {
return;
}
if (this.discussView.discuss.thread) {
this.trigger('o-push-state-action-manager');
}
@@ -53,9 +50,6 @@ export class Discuss extends LegacyComponent {
* @private
*/
_updateLocalStoreProps() {
if (!this.discussView) {
return;
}
/**
* Locally tracked store props `activeThreadCache`.
* Useful to set scroll position from last stored one and to display
@@ -36,9 +36,6 @@ export class DiscussSidebar extends Component {
* @private
*/
_update() {
if (!this.discussView) {
return;
}
if (this.discussView.quickSearchInputRef.el) {
this.discussView.quickSearchInputRef.el.value = this.discussView.discuss.sidebarQuickSearchValue;
}
@@ -232,9 +232,6 @@ export class Message extends Component {
* @private
*/
_update() {
if (!this.messageView) {
return;
}
if (this._prettyBodyRef.el && this.messageView.message.prettyBody !== this._lastPrettyBody) {
this._prettyBodyRef.el.innerHTML = this.messageView.message.prettyBody;
this._lastPrettyBody = this.messageView.message.prettyBody;
@@ -33,7 +33,7 @@ export class MessageList extends Component {
*/
this._lastRenderedValues = useRenderedValues(() => {
const messageListView = this.messageListView;
const threadView = messageListView && messageListView.threadViewOwner;
const threadView = messageListView.threadViewOwner;
const thread = threadView && threadView.thread;
const threadCache = threadView && threadView.threadCache;
return {
@@ -56,12 +56,13 @@ export class MessageList extends Component {
}
_willPatch() {
if (!this.messageListView) {
const { messageListView } = this._lastRenderedValues();
if (!messageListView.exists()) {
return;
}
this._willPatchSnapshot = {
scrollHeight: this.messageListView.getScrollableElement().scrollHeight,
scrollTop: this.messageListView.getScrollableElement().scrollTop,
scrollHeight: messageListView.getScrollableElement().scrollHeight,
scrollTop: messageListView.getScrollableElement().scrollTop,
};
}
@@ -99,7 +100,7 @@ export class MessageList extends Component {
*/
adjustFromComponentHints() {
const { componentHintList, messageListView } = this._lastRenderedValues();
if (!messageListView || !messageListView.exists()) {
if (!messageListView.exists()) {
return;
}
for (const hint of componentHintList) {
@@ -223,7 +224,7 @@ export class MessageList extends Component {
*/
_checkMostRecentMessageIsVisible() {
const { messageListView } = this._lastRenderedValues();
if (!messageListView || !messageListView.exists()) {
if (!messageListView.exists()) {
return;
}
const { lastMessageView } = messageListView.threadViewOwner;
@@ -288,14 +289,14 @@ export class MessageList extends Component {
thread,
threadCache,
} = this._lastRenderedValues();
if (!messageListView || !messageListView.exists()) {
if (!messageListView.exists()) {
return;
}
if (!messageListView.getScrollableElement()) {
// could be unmounted in the meantime (due to throttled behavior)
return;
}
const scrollTop = this.messageListView.getScrollableElement().scrollTop;
const scrollTop = messageListView.getScrollableElement().scrollTop;
this.messaging.messagingBus.trigger('o-component-message-list-scrolled', {
orderedMessages,
scrollTop,
@@ -16,7 +16,7 @@ export class PopoverView extends Component {
super.setup();
useComponentToModel({ fieldName: 'component' });
usePosition(
() => this.popoverView && this.popoverView.anchorRef && this.popoverView.anchorRef.el,
() => this.popoverView.anchorRef && this.popoverView.anchorRef.el,
{
popper: "root",
margin: 16,
@@ -94,9 +94,6 @@ export class RtcCallViewer extends Component {
* @private
*/
_setTileLayout() {
if (!this.rtcCallViewer) {
return;
}
if (!this.root.el) {
return;
}
@@ -44,9 +44,6 @@ export class RtcVideo extends Component {
if (!this.root.el) {
return;
}
if (!this.rtcVideoView) {
return;
}
if (!this.rtcVideoView.rtcSession || !this.rtcVideoView.rtcSession.videoStream) {
this.root.el.srcObject = undefined;
} else {
@@ -117,6 +117,7 @@ registerModel({
}),
composerViewOwner: one('ComposerView', {
compute: '_computeComposerViewOwner',
required: true,
}),
composerViewOwnerAsExtraSuggestion: one('ComposerView', {
inverse: 'extraSuggestions',