Skip to content

Commit

Permalink
Add OriginalType property.
Browse files Browse the repository at this point in the history
Add FileChat wrapper.
Update to 3.1.10
  • Loading branch information
storycraft committed Feb 15, 2021
1 parent 6e4114f commit e45c742
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ src/
node_modules/
tests/
tsconfig.json
loco-test.ts
loco-test.ts
deno-test.ts
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.9",
"version": "3.1.10",
"description": "Loco protocol compatible library",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/talk/chat/chat-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class ChatManager {

const TypedChat = TypeMap.getChatConstructor(chatLog.type);

return new TypedChat(channel, sender, chatLog.messageId, chatLog.logId, chatLog.prevLogId, chatLog.sendTime, chatLog.text, chatLog.rawAttachment);
return new TypedChat(channel, sender, chatLog.messageId, chatLog.type, chatLog.logId, chatLog.prevLogId, chatLog.sendTime, chatLog.text, chatLog.rawAttachment);
}

async deleteChat(channelId: Long, logId: Long): Promise<RequestResult<boolean>> {
Expand Down
37 changes: 33 additions & 4 deletions src/talk/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChatType } from "./chat-type";
import { Long, EJSON } from "bson";
import { ChatChannel, OpenChatChannel } from "../channel/chat-channel";
import { ChatUser } from "../user/chat-user";
import { ChatAttachment, PhotoAttachment, MessageTemplate, MediaTemplates } from "../..";
import { ChatAttachment, PhotoAttachment, MessageTemplate, MediaTemplates, FileAttachment } from "../..";
import { EmoticonAttachment, LongTextAttachment, VideoAttachment, MentionContentList, ChatMention, MapAttachment, ReplyAttachment } from "./attachment/chat-attachment";
import { SharpAttachment } from "./attachment/sharp-attachment";
import { JsonUtil } from "../../util/json-util";
Expand All @@ -24,6 +24,8 @@ export abstract class Chat {
private prevLogId: Long;
private logId: Long;

private originalType: ChatType;

private channel: ChatChannel;
private sender: ChatUser;

Expand All @@ -38,10 +40,12 @@ export abstract class Chat {

private sendTime: number;

constructor(channel: ChatChannel, sender: ChatUser, messageId: number, logId: Long, prevLogId: Long, sendTime: number, text: string, rawAttachment: string = '{}') {
constructor(channel: ChatChannel, sender: ChatUser, originalType: ChatType, messageId: number, logId: Long, prevLogId: Long, sendTime: number, text: string, rawAttachment: string = '{}') {
this.channel = channel;
this.sender = sender;

this.originalType = originalType;

this.logId = logId;
this.prevLogId = prevLogId;

Expand All @@ -67,6 +71,10 @@ export abstract class Chat {
return this.prevLogId;
}

get OriginalType() {
return this.originalType;
}

get LogId() {
return this.logId;
}
Expand Down Expand Up @@ -388,6 +396,26 @@ export class VideoChat extends Chat {

}

export class FileChat extends Chat {

get Type() {
return ChatType.File;
}

get Map(): FileAttachment {
return this.AttachmentList[0] as FileAttachment;
}

protected readAttachment(attachmentJson: any, attachmentList: ChatAttachment[]) {
let attachment = new FileAttachment();

attachment.readAttachment(attachmentJson);

attachmentList.push(attachment);
}

}

export class SharpSearchChat extends Chat {

get Type() {
Expand Down Expand Up @@ -452,7 +480,7 @@ export class ReplyChat extends Chat {
attachmentList.push(replyAttachment);

if (attachmentJson['attach_type']) {
let contentChat = new (TypeMap.getChatConstructor(attachmentJson['attach_type']))(this.Channel, this.Sender, this.MessageId, this.LogId, this.PrevLogId, this.SendTime, this.Text, attachmentJson['attach_content']);
let contentChat = new (TypeMap.getChatConstructor(attachmentJson['attach_type']))(this.Channel, this.Sender, attachmentJson['attach_type'], this.MessageId, this.LogId, this.PrevLogId, this.SendTime, this.Text, attachmentJson['attach_content']);
attachmentList.push(...contentChat.AttachmentList);
}

Expand Down Expand Up @@ -483,7 +511,7 @@ export class CustomChat extends Chat {

export namespace TypeMap {

export type ChatConstructor = new (channel: ChatChannel, sender: ChatUser, messageId: number, logId: Long, prevLogId: Long, sendTime: number, text: string, rawAttachment: string | undefined) => Chat;
export type ChatConstructor = new (channel: ChatChannel, sender: ChatUser, originalType: ChatType, messageId: number, logId: Long, prevLogId: Long, sendTime: number, text: string, rawAttachment: string | undefined) => Chat;

let typeMap: Map<ChatType, ChatConstructor> = new Map();

Expand All @@ -501,6 +529,7 @@ export namespace TypeMap {
typeMap.set(ChatType.Text, TextChat);
typeMap.set(ChatType.Photo, SinglePhotoChat);
typeMap.set(ChatType.MultiPhoto, MultiPhotoChat);
typeMap.set(ChatType.File, FileChat);
typeMap.set(ChatType.Video, VideoChat);
typeMap.set(ChatType.Sticker, StaticEmoticonChat);
typeMap.set(ChatType.StickerAni, AnimatedEmoticonChat);
Expand Down

0 comments on commit e45c742

Please sign in to comment.