Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/channel message wechaty #212

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mixins/message-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
type SayablePayload,
sayableTypes,
} from '../schemas/sayable.js'
import type { ChannelPayload } from '../schemas/channel.js'

const filebox = (filebox: string | FileBoxInterface) => typeof filebox === 'string' ? FileBox.fromJSON(filebox) : filebox

Expand Down Expand Up @@ -67,6 +68,7 @@ const messageMixin = <MinxinBase extends typeof PuppetSkeleton & CacheMixin>(bas
abstract messageMiniProgram (messageId: string) : Promise<MiniProgramPayload>
abstract messageUrl (messageId: string) : Promise<UrlLinkPayload>
abstract messageLocation (messageId: string) : Promise<LocationPayload>
abstract messageChannel (messageId: string) : Promise<ChannelPayload>

abstract messageForward (conversationId: string, messageId: string,) : Promise<void | string>
abstract messageSendContact (conversationId: string, contactId: string) : Promise<void | string>
Expand All @@ -76,6 +78,7 @@ const messageMixin = <MinxinBase extends typeof PuppetSkeleton & CacheMixin>(bas
abstract messageSendPost (conversationId: string, postPayload: PostPayload) : Promise<void | string>
abstract messageSendText (conversationId: string, text: string, mentionIdList?: string[]) : Promise<void | string>
abstract messageSendUrl (conversationId: string, urlLinkPayload: UrlLinkPayload) : Promise<void | string>
abstract messageSendChannel (conversationId: string, channelPayload: ChannelPayload) : Promise<void | string>

abstract messageRecall (messageId: string) : Promise<boolean>

Expand Down Expand Up @@ -280,6 +283,8 @@ const messageMixin = <MinxinBase extends typeof PuppetSkeleton & CacheMixin>(bas
return this.messageSendText(conversationId, sayable.payload.text, sayable.payload.mentions)
case sayableTypes.Post:
return this.messageSendPost(conversationId, sayable.payload)
case sayableTypes.Channel:
return this.messageSendChannel(conversationId, sayable.payload)
default:
throw new Error('unsupported sayable payload: ' + JSON.stringify(sayable))
}
Expand Down
4 changes: 4 additions & 0 deletions src/mixins/sayable-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const sayableMixin = <MixinBase extends typeof PuppetSkeleton & MessageMixin & P
const postPayload = await this.postPayload(sayableId)
return sayablePayloads.post(postPayload)
}
case MessageType.Channel: {
const channelPayload = await this.messageChannel(sayableId)
return sayablePayloads.channel(channelPayload)
}

default:
log.warn('PuppetSayableMixin',
Expand Down
2 changes: 2 additions & 0 deletions src/mods/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import type {
TapPayload,
UrlLinkPayload,
SayablePayload,
ChannelPayload,
} from '../schemas/mod.js'
import {
sayablePayloads,
Expand Down Expand Up @@ -81,6 +82,7 @@ export type {
SayablePayload as Sayable,
TapPayload as Tap,
UrlLinkPayload as UrlLink,
ChannelPayload as Channel,
}
export {
sayablePayloads as sayable, // Sayable payload creators
Expand Down
2 changes: 2 additions & 0 deletions src/mods/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PostType,
TapType,
sayableTypes,
ChannelType,

CHAT_EVENT_DICT,
PUPPET_EVENT_DICT,
Expand All @@ -32,6 +33,7 @@ export {
PostType as Post,
TapType as Tap,
sayableTypes as Sayable,
ChannelType as Channel,
/**
* Huan(202201): `DirtyType as Payload` will be removed after Dec 31, 2023
* @deprecated: use Dirty instead of Payload
Expand Down
19 changes: 19 additions & 0 deletions src/schemas/channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface ChannelPayload {
avatar: string,
coverUrl: string,
desc: string,
extras: string,
feedType: number,
nickname: string,
thumbUrl: string,
url: string,
objectId?: string,
objectNonceId?: string,
}

export enum ChannelType {
Unknown = 0,
Photo = 2,
Video = 4,
Live = 9,
hcfw007 marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion src/schemas/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export enum MessageType {
Url = 14, // Url(5)
Video = 15, // Video(4), Video(43)
Post = 16, // Moment, Channel, Tweet, etc

Channel = 17, // Channel
System = 18, // System Message
}

Expand Down
7 changes: 7 additions & 0 deletions src/schemas/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ import type {
ChatEventName,
} from './puppet.js'

import {
type ChannelPayload,
ChannelType,
} from './channel.js'

import {
sayablePayloads,
sayableTypes,
Expand Down Expand Up @@ -122,6 +127,7 @@ export {
sayableTypes,
ScanStatus,
TapType,
ChannelType,
type ChatEventName,
type ContactPayload,
type ContactQueryFilter,
Expand Down Expand Up @@ -170,5 +176,6 @@ export {
type TapPayload,
type TapQueryFilter,
type UrlLinkPayload,
type ChannelPayload,
YOU,
}
4 changes: 4 additions & 0 deletions src/schemas/sayable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MessageType } from './message.js'
import type { LocationPayload } from './location.js'
import type { UrlLinkPayload } from './url-link.js'
import type { MiniProgramPayload } from './mini-program.js'
import type { ChannelPayload } from './channel.js'
import type {
PostPayload,
SayablePayloadPost,
Expand All @@ -21,6 +22,7 @@ const payloadLocation = (locationPayload: LocationPayload) => ({ ...loc
const payloadMiniProgram = (miniProgramPayload: MiniProgramPayload) => ({ ...miniProgramPayload })
const payloadUrlLink = (urlLinkPayload: UrlLinkPayload) => ({ ...urlLinkPayload })
const payloadPost = (postPayload: PostPayload) => ({ ...postPayload })
const payloadChannel = (channelPayload: ChannelPayload) => ({ ...channelPayload })

/**
* using `types` as a static typed string name list for `createAction`
Expand Down Expand Up @@ -61,6 +63,7 @@ const location = createAction(sayableTypes.Location, payloadLocation)()
const miniProgram = createAction(sayableTypes.MiniProgram, payloadMiniProgram)()
const url = createAction(sayableTypes.Url, payloadUrlLink)()
const post = createAction(sayableTypes.Post, payloadPost)()
const channel = createAction(sayableTypes.Channel, payloadChannel)()

/**
* Huan(202201): Recursive type references
Expand All @@ -77,6 +80,7 @@ const sayablePayloadsNoPost = {
text,
url,
video,
channel,
} as const

/**
Expand Down