Skip to content

Commit

Permalink
Merge pull request #66 from juzibot/feat/room-dynamic-qrcode
Browse files Browse the repository at this point in the history
feat: ✨ add parse room dynamic qrcode and join room by this qrcode
  • Loading branch information
su-chang authored Nov 15, 2024
2 parents fca172a + 9b8bf50 commit 7595ef4
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@juzi/wechaty-puppet",
"version": "1.0.92",
"version": "1.0.93",
"description": "Abstract Puppet for Wechaty",
"type": "module",
"exports": {
Expand Down
3 changes: 2 additions & 1 deletion src/mixins/room-invitation-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
} from '../config.js'

import type {
RoomInvitationAcceptByQRCode,
RoomInvitationPayload,
} from '../schemas/room-invitation.js'

Expand Down Expand Up @@ -48,7 +49,7 @@ const roomInvitationMixin = <MixinBase extends typeof PuppetSkeleton & CacheMixi
}

abstract roomInvitationAccept (roomInvitationId: string): Promise<void>

abstract roomInvitationAcceptByQRCode (qrcode: string): Promise<RoomInvitationAcceptByQRCode>
/**
* Issue #155 - https://github.com/wechaty/puppet/issues/155
*
Expand Down
2 changes: 2 additions & 0 deletions src/mixins/room-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
RoomPayloadFilterFunction,
RoomQueryFilter,
RoomPermission,
RoomParseDynamicQRCode,
} from '../schemas/room.js'

import type { PuppetSkeleton } from '../puppet/puppet-skeleton.js'
Expand Down Expand Up @@ -37,6 +38,7 @@ const roomMixin = <MixinBase extends typeof PuppetSkeleton & ContactMixin & Room
abstract roomDel (roomId: string, contactId: string | string[]) : Promise<void>
abstract roomList () : Promise<string[]>
abstract roomQRCode (roomId: string) : Promise<string>
abstract roomParseDynamicQRCode (url: string) : Promise<RoomParseDynamicQRCode>
abstract roomQuit (roomId: string) : Promise<void>
abstract roomTopic (roomId: string) : Promise<string>
abstract roomTopic (roomId: string, topic: string) : Promise<void>
Expand Down
4 changes: 4 additions & 0 deletions src/mods/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
type PuppetEventName,
type ChatEventName,
type RoomPermission,
type RoomParseDynamicQRCode,
type RoomInvitationAcceptByQRCode,
TagEventType,
TagGroupEventType,
ContactGender,
Expand Down Expand Up @@ -82,6 +84,8 @@ export {
type FriendshipAddOptions,
type MessageSendTextOptions,
type RoomPermission,
type RoomParseDynamicQRCode,
type RoomInvitationAcceptByQRCode,
type ContactIdExternalUserIdPair,
type RoomAntiSpamStrategy,
type TextContent,
Expand Down
4 changes: 4 additions & 0 deletions src/schemas/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ import {
type RoomMemberPayload,
type RoomMemberQueryFilter,
type RoomPermission,
type RoomParseDynamicQRCode,
RoomMemberJoinSceneType,
} from './room.js'
import type {
RoomInvitationPayload,
RoomInvitationAcceptByQRCode,
} from './room-invitation.js'
import type {
UrlLinkPayload,
Expand Down Expand Up @@ -226,11 +228,13 @@ export {
type PuppetEventName,
type PuppetOptions,
type RoomInvitationPayload,
type RoomInvitationAcceptByQRCode,
type RoomMemberPayload,
type RoomMemberQueryFilter,
type RoomPayload,
type RoomQueryFilter,
type RoomPermission,
type RoomParseDynamicQRCode,
type SayablePayload,
type TapPayload,
type TapQueryFilter,
Expand Down
5 changes: 5 additions & 0 deletions src/schemas/room-invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ export interface RoomInvitationPayload {
timestamp : number, // Unix Timestamp, in seconds or milliseconds
receiverId : string, // the room invitation should send to which contact.
}

export interface RoomInvitationAcceptByQRCode {
roomId: string,
chatId: string,
}
6 changes: 6 additions & 0 deletions src/schemas/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export interface RoomPermission {
disableMemberMutualAdd: boolean, // 禁止外部群成员互相添加
}

export interface RoomParseDynamicQRCode {
qrcode: string, // 二维码url
qrcodeImgUrl: string, // 二维码图片url
roomName: string, // 群名称
}

/** @hidden */
export type RoomPayloadFilterFunction = (payload: RoomPayload) => boolean

Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/puppet-test/puppet-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class PuppetTest extends PUPPET.Puppet {
*
*/
override async roomInvitationAccept (_: string): Promise<void> { }
override async roomInvitationAcceptByQRCode (_: string): Promise<PUPPET.types.RoomInvitationAcceptByQRCode> { return {} as any }

override async roomInvitationRawPayload (roomInvitationId: string) : Promise<any> { return { roomInvitationId } as any }
override async roomInvitationRawPayloadParser (rawPayload: any) : Promise<PUPPET.payloads.RoomInvitation> { return rawPayload }
Expand All @@ -208,6 +209,7 @@ class PuppetTest extends PUPPET.Puppet {
override async roomDel (roomId: string, contactId: string) : Promise<void> { return { contactId, roomId } as any }
override async roomQuit (roomId: string) : Promise<void> { return { roomId } as any }
override async roomQRCode (roomId: string) : Promise<string> { return { roomId } as any }
override async roomParseDynamicQRCode (url: string) : Promise<PUPPET.types.RoomParseDynamicQRCode> { return { url } as any }

override async roomOwnerTransfer (roomId: string, contactId: string): Promise<void> { return { roomId, contactId } as any }
override async roomDismiss (roomId: string): Promise<void> { return { roomId } as any }
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/smoke-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class PuppetTest extends PUPPET.Puppet {
*
*/
override async roomInvitationAccept (roomInvitationId: string): Promise<void> { void roomInvitationId }
override async roomInvitationAcceptByQRCode (qrcode: string): Promise<PUPPET.types.RoomInvitationAcceptByQRCode> { return { qrcode } as any }

override async roomInvitationRawPayload (roomInvitationId: string) : Promise<any> { return { roomInvitationId } as any }
override async roomInvitationRawPayloadParser (rawPayload: any) : Promise<PUPPET.payloads.RoomInvitation> { return rawPayload }
Expand All @@ -192,6 +193,7 @@ class PuppetTest extends PUPPET.Puppet {
override async roomDel (roomId: string, contactId: string) : Promise<void> { return { contactId, roomId } as any }
override async roomQuit (roomId: string) : Promise<void> { return { roomId } as any }
override async roomQRCode (roomId: string) : Promise<string> { return { roomId } as any }
override async roomParseDynamicQRCode (url: string) : Promise<PUPPET.types.RoomParseDynamicQRCode> { return { url } as any }

override async roomTopic (roomId: string) : Promise<string>
override async roomTopic (roomId: string, topic: string) : Promise<void>
Expand Down

0 comments on commit 7595ef4

Please sign in to comment.