From 06d6fbad56cd2e8261d958c8291ca1820fa2acf2 Mon Sep 17 00:00:00 2001 From: NLOG Date: Wed, 2 Dec 2020 19:58:46 +0900 Subject: [PATCH 1/4] Add requestMusicList (#72) --- src/api/service-client.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/api/service-client.ts b/src/api/service-client.ts index c1cfc4bf..69ff4322 100644 --- a/src/api/service-client.ts +++ b/src/api/service-client.ts @@ -103,6 +103,10 @@ export class ServiceClient extends SessionApiClient { // profile + async requestMusicList(id: Long): Promise { + return this.request('GET', ServiceClient.getProfileApiPath(this.Agent, 'music/list.json'), { id: id.toString() }); + } + async requestMyProfile(): Promise { return this.request('GET', ServiceClient.getProfile3ApiPath(this.Agent, 'me.json')); } @@ -125,6 +129,10 @@ export class ServiceClient extends SessionApiClient { return `${agent}/friends/${api}`; } + static getProfileApiPath(agent: string, api: string) { + return `${agent}/profile/${api}`; + } + static getProfile3ApiPath(agent: string, api: string) { return `${agent}/profile3/${api}`; } From 95c1a346330fffb2aac5a36a894ea8f2027857d0 Mon Sep 17 00:00:00 2001 From: storycraft Date: Thu, 3 Dec 2020 16:19:50 +0900 Subject: [PATCH 2/4] FIxing #75 --- src/packet/packet-chat-on-room.ts | 7 ++++- src/packet/packet-rewrite.ts | 12 ++++---- src/talk/channel/channel-manager.ts | 45 +++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/packet/packet-chat-on-room.ts b/src/packet/packet-chat-on-room.ts index 0618fef7..c8d59ea5 100644 --- a/src/packet/packet-chat-on-room.ts +++ b/src/packet/packet-chat-on-room.ts @@ -44,7 +44,8 @@ export class PacketChatOnRoomRes extends LocoBsonResponsePacket { constructor( status: number, public ChannelId: Long = Long.ZERO, - public MemberList: (MemberStruct | OpenMemberStruct)[] = [], + public MemberList?: (MemberStruct | OpenMemberStruct)[], + public MemberIdList?: Long[], public Type: ChannelType = ChannelType.UNKNOWN, public WatermarkList: Long[] = [], public OpenChatToken: number = 0, @@ -73,6 +74,10 @@ export class PacketChatOnRoomRes extends LocoBsonResponsePacket { } } + if (rawData['mi']) { + this.MemberIdList = rawData['mi']; + } + if (rawData['olu']) this.ClientOpenProfile = Serializer.deserialize(rawData['olu'], OpenLinkMemberStruct.MAPPER); } diff --git a/src/packet/packet-rewrite.ts b/src/packet/packet-rewrite.ts index 004fdfc3..f940c61f 100644 --- a/src/packet/packet-rewrite.ts +++ b/src/packet/packet-rewrite.ts @@ -17,8 +17,8 @@ export class PacketRewriteReq extends LocoBsonRequestPacket { public LogId: Long = Long.ZERO, public Type: ChatType = ChatType.Text, public RewriteFeedType: FeedType = FeedType.OPENLINK_REWRITE_FEED, - public Unknown1: string = '', //Chat Reporting? - public Unknown2: string = '', + public ReportChannelLink: string = '', // Report channel + public Category: string = '', // Report Category ) { super(); } @@ -35,12 +35,12 @@ export class PacketRewriteReq extends LocoBsonRequestPacket { 't': this.Type }; - if (this.Unknown1 !== '') { - obj['rcli'] = this.Unknown1; + if (this.ReportChannelLink !== '') { + obj['rcli'] = this.ReportChannelLink; } - if (this.Unknown2 !== '') { - obj['cat'] = this.Unknown2; + if (this.Category !== '') { + obj['cat'] = this.Category; } if (this.RewriteFeedType === FeedType.RICH_CONTENT) { diff --git a/src/talk/channel/channel-manager.ts b/src/talk/channel/channel-manager.ts index b5e137ca..d20eabbd 100644 --- a/src/talk/channel/channel-manager.ts +++ b/src/talk/channel/channel-manager.ts @@ -38,6 +38,8 @@ import { PacketAddMemberReq, PacketAddMemberRes } from "../../packet/packet-add- import { PacketKickLeaveReq, PacketKickLeaveRes } from "../../packet/packet-kick-leave"; import { JsonUtil } from "../../util/json-util"; import { PacketCheckJoinReq, PacketCheckJoinRes } from "../../packet/packet-check-join"; +import { PacketGetMemberReq, PacketGetMemberRes } from "../../packet/packet-get-member"; +import { PacketMemberReq, PacketMemberRes } from "../../packet/packet-member"; export class ChannelManager extends IdStore { @@ -91,7 +93,14 @@ export class ChannelManager extends IdStore { } + let memberList = await this.requestDetailedMemberList(channel.Id); + + if (memberList) { + this.updateUserInfoList(channel, memberList); + } + await this.sendChatOn(channel); + this.set(id, channel); return channel; @@ -122,7 +131,7 @@ export class ChannelManager extends IdStore { if (channelInfo.displayMemberList) channel.updateDisplayUserInfoList(channelInfo.displayMemberList.map(this.getDisplayUserInfoFromStruct.bind(this))); } - protected initUserInfoList(channel: ManagedChatChannel, memberList: (MemberStruct | OpenMemberStruct)[], openProfile?: OpenMemberStruct) { + protected updateUserInfoList(channel: ManagedChatChannel, memberList: (MemberStruct | OpenMemberStruct)[], openProfile?: OpenMemberStruct) { if (!channel.isOpenChat()) { let normal = channel as ManagedChatChannel; @@ -217,6 +226,34 @@ export class ChannelManager extends IdStore { } } + protected async requestMemberList(channelId: Long): Promise<(MemberStruct | OpenMemberStruct)[] | null> { + let res = await this.client.NetworkManager.requestPacketRes(new PacketGetMemberReq(channelId)); + + if (res.StatusCode === StatusCode.SUCCESS) { + return res.MemberList!; + } else { + return null; + } + } + + protected async requestDetailedMemberList(channelId: Long, memberIdList?: Long[]): Promise<(MemberStruct | OpenMemberStruct)[] | null> { + if (!memberIdList) { + let simplfiedList = await this.requestMemberList(channelId); + + if (!simplfiedList) return null; + + memberIdList = simplfiedList.map(member => member.userId); + + } + let res = await this.client.NetworkManager.requestPacketRes(new PacketMemberReq(channelId, memberIdList)); + + if (res.StatusCode === StatusCode.SUCCESS) { + return res.MemberList!; + } else { + return null; + } + } + async sendChatOn(channel: ChatChannel): Promise> { let token = channel.LastChat ? channel.LastChat.LogId : Long.ZERO; let openToken; @@ -224,8 +261,10 @@ export class ChannelManager extends IdStore { let res = await this.client.NetworkManager.requestPacketRes(new PacketChatOnRoomReq(channel.Id, token, openToken)); - this.initUserInfoList(channel as ManagedChatChannel, res.MemberList, res.ClientOpenProfile); - + if (res.MemberList) { + this.updateUserInfoList(channel as ManagedChatChannel, res.MemberList, res.ClientOpenProfile); + } + return { status: res.StatusCode, result: res.StatusCode === StatusCode.SUCCESS }; } From d7a716ae64b88b797b47db4536742186631e677a Mon Sep 17 00:00:00 2001 From: storycraft Date: Thu, 3 Dec 2020 22:24:18 +0900 Subject: [PATCH 3/4] Do not request detailed user info --- src/talk/channel/channel-manager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/talk/channel/channel-manager.ts b/src/talk/channel/channel-manager.ts index d20eabbd..3117040f 100644 --- a/src/talk/channel/channel-manager.ts +++ b/src/talk/channel/channel-manager.ts @@ -93,7 +93,7 @@ export class ChannelManager extends IdStore { } - let memberList = await this.requestDetailedMemberList(channel.Id); + let memberList = await this.requestMemberList(channel.Id); if (memberList) { this.updateUserInfoList(channel, memberList); From cbabd6bf1767d242408f40330a4493ee5f7ed76e Mon Sep 17 00:00:00 2001 From: storycraft Date: Thu, 3 Dec 2020 22:34:01 +0900 Subject: [PATCH 4/4] Fixed #75. Update to 3.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index af6877a3..af4c0c06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-kakao", - "version": "3.1.2", + "version": "3.1.3", "description": "Loco protocol compatible library", "main": "dist/index.js", "scripts": {