Skip to content

Commit

Permalink
Merge branch 'dev' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
storycraft committed Dec 3, 2020
2 parents b62ee68 + cbabd6b commit 0572fac
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
8 changes: 8 additions & 0 deletions src/api/service-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export class ServiceClient extends SessionApiClient {

// profile

async requestMusicList(id: Long): Promise<WebApiStruct> {
return this.request('GET', ServiceClient.getProfileApiPath(this.Agent, 'music/list.json'), { id: id.toString() });
}

async requestMyProfile(): Promise<ProfileReqStruct> {
return this.request('GET', ServiceClient.getProfile3ApiPath(this.Agent, 'me.json'));
}
Expand All @@ -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}`;
}
Expand Down
7 changes: 6 additions & 1 deletion src/packet/packet-chat-on-room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -73,6 +74,10 @@ export class PacketChatOnRoomRes extends LocoBsonResponsePacket {
}
}

if (rawData['mi']) {
this.MemberIdList = rawData['mi'];
}

if (rawData['olu']) this.ClientOpenProfile = Serializer.deserialize<OpenLinkMemberStruct>(rawData['olu'], OpenLinkMemberStruct.MAPPER);
}

Expand Down
12 changes: 6 additions & 6 deletions src/packet/packet-rewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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) {
Expand Down
45 changes: 42 additions & 3 deletions src/talk/channel/channel-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatChannel> {

Expand Down Expand Up @@ -91,7 +93,14 @@ export class ChannelManager extends IdStore<ChatChannel> {

}

let memberList = await this.requestMemberList(channel.Id);

if (memberList) {
this.updateUserInfoList(channel, memberList);
}

await this.sendChatOn(channel);

this.set(id, channel);

return channel;
Expand Down Expand Up @@ -122,7 +131,7 @@ export class ChannelManager extends IdStore<ChatChannel> {
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;

Expand Down Expand Up @@ -217,15 +226,45 @@ export class ChannelManager extends IdStore<ChatChannel> {
}
}

protected async requestMemberList(channelId: Long): Promise<(MemberStruct | OpenMemberStruct)[] | null> {
let res = await this.client.NetworkManager.requestPacketRes<PacketGetMemberRes>(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<PacketMemberRes>(new PacketMemberReq(channelId, memberIdList));

if (res.StatusCode === StatusCode.SUCCESS) {
return res.MemberList!;
} else {
return null;
}
}

async sendChatOn(channel: ChatChannel): Promise<RequestResult<boolean>> {
let token = channel.LastChat ? channel.LastChat.LogId : Long.ZERO;
let openToken;
if (channel.isOpenChat()) openToken = (channel as OpenChatChannel).OpenToken;

let res = await this.client.NetworkManager.requestPacketRes<PacketChatOnRoomRes>(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 };
}

Expand Down

0 comments on commit 0572fac

Please sign in to comment.