const e = {
sharedImage: "shared an image 🖼️",
sharedVideo: "shared a video 📹",
sharedFile: "shared a file 📁",
callStarted: "has started a call 📞",
sharedAudio: "Shared an audio 🔊",
sharedVoice: "Shared a voice message 🎤",
sharedLink: "Shared a link 🔗",
},
t = { ROOM: "0", BROADCAST: "1", DM: "2" },
r = { CALL_JOINED: "call_joined" },
i = (e) => {
try {
const t = e.startsWith("www.") ? `https://${e}` : e,
r = new URL(t)
return "http:" === r.protocol || "https:" === r.protocol
} catch {
return !1
}
},
a = (e) => {
if (!e || "string" != typeof e) return !1
const t = e.trim()
return !/\s/.test(t) && i(t)
},
s = ({ roomType: e, title: r }) =>
e ? { isChannel: e === t.BROADCAST, isDm: e === t.DM || !r } : { isChannel: !1, isDm: !1 },
n = ({ sender: e, config: t }) => {
const { isDm: r } = s(t)
return r ? e.name : t.title
},
o = ({ message: t, sender: r, config: i, strings: n }) => {
const o = n || e,
{ type: d, chatText: h, fileType: l } = t,
{ name: c } = r,
g = c?.split("\n").join(" ") || "👋",
u = "call" === d,
{ isDm: m, isChannel: f } = s(i),
S = (() => {
if (h) return a(h) ? o.sharedLink : h
if ("file" === d && l) {
if (String(l).startsWith("image/")) return o.sharedImage
if (String(l).startsWith("video/")) return o.sharedVideo
if (String(l).startsWith("audio/x-m4a")) return o.sharedVoice
if (String(l).startsWith("audio/")) return o.sharedAudio
}
return u ? (m ? o.callStarted : `${g} ${o.callStarted}`) : o.sharedFile
})()
return m || f || u ? S : `${g}: ${S}`
}
module.exports = {
ROOM_TYPE: t,
MESSAGE_TYPE: r,
getRoomTypeFlags: s,
getNotificationTitle: n,
getNotificationBody: o,
}