Skip to content

Commit e64a040

Browse files
committed
Move ChannelMetaType to channel module.
Declare contact, profile, map, voip attachments. Separating text, attachment and content methods in ChatBuilder.
1 parent f768878 commit e64a040

File tree

15 files changed

+241
-53
lines changed

15 files changed

+241
-53
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-kakao",
3-
"version": "4.0.0-beta.3",
3+
"version": "4.0.0-beta.4",
44
"description": "Loco protocol compatible library",
55
"main": "./dist/index.js",
66
"exports": {

src/channel/meta.ts

+37-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,26 @@
55
*/
66

77
import { Long } from 'bson';
8-
import { ChannelMetaType } from '../packet/struct';
8+
9+
export enum KnownChannelMetaType {
10+
11+
UNDEFINED = 0,
12+
NOTICE = 1,
13+
GROUP = 2,
14+
TITLE = 3,
15+
PROFILE = 4,
16+
TV = 5,
17+
PRIVILEGE = 6,
18+
TV_LIVE = 7,
19+
PLUS_BACKGROUND = 8,
20+
LIVE_TALK_INFO = 11,
21+
LIVE_TALK_COUNT = 12,
22+
OPEN_CHANNEL_CHAT = 13,
23+
BOT = 14,
24+
25+
}
26+
27+
export type ChannelMetaType = KnownChannelMetaType | number;
928

1029
export enum ChannelClientMetaType {
1130

@@ -78,6 +97,23 @@ export interface TvLiveMetaContent {
7897

7998
}
8099

100+
export interface LiveTalkInfoOnMetaContent {
101+
liveon: boolean;
102+
title: string;
103+
startTime: number;
104+
userId: number | Long;
105+
csIP: string;
106+
csIP6: string;
107+
csPort: number;
108+
callId: string;
109+
}
110+
111+
export interface LiveTalkInfoOffMetaContent extends Partial<LiveTalkInfoOnMetaContent> {
112+
liveon: false;
113+
}
114+
115+
export type LiveTalkInfoMetaContent = LiveTalkInfoOnMetaContent | LiveTalkInfoOffMetaContent;
116+
81117
export interface LiveTalkCountMetaContent {
82118

83119
count: number;

src/chat/attachment/contact.ts

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Created on Fri Feb 12 2021
3+
*
4+
* Copyright (c) storycraft. Licensed under the MIT Licence.
5+
*/
6+
7+
import { Long } from 'bson';
8+
9+
/**
10+
* KakaoTalk profile attachment
11+
*/
12+
export interface ProfileAttachment {
13+
14+
/**
15+
* Profile user id
16+
*/
17+
userId: number | Long;
18+
19+
/**
20+
* User nickname
21+
*/
22+
nickName: string;
23+
24+
/**
25+
* User main profile (full)
26+
*/
27+
fullProfileImageUrl: string;
28+
29+
/**
30+
* User profile
31+
*/
32+
profileImageUrl: string;
33+
34+
/**
35+
* Profile status message
36+
*/
37+
statusMessage: string;
38+
39+
}
40+
41+
/**
42+
* Call Contact attachment
43+
*/
44+
export interface ContactAttachment {
45+
46+
/**
47+
* Contact name
48+
*/
49+
name: string;
50+
51+
/**
52+
* vcf contact file url
53+
*/
54+
url: string;
55+
56+
}

src/chat/attachment/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ export * from './reply';
88
export * from './mention';
99
export * from './media';
1010
export * from './emoticon';
11+
export * from './voip';
12+
export * from './contact';
13+
export * from './map';

src/chat/attachment/map.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Created on Fri Feb 12 2021
3+
*
4+
* Copyright (c) storycraft. Licensed under the MIT Licence.
5+
*/
6+
7+
export interface MapAttachment {
8+
9+
/**
10+
* Latitude (multiplied by 10000000000)
11+
*/
12+
lat: number;
13+
14+
/**
15+
* Longitude (multiplied by 10000000000)
16+
*/
17+
lng: number;
18+
19+
/**
20+
* Map address
21+
*/
22+
a: string;
23+
24+
/**
25+
* true if using kakao map
26+
*/
27+
c: boolean;
28+
29+
}

src/chat/attachment/voip.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Created on Fri Feb 12 2021
3+
*
4+
* Copyright (c) storycraft. Licensed under the MIT Licence.
5+
*/
6+
7+
import { VoipType } from '../../voip';
8+
9+
/**
10+
* Voip attachment
11+
*/
12+
export interface VoipAttachment {
13+
14+
/**
15+
* Call type
16+
*/
17+
type: VoipType;
18+
19+
/**
20+
* Call server ip
21+
*/
22+
csIP: string;
23+
24+
/**
25+
* Call server ip (ipv6)
26+
*/
27+
csIP6: string;
28+
29+
/**
30+
* Call server port
31+
*/
32+
csPort: number;
33+
34+
/**
35+
* Call id
36+
*/
37+
callId: string;
38+
39+
/**
40+
* Supplied when the call is live talk
41+
*/
42+
title?: string;
43+
44+
/**
45+
* Call start time.
46+
* Supplied when the call is live talk.
47+
*/
48+
startTime?: number;
49+
50+
/**
51+
* Call duration
52+
*/
53+
duration: number;
54+
}

src/chat/chat-builder.ts

+18-21
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@
66

77
import { Chat } from './chat';
88
import { ChatType } from './chat-type';
9-
import { AttachmentContent, ChatContent } from './content';
9+
import { AttachmentContent, ChatContent, TextContent } from './content';
1010

1111
/**
1212
* Build Chat object from existing chat or create new.
1313
*/
1414
export class ChatBuilder {
15-
private _contents: (string | ChatContent)[];
16-
17-
/**
18-
* Set chat options (shout, inapp)
19-
* This can be overridden by ChatContents.
20-
*/
21-
public options: Record<string, unknown>;
15+
private _contents: ChatContent[];
2216

2317
constructor() {
2418
this._contents = [];
25-
this.options = {};
19+
}
20+
21+
/**
22+
* Append text.
23+
* this is equivalent of calling builder.append(new TextContent(text));
24+
*
25+
* @param {string} text
26+
* @return {this}
27+
*/
28+
text(text: string): this {
29+
return this.append(new TextContent(text));
2630
}
2731

2832
/**
@@ -37,12 +41,12 @@ export class ChatBuilder {
3741
}
3842

3943
/**
40-
* Append text or chat content.
44+
* Append chat content.
4145
*
42-
* @param {string | ChatContent} content
46+
* @param {ChatContent} content
4347
* @return {this}
4448
*/
45-
append(content: string | ChatContent): this {
49+
append(content: ChatContent): this {
4650
this._contents.push(content);
4751
return this;
4852
}
@@ -55,8 +59,7 @@ export class ChatBuilder {
5559
* @return {this}
5660
*/
5761
shout(flag: boolean): this {
58-
this.options['shout'] = flag;
59-
return this;
62+
return this.attachment({ shout: flag });
6063
}
6164

6265
/**
@@ -81,14 +84,8 @@ export class ChatBuilder {
8184

8285
if (!chat.attachment) chat.attachment = {};
8386

84-
chat.attachment = Object.assign(chat.attachment, this.options);
85-
8687
for (const content of this._contents) {
87-
if (typeof content === 'string') {
88-
chat.text += content;
89-
} else {
90-
content.append(chat);
91-
}
88+
content.append(chat);
9289
}
9390

9491
return chat;

src/chat/content/attachment.ts renamed to src/chat/content/default.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,20 @@
55
*/
66

77
import { Chat } from '../chat';
8-
import { ChatContent } from '../content';
8+
import { ChatContent } from '.';
9+
10+
/**
11+
* Append text
12+
*/
13+
export class TextContent implements ChatContent {
14+
constructor(public text: string) {
15+
16+
}
17+
18+
append(chat: Chat): void {
19+
chat.text += this.text;
20+
}
21+
}
922

1023
/**
1124
* Append attachment

src/chat/content/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) storycraft. Licensed under the MIT Licence.
55
*/
66

7-
export * from './attachment';
7+
export * from './default';
88
export * from './mention';
99
export * from './reply';
1010

@@ -19,4 +19,4 @@ export interface ChatContent {
1919
*/
2020
append(chat: Chat): void;
2121

22-
}
22+
}

src/packet/struct/channel.ts

+1-20
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,9 @@
66

77
import { Long } from 'bson';
88
import { ChannelType } from '../../channel';
9+
import { ChannelMetaType } from '../../channel/meta';
910
import { ChatlogStruct } from './chat';
1011

11-
export enum KnownChannelMetaType {
12-
13-
UNDEFINED = 0,
14-
NOTICE = 1,
15-
GROUP = 2,
16-
TITLE = 3,
17-
PROFILE = 4,
18-
TV = 5,
19-
PRIVILEGE = 6,
20-
TV_LIVE = 7,
21-
PLUS_BACKGROUND = 8,
22-
LIVE_TALK_INFO = 11,
23-
LIVE_TALK_COUNT = 12,
24-
OPEN_CHANNEL_CHAT = 13,
25-
BOT = 14,
26-
27-
}
28-
29-
export type ChannelMetaType = KnownChannelMetaType | number;
30-
3112
export interface ChannelMetaStruct {
3213

3314
type: ChannelMetaType;

src/talk/channel/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ChannelEvents } from '../event';
1818
import {
1919
GroupMetaContent,
2020
LiveTalkCountMetaContent,
21+
LiveTalkInfoMetaContent,
2122
ProfileMetaContent,
2223
TvLiveMetaContent,
2324
TvMetaContent,
@@ -131,6 +132,13 @@ export interface TalkChannel extends Channel, ChannelSession, TypedEmitter<Chann
131132
*/
132133
setLiveTalkCountMeta(content: LiveTalkCountMetaContent): AsyncCommandResult;
133134

135+
/**
136+
* Set live talk info meta
137+
*
138+
* @param content
139+
*/
140+
setLiveTalkInfoMeta(content: LiveTalkInfoMetaContent): AsyncCommandResult;
141+
134142
/**
135143
* Set group profile meta
136144
*

src/talk/channel/talk-channel-session.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import {
3535
} from '../../packet/chat';
3636
import {
3737
ChannelInfoStruct,
38-
ChannelMetaType,
3938
NormalChannelInfoExtra,
4039
NormalMemberStruct,
4140
structToChannelUserInfo,
@@ -50,6 +49,7 @@ import { LocoSecureLayer } from '../../network';
5049
import { newCryptoStore } from '../../crypto';
5150
import { MediaUploadTemplate } from '../media/upload';
5251
import { sha1 } from 'hash-wasm';
52+
import { ChannelMetaType } from '../../channel/meta';
5353

5454
/**
5555
* Default ChannelSession implementation

0 commit comments

Comments
 (0)