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 Mar 29, 2021
2 parents 1fa3b09 + bf5783e commit 51960f4
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 86 deletions.
141 changes: 106 additions & 35 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-kakao",
"version": "4.1.2",
"version": "4.1.3",
"description": "Loco protocol compatible library",
"main": "./dist/index.js",
"exports": {
Expand Down Expand Up @@ -43,7 +43,7 @@
},
"license": "MIT",
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.1.0",
"@rollup/plugin-typescript": "^8.2.0",
"@types/bson": "^4.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/packet/chat/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export interface MsgRes {
noSeen: boolean;

/**
* Sender nickname
* Sender nickname (Only openchat)
*/
authorNickname: string;
authorNickname?: string;

/**
* true if notification read(?)
* true if notification read(?) (Only openchat)
*/
notiRead: boolean;
notiRead?: boolean;

}
47 changes: 32 additions & 15 deletions src/talk/channel/talk-channel-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {
UpdatableChannelDataStore
} from '../../channel';
import {
ChatFeed,
DeleteAllFeed,
DELETED_MESSAGE_OFFSET,
FeedFragment,
feedFromChat,
KnownChatType,
KnownFeedType,
Expand Down Expand Up @@ -62,6 +64,13 @@ export class TalkChannelHandler<T extends Channel> implements Managed<TalkChanne

const chatLog = structToChatlog(msgData.chatLog);

if (msgData.authorNickname) {
const userInfo = this._store.getUserInfo(chatLog.sender);
if (userInfo && userInfo.nickname !== msgData.authorNickname) {
this._store.updateUserInfo(chatLog.sender, { nickname: msgData.authorNickname });
}
}

this._callEvent(
parentCtx,
'chat',
Expand Down Expand Up @@ -140,22 +149,30 @@ export class TalkChannelHandler<T extends Channel> implements Managed<TalkChanne
if (!this._channel.channelId.eq(struct.chatId)) return;

const chatLog = structToChatlog(struct);
const user = this._store.getUserInfo(chatLog.sender);
if (!user) return;

this._store.removeUser(chatLog.sender);

if (chatLog.type !== KnownChatType.FEED) return;
const feed = feedFromChat(chatLog);

this._callEvent(
parentCtx,
'user_left',
chatLog,
this._channel,
user,
feed,
);
// TODO: The event should be called whatever the chat is valid or not.
if (chatLog.type === KnownChatType.FEED) {
const feed = feedFromChat(chatLog);

if ('member' in feed) {
const memberFeed = feed as ChatFeed & FeedFragment.Member;

const user = this._store.getUserInfo(memberFeed.member);

if (user) {
this._store.removeUser(user);

this._callEvent(
parentCtx,
'user_left',
chatLog,
this._channel,
user,
feed,
);
}
}
}

this._chatListStore.addChat(chatLog).then();

Expand Down
Loading

0 comments on commit 51960f4

Please sign in to comment.