refac
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
blobToFile,
|
||||
compressImage,
|
||||
extractInputVariables,
|
||||
getAge,
|
||||
getCurrentDateTime,
|
||||
getFormattedDate,
|
||||
getFormattedTime,
|
||||
@@ -31,6 +32,7 @@
|
||||
import FilesOverlay from '../chat/MessageInput/FilesOverlay.svelte';
|
||||
import Commands from '../chat/MessageInput/Commands.svelte';
|
||||
import InputVariablesModal from '../chat/MessageInput/InputVariablesModal.svelte';
|
||||
import { getSessionUser } from '$lib/apis/auths';
|
||||
|
||||
export let placeholder = $i18n.t('Send a Message');
|
||||
|
||||
@@ -116,11 +118,47 @@
|
||||
text = text.replaceAll('{{USER_LOCATION}}', String(location));
|
||||
}
|
||||
|
||||
const sessionUser = getSessionUser(localStorage.token);
|
||||
|
||||
if (text.includes('{{USER_NAME}}')) {
|
||||
const name = $user?.name || 'User';
|
||||
const name = sessionUser?.name || 'User';
|
||||
text = text.replaceAll('{{USER_NAME}}', name);
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_BIO}}')) {
|
||||
const bio = sessionUser?.bio || '';
|
||||
|
||||
if (bio) {
|
||||
text = text.replaceAll('{{USER_BIO}}', bio);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_GENDER}}')) {
|
||||
const gender = sessionUser?.gender || '';
|
||||
|
||||
if (gender) {
|
||||
text = text.replaceAll('{{USER_GENDER}}', gender);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_BIRTH_DATE}}')) {
|
||||
const birthDate = sessionUser?.date_of_birth || '';
|
||||
|
||||
if (birthDate) {
|
||||
text = text.replaceAll('{{USER_BIRTH_DATE}}', birthDate);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_AGE}}')) {
|
||||
const birthDate = sessionUser?.date_of_birth || '';
|
||||
|
||||
if (birthDate) {
|
||||
// calculate age using date
|
||||
const age = getAge(birthDate);
|
||||
text = text.replaceAll('{{USER_AGE}}', age);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_LANGUAGE}}')) {
|
||||
const language = localStorage.getItem('locale') || 'en-US';
|
||||
text = text.replaceAll('{{USER_LANGUAGE}}', language);
|
||||
|
||||
Reference in New Issue
Block a user