You've already forked AstralRinth
forked from didirus/AstralRinth
Implements MOD-171: Intercom messenger integration on servers panel (#2959)
* feat: intercom Signed-off-by: Evan Song <theevansong@gmail.com> * fix: double check Signed-off-by: Evan Song <theevansong@gmail.com> * fix: address double booting Signed-off-by: Evan Song <theevansong@gmail.com> --------- Signed-off-by: Evan Song <theevansong@gmail.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@formatjs/intl-localematcher": "^0.5.4",
|
||||
"@intercom/messenger-js-sdk": "^0.0.14",
|
||||
"@ltd/j-toml": "^1.38.0",
|
||||
"@modrinth/assets": "workspace:*",
|
||||
"@modrinth/ui": "workspace:*",
|
||||
|
||||
@@ -266,6 +266,7 @@ import {
|
||||
import DOMPurify from "dompurify";
|
||||
import { ButtonStyled } from "@modrinth/ui";
|
||||
import { refThrottled } from "@vueuse/core";
|
||||
import { Intercom, shutdown } from "@intercom/messenger-js-sdk";
|
||||
import type { ServerState, Stats, WSEvent, WSInstallationResultEvent } from "~/types/servers";
|
||||
|
||||
const socket = ref<WebSocket | null>(null);
|
||||
@@ -275,6 +276,19 @@ const reconnectInterval = ref<ReturnType<typeof setInterval> | null>(null);
|
||||
const isFirstMount = ref(true);
|
||||
const isMounted = ref(true);
|
||||
|
||||
const INTERCOM_APP_ID = ref("ykeritl9");
|
||||
const auth = await useAuth();
|
||||
// @ts-expect-error - Auth is untyped
|
||||
const userId = ref(auth.value?.user?.id ?? null);
|
||||
// @ts-expect-error - Auth is untyped
|
||||
const username = ref(auth.value?.user?.username ?? null);
|
||||
// @ts-expect-error - Auth is untyped
|
||||
const email = ref(auth.value?.user?.email ?? null);
|
||||
const createdAt = ref(
|
||||
// @ts-expect-error - Auth is untyped
|
||||
auth.value?.user?.created ? Math.floor(new Date(auth.value.user.created).getTime() / 1000) : null,
|
||||
);
|
||||
|
||||
const route = useNativeRoute();
|
||||
const router = useRouter();
|
||||
const serverId = route.params.id as string;
|
||||
@@ -735,6 +749,8 @@ const openInstallLog = () => {
|
||||
const cleanup = () => {
|
||||
isMounted.value = false;
|
||||
|
||||
shutdown();
|
||||
|
||||
stopPolling();
|
||||
stopUptimeUpdates();
|
||||
if (reconnectInterval.value) {
|
||||
@@ -774,6 +790,27 @@ onMounted(() => {
|
||||
connectWebSocket();
|
||||
}
|
||||
|
||||
if (username.value && email.value && userId.value && createdAt.value) {
|
||||
const currentUser = auth.value?.user as any;
|
||||
const matches =
|
||||
username.value === currentUser?.username &&
|
||||
email.value === currentUser?.email &&
|
||||
userId.value === currentUser?.id &&
|
||||
createdAt.value === Math.floor(new Date(currentUser?.created).getTime() / 1000);
|
||||
|
||||
if (matches) {
|
||||
Intercom({
|
||||
app_id: INTERCOM_APP_ID.value,
|
||||
userId: userId.value,
|
||||
name: username.value,
|
||||
email: email.value,
|
||||
created_at: createdAt.value,
|
||||
});
|
||||
} else {
|
||||
console.warn("[PYROSERVERS][INTERCOM] mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
DOMPurify.addHook(
|
||||
"afterSanitizeAttributes",
|
||||
(node: {
|
||||
|
||||
Reference in New Issue
Block a user