Debian Codegraph @

addons/portal_rating/static/src/chatter/frontend/message_patch.js

raw
1 import { Message } from "@mail/core/common/message";
2 import { convertBrToLineBreak } from "@mail/utils/common/format";
3
4 import { DropdownItem } from "@web/core/dropdown/dropdown_item";
5 import { rpc } from "@web/core/network/rpc";
6 import { patch } from "@web/core/utils/patch";
7
8 Message.components = { ...Message.components, DropdownItem };
9
10 patch(Message.prototype, {
11 setup() {
12 super.setup(...arguments);
13 this.state.editRating = false;
14 },
15
16 get isEditing() {
17 return !this.state.editRating && super.isEditing;
18 },
19
20 get ratingValue() {
21 return this.message.rating_value || this.message.rating_id?.rating;
22 },
23
24 onClikEditComment() {
25 this.state.editRating = !this.state.editRating;
26 if (this.state.editRating) {
27 const messageContent = convertBrToLineBreak(
28 this.props.message.rating_id.publisher_comment
29 );
30 this.props.message.composer = {
31 message: this.props.message,
32 composerHtml: this.props.message.rating_id.publisher_comment,
33 portalComment: true,
34 selection: {
35 start: messageContent.length,
36 end: messageContent.length,
37 direction: "none",
38 },
39 };
40 } else {
41 this.message.composer = null;
42 }
43 },
44
45 exitEditCommentMode() {
46 this.props.message.composer.clear();
47 this.message.composer = null;
48 this.state.editRating = false;
49 },
50
51 async deleteComment() {
52 const data = await rpc("/website/rating/comment", {
53 rating_id: this.message.rating_id.id,
54 publisher_comment: "",
55 });
56 this.message.rating_id = data;
57 },
58 });