This commit is contained in:
pengxiaolong
2025-05-13 19:39:53 +08:00
parent 37da6765b8
commit c006a8e63d
1232 changed files with 96963 additions and 883 deletions

View File

@@ -0,0 +1,17 @@
import TUIChatEngine from '@tencentcloud/chat-uikit-engine';
export const DEFAULT_DESC: any = {
[TUIChatEngine.TYPES.MSG_TEXT]: '[文本]',
[TUIChatEngine.TYPES.MSG_FACE]: '[动画表情]',
[TUIChatEngine.TYPES.MSG_IMAGE]: '[图片]',
[TUIChatEngine.TYPES.MSG_FILE]: '[文件]',
[TUIChatEngine.TYPES.MSG_AUDIO]: '[语音]',
[TUIChatEngine.TYPES.MSG_VIDEO]: '[视频]',
[TUIChatEngine.TYPES.MSG_LOCATION]: '[地理位置]',
[TUIChatEngine.TYPES.MSG_MERGER]: '[聊天记录]',
[TUIChatEngine.TYPES.MSG_CUSTOM]: '[自定义消息]',
};
export enum PUSH_SCENE {
CHAT = 'chat',
CALL = 'call',
}

View File

@@ -0,0 +1,6 @@
import OfflinePushInfoManager from './offlinePushInfoManager';
export * from './const';
export * from './interface';
export default OfflinePushInfoManager.getInstance();

View File

@@ -0,0 +1,8 @@
import { IChatOfflinePushInfo, ICallOfflinePushInfo } from './interface';
export const chatOfflinePushInfo: IChatOfflinePushInfo = {
androidInfo: {},
apnsInfo: {},
};
export const callOfflinePushInfo: ICallOfflinePushInfo = {};

View File

@@ -0,0 +1,49 @@
import { IConversationModel } from '@tencentcloud/chat-uikit-engine';
export interface IOfflinePushInfoCreateParams {
conversation: IConversationModel;
payload?: any;
messageType: string;
}
export interface IOfflinePushApnsInfo {
sound?: string;
ignoreIOSBadge?: boolean;
disableVoipPush?: boolean;
image?: string;
}
export interface IOfflinePushAndroidInfo {
sound?: string;
XiaoMiChannelID?: string;
OPPOChannelID?: string;
FCMChannelID?: string;
VIVOClassification?: number;
VIVOCategory?: string;
HuaWeiCategory?: string;
HuaWeiImage?: string;
HonorImage?: string;
GoogleImage?: string;
}
// https://web.sdk.qcloud.com/im/doc/v3/zh-cn/SDK.html#sendMessage
export interface IChatOfflinePushInfo {
title?: string;
description?: string;
extension?: string;
androidInfo?: IOfflinePushAndroidInfo;
apnsInfo?: IOfflinePushApnsInfo;
}
// doc: https://cloud.tencent.com/document/product/269/105713
export interface ICallOfflinePushInfo {
title?: string;
description?: string;
iOSSound?: string;
androidSound?: string;
androidOPPOChannelID?: string;
androidXiaoMiChannelID?: string;
androidFCMChannelID?: string;
ignoreIOSBadge?: string;
isDisablePush?: string;
}

View File

@@ -0,0 +1,76 @@
import TUIChatEngine, { IConversationModel, StoreName, TUIStore, TUITranslateService } from '@tencentcloud/chat-uikit-engine';
import { transformTextWithKeysToEmojiNames } from '../emoji-config';
import {
IChatOfflinePushInfo,
IOfflinePushInfoCreateParams,
} from './interface';
import { chatOfflinePushInfo, callOfflinePushInfo } from './info';
import { DEFAULT_DESC, PUSH_SCENE } from './const';
class OfflinePushInfoManager {
private name = 'OfflinePushInfoManager';
private static instance: OfflinePushInfoManager | null = null;
private offlinePushInfo: any = {};
private constructor() {
this.offlinePushInfo = {
[PUSH_SCENE.CHAT]: chatOfflinePushInfo,
[PUSH_SCENE.CALL]: callOfflinePushInfo,
};
}
public static getInstance(): OfflinePushInfoManager {
if (!OfflinePushInfoManager.instance) {
OfflinePushInfoManager.instance = new OfflinePushInfoManager();
}
return OfflinePushInfoManager.instance;
}
public getOfflinePushInfo(scene: PUSH_SCENE) {
if (!Object.values(PUSH_SCENE).includes(scene)) {
console.error(`${this.name} getOfflinePushInfo scene: ${scene} is invalid`);
return null;
}
return this.offlinePushInfo[scene];
}
private genTitle(conversation: IConversationModel, userInfo: any) {
let title = conversation?.getShowName();
if (conversation.type === TUIChatEngine.TYPES.CONV_C2C) {
title = userInfo?.nick || userInfo?.userID;
}
return title;
}
private genDesc(messageType: string, payload: any) {
let desc = '';
if (messageType === TUIChatEngine.TYPES.MSG_TEXT) {
desc = transformTextWithKeysToEmojiNames(payload.text);
}
if (messageType === TUIChatEngine.TYPES.MSG_CUSTOM) {
desc = payload.description;
}
return desc || TUITranslateService.t(`TUIChat.${DEFAULT_DESC[messageType]}`);
}
public create(options: IOfflinePushInfoCreateParams): IChatOfflinePushInfo {
const { conversation, messageType = '', payload = {} } = options || {};
const userInfo = TUIStore.getData(StoreName.USER, 'userProfile');
const entity = {
sender: conversation.type === TUIChatEngine.TYPES.CONV_GROUP ? conversation.groupProfile?.groupID : userInfo?.userID,
nickName: userInfo?.nick,
chatType: conversation.type === TUIChatEngine.TYPES.CONV_GROUP ? 2 : 1,
version: 1,
action: 1,
};
return {
title: this.genTitle(conversation, userInfo),
description: this.genDesc(messageType, payload),
extension: JSON.stringify({ entity }),
...this.offlinePushInfo[PUSH_SCENE.CHAT],
};
}
}
export default OfflinePushInfoManager;