Skip to content

Commit 72cdae2

Browse files
committed
feat: support marketface
1 parent 60fa49a commit 72cdae2

File tree

9 files changed

+216
-19
lines changed

9 files changed

+216
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,63 @@
1-
import type { Media } from '@chronocat/red'
1+
import type { AssetRequest } from '@chronocat/red'
22
import { ChatType } from '@chronocat/red'
33
import type { ChronocatContext } from '@chronocat/shell'
4-
import { downloadRichMedia } from '../../../definitions/msgService'
5-
import { richMediaDownloadMap } from '../../../globalVars'
4+
import {
5+
downloadRichMedia,
6+
fetchMarketEmoticonAioImage,
7+
} from '../../../definitions/msgService'
8+
import { emojiDownloadMap, richMediaDownloadMap } from '../../../globalVars'
69

710
export const buildAssetsGet =
811
(ctx: ChronocatContext) => async (raw: string) => {
912
const data = JSON.parse(
1013
Buffer.from(raw, 'base64url').toString('utf-8'),
11-
) as Media
14+
) as AssetRequest
1215

13-
const downloadId = data.msgId + '::' + data.elementId
16+
if ('type' in data) {
17+
switch (data.type) {
18+
case 'marketface': {
19+
const downloadId = data.tabId + '::' + data.faceId
1420

15-
const downloadCompletePromise = new Promise<string>((res, rej) => {
16-
richMediaDownloadMap[downloadId] = res
17-
void ctx.chronocat.sleep(1000).then(rej)
18-
})
21+
const downloadCompletePromise = new Promise<string>((res, rej) => {
22+
emojiDownloadMap[downloadId] = res
23+
void ctx.chronocat.sleep(5000).then(rej)
24+
})
1925

20-
if (data.chatType === ChatType.Private && !data.peerUid.startsWith('u_'))
21-
data.peerUid = ctx.chronocat.uix.getUid(data.peerUid)!
26+
await fetchMarketEmoticonAioImage({
27+
marketEmoticonAioImageReq: {
28+
eId: data.faceId,
29+
epId: data.tabId,
30+
name: data.name,
31+
width: 200,
32+
height: 200,
33+
jobType: 0,
34+
encryptKey: data.key,
35+
filePath: data.filePath,
36+
downloadType: 3,
37+
},
38+
})
2239

23-
await downloadRichMedia({
24-
getReq: {
25-
...data,
26-
downloadType: 1,
27-
},
28-
})
40+
return await downloadCompletePromise
41+
}
42+
}
43+
} else {
44+
const downloadId = data.msgId + '::' + data.elementId
2945

30-
return await downloadCompletePromise
46+
const downloadCompletePromise = new Promise<string>((res, rej) => {
47+
richMediaDownloadMap[downloadId] = res
48+
void ctx.chronocat.sleep(1000).then(rej)
49+
})
50+
51+
if (data.chatType === ChatType.Private && !data.peerUid.startsWith('u_'))
52+
data.peerUid = ctx.chronocat.uix.getUid(data.peerUid)!
53+
54+
await downloadRichMedia({
55+
getReq: {
56+
...data,
57+
downloadType: 1,
58+
},
59+
})
60+
61+
return await downloadCompletePromise
62+
}
3163
}

packages/engine-chronocat-api/src/api/message/create/messager.ts

+13
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,19 @@ export class Messager {
277277
return
278278
}
279279

280+
case `${this.ctx.chronocat.platform}:marketface`: {
281+
this.children.push(
282+
r.marketFace(
283+
Number(attrs['tabId']),
284+
attrs['faceId'] as string,
285+
attrs['key'] as string,
286+
),
287+
)
288+
289+
this.isEndLine = false
290+
return
291+
}
292+
280293
case 'quote': {
281294
const [author] = this.ctx.chronocat.h.select(children, 'author')
282295

packages/engine-chronocat-api/src/api/message/create/r.ts

+22
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ const b = () => {
114114
},
115115
}),
116116

117+
marketFace: (
118+
tabId: number,
119+
faceId: string,
120+
key: string,
121+
): O.Partial<Element, 'deep'> => ({
122+
elementType: 11,
123+
elementId: '',
124+
marketFaceElement: {
125+
itemType: 6,
126+
faceInfo: 1,
127+
emojiPackageId: tabId,
128+
subType: 3,
129+
mediaType: 0,
130+
imageWidth: 200,
131+
imageHeight: 200,
132+
faceName: '[动画表情]',
133+
emojiId: faceId,
134+
key: key,
135+
emojiType: 1,
136+
},
137+
}),
138+
117139
pcPoke: (pokeType: number): O.Partial<Element, 'deep'> => ({
118140
elementId: '0',
119141
elementType: 6,

packages/engine-chronocat-api/src/definitions/msgService.ts

+19
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,22 @@ export const deleteActiveChatByUid = define<Record<string, never>, [string]>(
151151
'ns-ntApi-2',
152152
'nodeIKernelMsgService/deleteActiveChatByUid',
153153
)
154+
155+
export const fetchMarketEmoticonAioImage = define<
156+
never,
157+
[
158+
{
159+
marketEmoticonAioImageReq: {
160+
eId: string // '94c8ffa6977fd17e8b180b312cdddc28'
161+
epId: number // 235125
162+
name: string // '[抱抱]'
163+
width: 200
164+
height: 200
165+
jobType: 0
166+
encryptKey: string // 'ea4dc6c26b6f9c31'
167+
filePath: string
168+
downloadType: 3 | 4
169+
}
170+
},
171+
]
172+
>('ns-ntApi-2', 'nodeIKernelMsgService/fetchMarketEmoticonAioImage')

packages/engine-chronocat-api/src/globalVars.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const groupMap: Record<string, Group> = {}
1111
export const roleMap: Record<string, Record<string, number>> = {}
1212
export const friendMap: Record<string, Profile> = {}
1313
export const richMediaDownloadMap: Record<string, (path: string) => void> = {}
14+
export const emojiDownloadMap: Record<string, (path: string) => void> = {}
1415

1516
export const sendQueue: ((msg: RedMessage) => void)[] = []
1617
export const sendCallbackMap: Record<string, (msg: RedMessage) => void> = {}

packages/engine-chronocat-api/src/handler.ts

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
MsgsIncludeSelf,
44
OnAddSendMsg,
55
OnBuddyListChange,
6+
OnEmojiDownloadComplete,
67
OnGroupListUpdate,
78
OnMemberInfoChange,
89
OnMemberListChange,
@@ -20,6 +21,7 @@ import type { ChronocatContext } from '@chronocat/shell'
2021
import type { IpcManData } from 'ipcman'
2122
import {
2223
chronoEventEmitter,
24+
emojiDownloadMap,
2325
friendMap,
2426
groupMap,
2527
requestCallbackMap,
@@ -131,6 +133,19 @@ const responseDispatcher = async (
131133
return
132134
}
133135

136+
case 'nodeIKernelMsgListener/onEmojiDownloadComplete': {
137+
const { notifyInfo } = payload as OnEmojiDownloadComplete
138+
139+
const downloadId = `${notifyInfo.emojiPackageId}::${notifyInfo.emojiId}`
140+
141+
if (notifyInfo.downloadType === 0 && emojiDownloadMap[downloadId]) {
142+
emojiDownloadMap[downloadId]!(notifyInfo.path)
143+
delete emojiDownloadMap[downloadId]
144+
}
145+
146+
return
147+
}
148+
134149
case 'nodeIKernelProfileListener/onProfileSimpleChanged':
135150
case 'nodeIKernelProfileListener/onProfileDetailInfoChanged':
136151
case 'nodeIKernelGroupListener/onSearchMemberChange':

packages/engine-chronocat-event/src/parser/index.ts

+28
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,34 @@ async function parseElements(
552552
break
553553
}
554554

555+
case 11: {
556+
elements.push(
557+
ctx.chronocat.h(
558+
`${ctx.chronocat.platform}:marketface`,
559+
{
560+
tabId: m.marketFaceElement!.emojiPackageId,
561+
faceId: m.marketFaceElement!.emojiId,
562+
key: m.marketFaceElement!.key,
563+
},
564+
[
565+
ctx.chronocat.h('img', {
566+
src: `${config.self_url}/v1/assets/${Buffer.from(
567+
JSON.stringify({
568+
type: 'marketface',
569+
tabId: m.marketFaceElement!.emojiPackageId,
570+
faceId: m.marketFaceElement!.emojiId,
571+
key: m.marketFaceElement!.key,
572+
name: m.marketFaceElement!.faceName,
573+
filePath: m.marketFaceElement!.staticFacePath,
574+
}),
575+
).toString('base64url')}`,
576+
}),
577+
],
578+
),
579+
)
580+
break
581+
}
582+
555583
default:
556584
break
557585
}

packages/red/src/redEntity.ts

+47-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export interface Element {
275275
inlineKeyboardElement?: InlineKeyboardElement
276276
liveGiftElement?: unknown
277277
markdownElement?: MarkdownElement
278-
marketFaceElement?: unknown
278+
marketFaceElement?: MarketFaceElement
279279
multiForwardMsgElement?: unknown
280280
pttElement?: PttElement
281281
replyElement?: ReplyElement
@@ -653,6 +653,17 @@ export interface Media {
653653
downloadType: number
654654
}
655655

656+
export interface MarketFaceAssetRequest {
657+
type: 'marketface'
658+
tabId: number
659+
faceId: string
660+
key: string
661+
name: string
662+
filePath: string
663+
}
664+
665+
export type AssetRequest = MarketFaceAssetRequest | Media
666+
656667
export interface InlineKeyboardElement {
657668
rows: InlineKeyboardRow[]
658669
}
@@ -762,6 +773,41 @@ export interface MarkdownElement {
762773
content: string
763774
}
764775

776+
export interface MarketFaceElement {
777+
itemType: 6
778+
faceInfo: 1
779+
emojiPackageId: number // 235125
780+
subType: 3
781+
mediaType: 0
782+
imageWidth: number // 200
783+
imageHeight: number // 200
784+
faceName: string // '[好耶]'
785+
emojiId: string // 'e6e7817c449efdea0be5ceeef3a40c06'
786+
key: string // 'ea4dc6c26b6f9c31'
787+
param: unknown
788+
mobileParam: unknown
789+
sourceType: 0
790+
startTime: 0
791+
endTime: 0
792+
emojiType: 1
793+
hasIpProduct: 0
794+
voiceItemHeightArr: unknown
795+
sourceName: unknown
796+
sourceJumpUrl: unknown
797+
sourceTypeName: string // ''
798+
backColor: unknown
799+
volumeColor: unknown
800+
staticFacePath: string
801+
dynamicFacePath: string
802+
supportSize: MarketFaceElementSupportSize[]
803+
apngSupportSize: unknown
804+
}
805+
806+
export interface MarketFaceElementSupportSize {
807+
width: number // 300
808+
height: number // 300
809+
}
810+
765811
export interface ArkElement {
766812
bytesData: string
767813
linkInfo: never

packages/red/src/redIpcEntity.ts

+21
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ export interface OnRichMediaDownloadComplete {
7575
}
7676
}
7777

78+
export interface OnEmojiDownloadComplete {
79+
notifyInfo: {
80+
result: 0
81+
errMsg: string // ''
82+
emojiType: 0
83+
md5: string // ''
84+
resId: string // ''
85+
path: string
86+
extraData: Record<string, never>
87+
emojiId: string // '94c8ffa6977fd17e8b180b312cdddc28'
88+
emojiPackageId: string // '235125'
89+
90+
/**
91+
* 下载富媒体的类型。发送时 3 为 PNG,4 为动图;接收时 0 为 PNG,4 为动图。
92+
*/
93+
downloadType: 0 | 4
94+
95+
dynamicFacePath: string // ''
96+
}
97+
}
98+
7899
export interface OnGroupListUpdate {
79100
updateType: 1
80101
groupList: Group[]

0 commit comments

Comments
 (0)