UNPKG

2.85 kBJavaScriptView Raw
1/*
2Copyright 2018 New Vector Ltd
3Copyright 2019 The Matrix.org Foundation C.I.C.
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16*/
17
18/** @module ContentHelpers */
19
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 */
26export function makeHtmlMessage(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 */
41export function makeHtmlNotice(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 */
56export function makeHtmlEmote(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 */
70export function makeTextMessage(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 */
82export function makeNotice(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 */
94export function makeEmoteMessage(body) {
95 return {
96 msgtype: "m.emote",
97 body: body,
98 };
99}