SHA256
UI: доработать профиль и связи
This commit is contained in:
@@ -254,9 +254,14 @@ export async function loadUserProfileCard(login) {
|
||||
address: fields.address || '',
|
||||
web: fields.web || '',
|
||||
phone: fields.phone || '',
|
||||
about: fields.about || '',
|
||||
spiritualPath: fields.spiritual_path || '',
|
||||
accountRole: String(snapshot?.accountRole || '').trim().toLowerCase(),
|
||||
shineStatus: String(snapshot?.shineStatus || '').trim().toLowerCase(),
|
||||
gender: String(snapshot?.gender || 'unknown').trim().toLowerCase() || 'unknown',
|
||||
official: Boolean(toggles.official),
|
||||
shine: Boolean(toggles.shine),
|
||||
// Compatibility aliases for older graph/card consumers; values come only from the new profile schema.
|
||||
official: String(snapshot?.accountRole || '').trim().toLowerCase() === 'primary',
|
||||
shine: String(snapshot?.shineStatus || '').trim().toLowerCase() === 'shining',
|
||||
avatar: snapshot?.avatar?.txId
|
||||
? {
|
||||
ar: String(snapshot.avatar.txId).trim(),
|
||||
|
||||
@@ -12,12 +12,17 @@ export const profileFieldDefs = [
|
||||
{ key: 'address', readKeys: ['address'], label: 'Адрес', placeholder: 'Город, улица, дом' },
|
||||
{ key: 'web', readKeys: ['web'], label: 'Веб', placeholder: 'Сайт или профиль' },
|
||||
{ key: 'phone', readKeys: ['phone'], label: 'Телефон', placeholder: '+7 ...' },
|
||||
{ key: 'about', readKeys: ['about'], label: 'О себе', placeholder: 'Коротко расскажите о себе', maxLength: 160, multiline: true },
|
||||
{ key: 'spiritual_path', readKeys: ['spiritual_path'], label: 'Духовный путь', placeholder: 'Расскажите о своём духовном пути, опыте, практиках и взглядах', maxLength: 5000, multiline: true },
|
||||
];
|
||||
|
||||
export const profileToggleDefs = [
|
||||
{ key: 'official', label: 'Официальный' },
|
||||
{ key: 'shine', label: 'Сияющий' },
|
||||
];
|
||||
export const profileToggleDefs = []; // legacy boolean toggles are no longer used by the new UI.
|
||||
|
||||
export const PROFILE_ACCOUNT_ROLE_PRIMARY = 'primary';
|
||||
export const PROFILE_ACCOUNT_ROLE_NON_VOTING = 'non_voting';
|
||||
export const PROFILE_SHINE_SHINING = 'shining';
|
||||
export const PROFILE_SHINE_UNKNOWN = 'unknown';
|
||||
export const PROFILE_SHINE_NOT_INTERESTED = 'not_interested';
|
||||
|
||||
export const PROFILE_GENDER_MALE = 'male';
|
||||
export const PROFILE_GENDER_FEMALE = 'female';
|
||||
@@ -104,23 +109,31 @@ export async function loadProfileSnapshot(login) {
|
||||
key: field.key,
|
||||
label: field.label,
|
||||
placeholder: field.placeholder,
|
||||
maxLength: Number(field.maxLength || 300),
|
||||
multiline: Boolean(field.multiline),
|
||||
value: latest?.value || '',
|
||||
timeMs: latest?.timeMs || 0,
|
||||
});
|
||||
}
|
||||
|
||||
const toggles = [];
|
||||
for (let i = 0; i < profileToggleDefs.length; i += 1) {
|
||||
const toggle = profileToggleDefs[i];
|
||||
const latest = loadLatestByAliasesFromItems(items, [toggle.key]);
|
||||
toggles.push({
|
||||
key: toggle.key,
|
||||
label: toggle.label,
|
||||
enabled: latest ? parseToggleValue(latest.value) : false,
|
||||
rawValue: latest?.value || 'no',
|
||||
timeMs: latest?.timeMs || 0,
|
||||
});
|
||||
}
|
||||
const latestAccountRole = loadLatestByAliasesFromItems(items, ['account_role']);
|
||||
const rawAccountRole = String(latestAccountRole?.value || '').trim().toLowerCase();
|
||||
const accountRole = rawAccountRole === PROFILE_ACCOUNT_ROLE_PRIMARY || rawAccountRole === PROFILE_ACCOUNT_ROLE_NON_VOTING
|
||||
? rawAccountRole
|
||||
: '';
|
||||
|
||||
const latestShine = loadLatestByAliasesFromItems(items, ['shine']);
|
||||
const rawShine = String(latestShine?.value || '').trim().toLowerCase();
|
||||
let shineStatus = '';
|
||||
if (rawShine === PROFILE_SHINE_SHINING || rawShine === 'yes') shineStatus = PROFILE_SHINE_SHINING;
|
||||
else if (rawShine === PROFILE_SHINE_UNKNOWN) shineStatus = PROFILE_SHINE_UNKNOWN;
|
||||
else if (rawShine === PROFILE_SHINE_NOT_INTERESTED) shineStatus = PROFILE_SHINE_NOT_INTERESTED;
|
||||
// Legacy shine=no is intentionally ignored. Legacy official=yes/no is not read at all.
|
||||
|
||||
const toggles = [
|
||||
{ key: 'account_role', label: 'Роль аккаунта', enabled: accountRole === PROFILE_ACCOUNT_ROLE_PRIMARY, rawValue: accountRole, timeMs: latestAccountRole?.timeMs || 0 },
|
||||
{ key: 'shine', label: 'Сияние', enabled: shineStatus === PROFILE_SHINE_SHINING, rawValue: shineStatus, timeMs: latestShine?.timeMs || 0 },
|
||||
];
|
||||
|
||||
const latestGender = loadLatestByAliasesFromItems(items, ['gender']);
|
||||
const gender = normalizeGenderValue(latestGender?.value || PROFILE_GENDER_UNKNOWN);
|
||||
@@ -145,6 +158,10 @@ export async function loadProfileSnapshot(login) {
|
||||
return {
|
||||
fields,
|
||||
toggles,
|
||||
accountRole,
|
||||
accountRoleTimeMs: latestAccountRole?.timeMs || 0,
|
||||
shineStatus,
|
||||
shineTimeMs: latestShine?.timeMs || 0,
|
||||
gender,
|
||||
genderTimeMs: latestGender?.timeMs || 0,
|
||||
avatar,
|
||||
@@ -161,14 +178,24 @@ export async function saveProfileParamBlock(login, key, value) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveProfileToggle(login, key, enabled) {
|
||||
export async function saveProfileStatus(login, key, value) {
|
||||
const cleanKey = String(key || '').trim();
|
||||
const cleanValue = String(value || '').trim().toLowerCase();
|
||||
if (cleanKey === 'account_role' && ![PROFILE_ACCOUNT_ROLE_PRIMARY, PROFILE_ACCOUNT_ROLE_NON_VOTING].includes(cleanValue)) {
|
||||
throw new Error('Некорректное значение account_role');
|
||||
}
|
||||
if (cleanKey === 'shine' && ![PROFILE_SHINE_SHINING, PROFILE_SHINE_UNKNOWN, PROFILE_SHINE_NOT_INTERESTED].includes(cleanValue)) {
|
||||
throw new Error('Некорректное значение shine');
|
||||
}
|
||||
const storagePwd = await getStoragePwd();
|
||||
await authService.addBlockUserParam({
|
||||
login,
|
||||
param: key,
|
||||
value: enabled ? 'yes' : 'no',
|
||||
storagePwd,
|
||||
});
|
||||
await authService.addBlockUserParam({ login, param: cleanKey, value: cleanValue, storagePwd });
|
||||
}
|
||||
|
||||
// Kept only for old callers outside the current UI. New code must use saveProfileStatus().
|
||||
export async function saveProfileToggle(login, key, enabled) {
|
||||
if (key === 'shine') return saveProfileStatus(login, 'shine', enabled ? PROFILE_SHINE_SHINING : PROFILE_SHINE_UNKNOWN);
|
||||
if (key === 'official') throw new Error('Параметр official устарел. Используйте account_role.');
|
||||
throw new Error(`Неизвестный legacy toggle: ${key}`);
|
||||
}
|
||||
|
||||
export async function saveProfileGender(login, gender) {
|
||||
|
||||
Reference in New Issue
Block a user