Skip to content

Commit

Permalink
feat(event): implement guild-request event
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp committed Aug 23, 2024
1 parent 660c7d5 commit d4f322d
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 3 deletions.
11 changes: 11 additions & 0 deletions packages/engine-chronocat-api/src/definitions/groupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ export const quitGroup = define<
]
>('ns-ntApi-2', 'nodeIKernelGroupService/quitGroup')

export const getSingleScreenNotifies = define<
unknown,
[
{
doubt: boolean
startSeq: string // '1716209619000000'
number: number // 16
},
]
>('ns-ntApi-2', 'nodeIKernelGroupService/getSingleScreenNotifies')

export const operateSysNotify = define<
unknown,
[
Expand Down
1 change: 1 addition & 0 deletions packages/engine-chronocat-event/src/globalVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Group, Profile } from '@chronocat/red'

export const requestMethodMap: Record<string, string> = {}
export const emittedBuddyReqList: string[] = []
export const emittedGroupReqList: string[] = []

export const sendQueue: string[] = []

Expand Down
29 changes: 27 additions & 2 deletions packages/engine-chronocat-event/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
OnBuddyListChange,
OnBuddyReqChange,
OnGroupListUpdate,
OnGroupSingleScreenNotifies,
OnMemberInfoChange,
OnMemberListChange,
OnMsgInfoListUpdate,
Expand All @@ -22,13 +23,15 @@ import type { ChronocatContext } from '@chronocat/shell'
import type { IpcManData } from 'ipcman'
import {
emittedBuddyReqList,
emittedGroupReqList,
friendMap,
groupMap,
requestMethodMap,
sendQueue,
} from './globalVars'
import {
FriendRequestDispatchMessage,
GuildRequestDispatchMessage,
MessageCreatedDispatchMessage,
MessageDeletedDispatchMessage,
} from './messages'
Expand Down Expand Up @@ -208,6 +211,30 @@ const dispatcher = async (
return
}

case 'nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated': {
// const {} = payload as OnGroupNotifiesUnreadCountUpdated

return
}

case 'nodeIKernelGroupListener/onGroupSingleScreenNotifies': {
const { notifies } = payload as OnGroupSingleScreenNotifies

for (const notify of notifies) {
const uin = ctx.chronocat.uix.getUin(notify.user1.uid)
if (!uin) return

const key = `${notify.group.groupCode}:${uin}:${notify.seq}`
if (emittedGroupReqList.includes(key)) return

emittedGroupReqList.push(key)

ctx.chronocat.emit(new GuildRequestDispatchMessage(notify, uin))
}

return
}

case 'onBuddyListChange':
case 'nodeIKernelBuddyListener/onBuddyListChange': {
const { data } = payload as OnBuddyListChange
Expand All @@ -225,8 +252,6 @@ const dispatcher = async (
}

case 'nodeIKernelBuddyListener/onBuddyReqChange': {
if (channel !== 'IPC_DOWN_2') return

const { buddyReqs } = payload as OnBuddyReqChange

buddyReqs.forEach((x) => {
Expand Down
42 changes: 41 additions & 1 deletion packages/engine-chronocat-event/src/messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BuddyReq, RedMessage } from '@chronocat/red'
import type { BuddyReq, GroupNotify, RedMessage } from '@chronocat/red'
import type {
ChronocatContext,
ChronocatLogCurrentConfig,
Expand Down Expand Up @@ -38,6 +38,46 @@ export class MessageDeletedDispatchMessage implements SatoriDispatchMessage {
.map((e) => ((e.type = 'message-deleted'), e))
}

export class GuildRequestDispatchMessage implements SatoriDispatchMessage {
constructor(
private notify: GroupNotify,
private uin: string,
) {}

type = 'satori' as const

toSatori = async (
ctx: ChronocatContext,
_config: O.Intersect<
ChronocatLogCurrentConfig,
ChronocatSatoriEventsConfig
>,
) => {
const event: Event = {
id: undefined as unknown as number,
type: 'guild-request',

platform: ctx.chronocat.platform,
self_id: undefined as unknown as string,
timestamp: new Date().getTime(),

guild: {
id: this.notify.group.groupCode,
name: this.notify.group.groupName,
avatar: `https://p.qlogo.cn/gh/${this.notify.group.groupCode}/${this.notify.group.groupCode}/640`,
},

user: {
id: `${this.uin}`,
name: this.notify.user1.nickName,
avatar: `http://thirdqq.qlogo.cn/headimg_dl?dst_uin=${this.uin}&spec=640`,
},
}

return [event]
}
}

export class FriendRequestDispatchMessage implements SatoriDispatchMessage {
constructor(
private buddyReq: BuddyReq,
Expand Down
77 changes: 77 additions & 0 deletions packages/red/src/redIpcEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,80 @@ export interface MsgsIncludeSelf {
export interface OnOpenParamChange {
data: Contact[]
}

export interface OnGroupNotifiesUnreadCountUpdated {
/**
* 是否有过滤消息
*/
doubt: boolean

/**
* 最旧未读消息 ID
*/
oldestUnreadSeq: string // '1716209619000000'

/**
*
* 未读消息数
*/
unreadCount: number
}

export interface OnGroupSingleScreenNotifies {
/**
* 是否是过滤消息列表
*/
doubt: false

/**
* 分页 ID
*/
nextStartSeq: '0'

notifies: GroupNotify[]
}

export interface GroupNotify {
seq: string // '1716209619000000'

type: number // 7

status: number // 1

group: {
groupCode: string
groupName: string
}

user1: {
uid: string
nickName: string
}

user2: {
uid: string
nickName: string
}

actionUser: {
uid: string
nickName: string
}

actionTime: string // '0'

invitationExt: {
srcType: number // 0
groupCode: string // '0'
waitStatus: number // 0
}

/**
* 验证消息
*/
postscript: string

repeatSeqs: []

warningTips: string // '该账号存在风险,请谨慎操作'
}

0 comments on commit d4f322d

Please sign in to comment.