1 | /*
|
2 | Copyright 2018 New Vector Ltd
|
3 |
|
4 | Licensed under the Apache License, Version 2.0 (the "License");
|
5 | you may not use this file except in compliance with the License.
|
6 | You may obtain a copy of the License at
|
7 |
|
8 | http://www.apache.org/licenses/LICENSE-2.0
|
9 |
|
10 | Unless required by applicable law or agreed to in writing, software
|
11 | distributed under the License is distributed on an "AS IS" BASIS,
|
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | See the License for the specific language governing permissions and
|
14 | limitations under the License.
|
15 | */
|
16 | ;
|
17 |
|
18 | /** @module ContentHelpers */
|
19 | module.exports = {
|
20 | /**
|
21 | * Generates the content for a HTML Message event
|
22 | * @param {string} body the plaintext body of the message
|
23 | * @param {string} htmlBody the HTML representation of the message
|
24 | * @returns {{msgtype: string, format: string, body: string, formatted_body: string}}
|
25 | */
|
26 | makeHtmlMessage: function(body, htmlBody) {
|
27 | return {
|
28 | msgtype: "m.text",
|
29 | format: "org.matrix.custom.html",
|
30 | body: body,
|
31 | formatted_body: htmlBody,
|
32 | };
|
33 | },
|
34 |
|
35 | /**
|
36 | * Generates the content for a HTML Notice event
|
37 | * @param {string} body the plaintext body of the notice
|
38 | * @param {string} htmlBody the HTML representation of the notice
|
39 | * @returns {{msgtype: string, format: string, body: string, formatted_body: string}}
|
40 | */
|
41 | makeHtmlNotice: function(body, htmlBody) {
|
42 | return {
|
43 | msgtype: "m.notice",
|
44 | format: "org.matrix.custom.html",
|
45 | body: body,
|
46 | formatted_body: htmlBody,
|
47 | };
|
48 | },
|
49 |
|
50 | /**
|
51 | * Generates the content for a HTML Emote event
|
52 | * @param {string} body the plaintext body of the emote
|
53 | * @param {string} htmlBody the HTML representation of the emote
|
54 | * @returns {{msgtype: string, format: string, body: string, formatted_body: string}}
|
55 | */
|
56 | makeHtmlEmote: function(body, htmlBody) {
|
57 | return {
|
58 | msgtype: "m.emote",
|
59 | format: "org.matrix.custom.html",
|
60 | body: body,
|
61 | formatted_body: htmlBody,
|
62 | };
|
63 | },
|
64 |
|
65 | /**
|
66 | * Generates the content for a Plaintext Message event
|
67 | * @param {string} body the plaintext body of the emote
|
68 | * @returns {{msgtype: string, body: string}}
|
69 | */
|
70 | makeTextMessage: function(body) {
|
71 | return {
|
72 | msgtype: "m.text",
|
73 | body: body,
|
74 | };
|
75 | },
|
76 |
|
77 | /**
|
78 | * Generates the content for a Plaintext Notice event
|
79 | * @param {string} body the plaintext body of the notice
|
80 | * @returns {{msgtype: string, body: string}}
|
81 | */
|
82 | makeNotice: function(body) {
|
83 | return {
|
84 | msgtype: "m.notice",
|
85 | body: body,
|
86 | };
|
87 | },
|
88 |
|
89 | /**
|
90 | * Generates the content for a Plaintext Emote event
|
91 | * @param {string} body the plaintext body of the emote
|
92 | * @returns {{msgtype: string, body: string}}
|
93 | */
|
94 | makeEmoteMessage: function(body) {
|
95 | return {
|
96 | msgtype: "m.emote",
|
97 | body: body,
|
98 | };
|
99 | },
|
100 | };
|