diff --git a/.npmignore b/.npmignore index a01ac6db..afb05579 100644 --- a/.npmignore +++ b/.npmignore @@ -2,4 +2,5 @@ src/ node_modules/ tests/ tsconfig.json -loco-test.ts \ No newline at end of file +loco-test.ts +deno-test.ts \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 953ddb55..451fd2c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "node-kakao", - "version": "3.1.9", + "version": "3.1.10", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f4d9eeca..681bf9d3 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/talk/chat/chat-manager.ts b/src/talk/chat/chat-manager.ts index 4ee0f6ab..62adcc51 100644 --- a/src/talk/chat/chat-manager.ts +++ b/src/talk/chat/chat-manager.ts @@ -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> { diff --git a/src/talk/chat/chat.ts b/src/talk/chat/chat.ts index d19c6ee5..cc74c86c 100644 --- a/src/talk/chat/chat.ts +++ b/src/talk/chat/chat.ts @@ -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"; @@ -24,6 +24,8 @@ export abstract class Chat { private prevLogId: Long; private logId: Long; + private originalType: ChatType; + private channel: ChatChannel; private sender: ChatUser; @@ -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; @@ -67,6 +71,10 @@ export abstract class Chat { return this.prevLogId; } + get OriginalType() { + return this.originalType; + } + get LogId() { return this.logId; } @@ -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() { @@ -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); } @@ -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 = new Map(); @@ -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);