refactor(im): 对齐文赫电竞消息系统(配对群ID+稳定监听)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import GoEasy from '../static/lib/goeasy-2.13.24.esm.min';
|
||||
import { jianquanxian } from './imAuth/jianquanxian';
|
||||
import { parseOrderCardText } from './group-chat.js';
|
||||
import { persistGroupMeta, getFreshImUser, getImUserIdForRole } from './im-user.js';
|
||||
import { persistGroupMeta, getFreshImUser, getImUserIdForRole, getLocalImUserId, getLocalImIdentity } from './im-user.js';
|
||||
|
||||
let _globalPrivateHandler = null;
|
||||
let _globalGroupHandler = null;
|
||||
@@ -82,9 +82,11 @@ function getCurrentGoEasyUserId() {
|
||||
}
|
||||
|
||||
function getExpectedImUserId(app) {
|
||||
const fromLocal = getLocalImUserId(app);
|
||||
if (fromLocal) return fromLocal;
|
||||
const uid = wx.getStorageSync('uid');
|
||||
if (!uid) return '';
|
||||
const role = app.globalData.currentRole || 'normal';
|
||||
const role = app.globalData.currentRole || getLocalImIdentity(app) || 'normal';
|
||||
return getImUserIdForRole(role, uid);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { getPrimaryRole } from './primary-role.js';
|
||||
import { resolveAvatarUrl } from './avatar.js';
|
||||
import { ensureRoleOnCenterPage } from './role-tab-bar.js';
|
||||
import { isStaffMode } from './staff-api.js';
|
||||
|
||||
/** 联系对象前缀:管事/组长/考核官已废弃独立前缀,统一 Ds */
|
||||
const PEER_PREFIX = {
|
||||
@@ -14,15 +15,37 @@ const PEER_PREFIX = {
|
||||
kaoheguan: 'Ds',
|
||||
};
|
||||
|
||||
export const IM_ROLE_PREFIX = {
|
||||
normal: 'Boss',
|
||||
dashou: 'Ds',
|
||||
shangjia: 'Sj',
|
||||
guanshi: 'Ds',
|
||||
zuzhang: 'Ds',
|
||||
kaoheguan: 'Ds',
|
||||
};
|
||||
|
||||
export function getDefaultAvatar(app) {
|
||||
const oss = app.globalData.ossImageUrl || '';
|
||||
return oss + (app.globalData.morentouxiang || '');
|
||||
}
|
||||
|
||||
export function getImPrefixForRole(role) {
|
||||
if (isStaffMode()) return 'Sj';
|
||||
return PEER_PREFIX[role] || 'Ds';
|
||||
}
|
||||
|
||||
/** 当前端连接 GoEasy 用的 userId */
|
||||
export function getImUserIdForRole(role, uid) {
|
||||
if (!uid) return '';
|
||||
const prefix = getImPrefixForRole(role);
|
||||
return prefix + uid;
|
||||
}
|
||||
|
||||
/** 当前端连接 GoEasy 用的 userId(子客服仍用 Sj) */
|
||||
export function getLocalImUserId(app) {
|
||||
app = app || getApp();
|
||||
const uid = wx.getStorageSync('uid') || '';
|
||||
if (!uid) return '';
|
||||
if (isStaffMode()) return 'Sj' + uid;
|
||||
const primary = getPrimaryRole(app);
|
||||
if (primary === 'dashou') return 'Ds' + uid;
|
||||
if (primary === 'shangjia') return 'Sj' + uid;
|
||||
@@ -31,15 +54,43 @@ export function getLocalImUserId(app) {
|
||||
|
||||
export function getLocalImIdentity(app) {
|
||||
app = app || getApp();
|
||||
if (isStaffMode()) return 'shangjia';
|
||||
return getPrimaryRole(app) || 'normal';
|
||||
}
|
||||
|
||||
export function getFreshImUser(app, role, uid) {
|
||||
const effectiveRole = isStaffMode() ? 'shangjia' : role;
|
||||
const id = getImUserIdForRole(effectiveRole, uid);
|
||||
const touxiang = wx.getStorageSync('touxiang') || '';
|
||||
const avatar = resolveAvatarUrl(touxiang, app);
|
||||
const name = app.globalData.currentUser?.name || `用户${(uid || '').slice(-6)}`;
|
||||
return { id, name, avatar };
|
||||
}
|
||||
|
||||
export function persistGroupMeta(app, groupId, meta) {
|
||||
if (!groupId || !meta) return;
|
||||
if (!app.globalData.groupInfoMap) app.globalData.groupInfoMap = {};
|
||||
app.globalData.groupInfoMap[groupId] = { ...app.globalData.groupInfoMap[groupId], ...meta };
|
||||
try {
|
||||
const cache = wx.getStorageSync('pairGroupMetaCache') || {};
|
||||
cache[groupId] = app.globalData.groupInfoMap[groupId];
|
||||
wx.setStorageSync('pairGroupMetaCache', cache);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
export function loadGroupMetaCache(app) {
|
||||
try {
|
||||
const cache = wx.getStorageSync('pairGroupMetaCache') || {};
|
||||
if (!app.globalData.groupInfoMap) app.globalData.groupInfoMap = {};
|
||||
Object.assign(app.globalData.groupInfoMap, cache);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
export function buildPeerImUserId(uid, role = 'dashou') {
|
||||
if (!uid) return '';
|
||||
return getImPrefixForRole(role) + uid;
|
||||
}
|
||||
|
||||
/** 联系邀请人/管事/组长:统一 Ds 前缀 */
|
||||
export function buildGuanshiPeerId(uid) {
|
||||
return buildDashouPeerId(uid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user