|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | import { Long } from 'bson';
|
8 |
| -import { ChannelStore, LoginData, NormalChannelData } from '../channel'; |
| 8 | +import { Channel, ChannelStore, LoginData, NormalChannelData } from '../channel'; |
9 | 9 | import { TalkSession } from './client';
|
10 | 10 | import { EventContext, TypedEmitter } from '../event';
|
11 | 11 | import { InformedOpenLink, OpenChannelData } from '../openlink';
|
12 | 12 | import { DefaultRes } from '../request';
|
13 |
| -import { ChainedIterator } from '../util'; |
| 13 | +import { ChainedIterator, JsonUtil } from '../util'; |
14 | 14 | import { ChannelListEvents } from './event';
|
15 | 15 | 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'; |
18 | 24 | import { ChannelUserInfo } from '../user';
|
19 | 25 | 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'; |
21 | 29 |
|
22 | 30 | type TalkChannelListEvents = ChannelListEvents<TalkChannel, ChannelUserInfo>;
|
23 | 31 |
|
@@ -98,6 +106,40 @@ export class TalkChannelList
|
98 | 106 | ctx.emit('channel_added', res.result);
|
99 | 107 | }
|
100 | 108 | }
|
| 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 | + } |
101 | 143 | }
|
102 | 144 |
|
103 | 145 | await this._normal.pushReceived(method, data, ctx);
|
|
0 commit comments