| 1 |
import { Composer } from "@mail/core/common/composer"; |
| 2 |
import { markEventHandled } from "@web/core/utils/misc"; |
| 3 |
|
| 4 |
import { markup, useRef } from "@odoo/owl"; |
| 5 |
|
| 6 |
import { useService } from "@web/core/utils/hooks"; |
| 7 |
import { patch } from "@web/core/utils/patch"; |
| 8 |
|
| 9 |
/** @type {Composer} */ |
| 10 |
const composerPatch = { |
| 11 |
setup() { |
| 12 |
this.gifButton = useRef("gif-button"); |
| 13 |
super.setup(); |
| 14 |
this.ui = useService("ui"); |
| 15 |
}, |
| 16 |
get pickerSettings() { |
| 17 |
const setting = super.pickerSettings; |
| 18 |
if (this.hasGifPicker) { |
| 19 |
setting.pickers.gif = (gif) => this.sendGifMessage(gif); |
| 20 |
if (this.hasGifPickerButton) { |
| 21 |
setting.buttons.push(this.gifButton); |
| 22 |
} |
| 23 |
} |
| 24 |
return setting; |
| 25 |
}, |
| 26 |
get hasGifPicker() { |
| 27 |
return ( |
| 28 |
(this.store.hasGifPickerFeature || this.store.self.main_user_id?.is_admin) && |
| 29 |
!this.env.inChatter && |
| 30 |
!this.props.composer.message |
| 31 |
); |
| 32 |
}, |
| 33 |
get hasGifPickerButton() { |
| 34 |
return this.hasGifPicker && !this.ui.isSmall && !this.env.inChatWindow; |
| 35 |
}, |
| 36 |
onClickAddGif(ev) { |
| 37 |
markEventHandled(ev, "Composer.onClickAddGif"); |
| 38 |
}, |
| 39 |
async sendGifMessage(gif) { |
| 40 |
const href = encodeURI(gif.url); |
| 41 |
await this._sendMessage( |
| 42 |
markup`<a href="${href}" target="_blank" rel="noreferrer noopener">${gif.url}</a>`, |
| 43 |
{ |
| 44 |
parentId: this.props.composer.replyToMessage?.id, |
| 45 |
} |
| 46 |
); |
| 47 |
}, |
| 48 |
}; |
| 49 |
patch(Composer.prototype, composerPatch); |