added chat 2
This commit is contained in:
+55
-1
@@ -55,6 +55,9 @@ export const appNotificationEnabledSetting = ref(true)
|
||||
/** reactive — منبع قیمت فعال (montzar / zaarbox / main_product) */
|
||||
export const priceProviderSetting = ref('')
|
||||
|
||||
/** reactive — منوی افقی / دکمه «چت پشتیبانی» */
|
||||
export const supportChatMenuEnabledSetting = ref(false)
|
||||
|
||||
export const accountingProviderSetting = ref<AccountingProvider>('none')
|
||||
|
||||
let tahesabEnabledFromSettings: boolean | null = null
|
||||
@@ -65,7 +68,7 @@ let accountingProviderFromSettings: AccountingProvider | null = null
|
||||
|
||||
function isSwitchOn(value: string | undefined | null): boolean {
|
||||
const v = (value ?? '').trim().toLowerCase()
|
||||
return v === 'true' || v === '1' || v === 'yes'
|
||||
return v === 'true' || v === '1' || v === 'yes' || v === 'activate'
|
||||
}
|
||||
|
||||
function normalizeAccountingProvider(value: string | undefined | null): AccountingProvider {
|
||||
@@ -146,6 +149,56 @@ export function setAppNotificationEnabledFromSettings(value: boolean): void {
|
||||
appNotificationEnabledSetting.value = value
|
||||
}
|
||||
|
||||
export function setSupportChatMenuEnabledFromSettings(value: boolean): void {
|
||||
supportChatMenuEnabledSetting.value = value
|
||||
}
|
||||
|
||||
let lastShowToUsersChat = ''
|
||||
let lastHasChat = ''
|
||||
let lastChatApi = ''
|
||||
|
||||
/** منوی چت: show_to_users_chat + has_chat + chat_api */
|
||||
export function resolveSupportChatMenuEnabled(
|
||||
getValue: (key: string) => string | undefined | null
|
||||
): boolean {
|
||||
const api = String(getValue('chat_api') ?? '').trim()
|
||||
return (
|
||||
isSwitchOn(getValue('show_to_users_chat')) &&
|
||||
isSwitchOn(getValue('has_chat')) &&
|
||||
Boolean(api) &&
|
||||
api.toLowerCase() !== 'null'
|
||||
)
|
||||
}
|
||||
|
||||
export function applySupportChatMenuEnabledFromRows(
|
||||
rows: Array<{ key?: string; value?: string | null }>
|
||||
): void {
|
||||
let touched = false
|
||||
for (const row of rows) {
|
||||
const key = String(row.key ?? '')
|
||||
if (key === 'show_to_users_chat') {
|
||||
lastShowToUsersChat = String(row.value ?? '')
|
||||
touched = true
|
||||
} else if (key === 'has_chat') {
|
||||
lastHasChat = String(row.value ?? '')
|
||||
touched = true
|
||||
} else if (key === 'chat_api') {
|
||||
lastChatApi = String(row.value ?? '')
|
||||
touched = true
|
||||
}
|
||||
}
|
||||
if (!touched) return
|
||||
|
||||
setSupportChatMenuEnabledFromSettings(
|
||||
resolveSupportChatMenuEnabled((key) => {
|
||||
if (key === 'show_to_users_chat') return lastShowToUsersChat
|
||||
if (key === 'has_chat') return lastHasChat
|
||||
if (key === 'chat_api') return lastChatApi
|
||||
return undefined
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export function setPriceProviderFromSettings(value?: string | null): void {
|
||||
priceProviderSetting.value = (value ?? '').trim().toLowerCase()
|
||||
}
|
||||
@@ -217,6 +270,7 @@ async function bootstrapSettingsFromApi(): Promise<void> {
|
||||
applyConditionalOrderEnabledFromRows(list)
|
||||
applyPriceTriggerEnabledFromRows(list)
|
||||
applyAppNotificationEnabledFromRows(list)
|
||||
applySupportChatMenuEnabledFromRows(list)
|
||||
applyPriceProviderFromRows(list)
|
||||
setCachedMainMetal(mainMetalRow?.value)
|
||||
const { setCachedMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
|
||||
|
||||
Reference in New Issue
Block a user