Skip to content

Commit 1aba0cb

Browse files
committed
Fix SYNCJOIN to work properly.
This fix is hacky so need to be fixed in future
1 parent 0880d0e commit 1aba0cb

File tree

4 files changed

+50
-24
lines changed

4 files changed

+50
-24
lines changed

src/talk/channel/talk-channel-handler.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from '../../chat';
2525
import { EventContext, TypedEmitter } from '../../event';
2626
import { ChannelEvents, ChannelListEvent } from '../event';
27-
import { ChgMetaRes, DecunreadRes, LeftRes, MsgRes, SyncJoinRes } from '../../packet/chat';
27+
import { ChgMetaRes, DecunreadRes, LeftRes, MsgRes } from '../../packet/chat';
2828
import { ChatlogStruct, structToChatlog } from '../../packet/struct';
2929
import { AsyncCommandResult, DefaultRes } from '../../request';
3030
import { ChannelUserInfo } from '../../user';
@@ -296,22 +296,6 @@ export class TalkChannelListHandler<T extends Channel> implements Managed<Channe
296296
break;
297297
}
298298

299-
// TODO: Move SYNCJOIN handling to TalkChannelList
300-
case 'SYNCJOIN': {
301-
const joinData = data as DefaultRes & SyncJoinRes;
302-
303-
const res = await this._updater.addChannel({ channelId: joinData.c });
304-
if (res.success) {
305-
this._callEvent(
306-
parentCtx,
307-
'channel_join',
308-
res.result as T,
309-
);
310-
}
311-
312-
break;
313-
}
314-
315299
default: break;
316300
}
317301
}

src/talk/channel/talk-normal-channel-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { TalkChannelManageSession } from './talk-channel-session';
2525
import { ClientDataLoader } from '../../loader';
2626
import { updateChatList } from './common';
2727

28-
type TalkNormalChannelListEvents = NormalChannelListEvents<TalkNormalChannel, NormalChannelUserInfo>;
28+
export type TalkNormalChannelListEvents = NormalChannelListEvents<TalkNormalChannel, NormalChannelUserInfo>;
2929

3030
/**
3131
* Manage session channels

src/talk/openlink/talk-open-channel-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { OpenChannelUserInfo } from '../../user';
3737
import { ClientDataLoader } from '../../loader';
3838
import { TalkClientLinkStore } from './client-link-store';
3939

40-
type TalkOpenChannelListEvents = OpenChannelListEvents<TalkOpenChannel, OpenChannelUserInfo>;
40+
export type TalkOpenChannelListEvents = OpenChannelListEvents<TalkOpenChannel, OpenChannelUserInfo>;
4141

4242
/**
4343
* Manage open profile, channel.

src/talk/talk-channel-list.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@
55
*/
66

77
import { Long } from 'bson';
8-
import { ChannelStore, LoginData, NormalChannelData } from '../channel';
8+
import { Channel, ChannelStore, LoginData, NormalChannelData } from '../channel';
99
import { TalkSession } from './client';
1010
import { EventContext, TypedEmitter } from '../event';
1111
import { InformedOpenLink, OpenChannelData } from '../openlink';
1212
import { DefaultRes } from '../request';
13-
import { ChainedIterator } from '../util';
13+
import { ChainedIterator, JsonUtil } from '../util';
1414
import { ChannelListEvents } from './event';
1515
import { Managed } from './managed';
16-
import { TalkOpenChannel, TalkOpenChannelList } from './openlink';
17-
import { ChannelListUpdater, TalkChannel, TalkNormalChannel, TalkNormalChannelList } from './channel';
16+
import { TalkOpenChannel, TalkOpenChannelList, TalkOpenChannelListEvents } from './openlink';
17+
import {
18+
ChannelListUpdater,
19+
TalkChannel,
20+
TalkNormalChannel,
21+
TalkNormalChannelList,
22+
TalkNormalChannelListEvents
23+
} from './channel';
1824
import { ChannelUserInfo } from '../user';
1925
import { ClientDataLoader } from '../loader';
20-
import { MsgRes } from '../packet/chat';
26+
import { MsgRes, SyncJoinRes } from '../packet/chat';
27+
import { structToChatlog } from '../packet/struct';
28+
import { KnownChatType, KnownFeedType } from '../chat';
2129

2230
type TalkChannelListEvents = ChannelListEvents<TalkChannel, ChannelUserInfo>;
2331

@@ -98,6 +106,40 @@ export class TalkChannelList
98106
ctx.emit('channel_added', res.result);
99107
}
100108
}
109+
} else if (method === 'SYNCJOIN') {
110+
const joinData = data as DefaultRes & SyncJoinRes;
111+
112+
if (joinData.chatLog) {
113+
const chat = structToChatlog(joinData.chatLog);
114+
115+
if (chat.type === KnownChatType.FEED && chat.text) {
116+
const content = JsonUtil.parseLoseless(chat.text);
117+
118+
const channel: Channel = { channelId: joinData.c };
119+
120+
if (content['feedType'] === KnownFeedType.OPENLINK_JOIN) {
121+
const openRes = await this._open.addChannel(channel);
122+
123+
if (openRes.success) {
124+
const childCtx = new EventContext<TalkOpenChannelListEvents>(this._open, ctx);
125+
childCtx.emit(
126+
'channel_join',
127+
openRes.result,
128+
);
129+
}
130+
} else {
131+
const normalRes = await this._normal.addChannel(channel);
132+
133+
if (normalRes.success) {
134+
const childCtx = new EventContext<TalkNormalChannelListEvents>(this._normal, ctx);
135+
childCtx.emit(
136+
'channel_join',
137+
normalRes.result,
138+
);
139+
}
140+
}
141+
}
142+
}
101143
}
102144

103145
await this._normal.pushReceived(method, data, ctx);

0 commit comments

Comments
 (0)