aboutsummaryrefslogtreecommitdiff
path: root/vnext/server/common/MessageUtils.js
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/server/common/MessageUtils.js')
-rw-r--r--vnext/server/common/MessageUtils.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/vnext/server/common/MessageUtils.js b/vnext/server/common/MessageUtils.js
new file mode 100644
index 00000000..f766faf2
--- /dev/null
+++ b/vnext/server/common/MessageUtils.js
@@ -0,0 +1,66 @@
+/**
+ * check if message is PM
+ *
+ * @param {import('../../src/api').Message} msg message
+ */
+ export function isPM(msg) {
+ return !msg.mid;
+}
+
+/**
+ * check if message is reply
+ *
+ * @param {import('../../src/api').Message} msg message
+ */
+export function isReply(msg) {
+ return msg.rid && msg.rid > 0;
+}
+
+/**
+ * check if message is service one
+ *
+ * @param {import('../../src/api').Message} msg message
+ */
+export function isService(msg) {
+ return msg.service && msg.service;
+}
+
+/**
+ * format notification title
+ *
+ * @param {import('../../src/api').Message} msg message
+ * @returns {string} formatted title
+ */
+export function formatTitle(msg) {
+ if (isReply(msg)) {
+ return `Reply by ${msg.user.uname}:`;
+ } else if (isPM(msg)) {
+ return `Private message from ${msg.user.uname}:`;
+ }
+ return `${msg.user.uname}`;
+}
+
+/**
+ * format notification quote
+ *
+ * @param { import('../../src/api').Message } msg message
+ * @returns {string} formatted quote line
+ */
+export function formatQuote(msg) {
+ if (isReply(msg)) {
+ return msg.replyQuote || '';
+ } else if (isPM(msg)) {
+ return '';
+ }
+ return (msg.tags || []).map(t => `*${t}`).join(', ');
+}
+
+/**
+ * format notification body
+ *
+ * @param {import('../../src/api').Message} msg message
+ * @returns {string} formatted body
+ */
+export function formatMessage(msg) {
+ return msg.body || 'Sent an image';
+}