ChatroomsService constructor
Implementation
ChatroomsService(this.core, this._config, this._profile) : log = core.moduleLog('chatrooms') {
core.onDirect('chatroom.batch', (frame) => _handles[asString(frame.data['room_id']) ?? '']?.applyBatch(frame.data));
core.onDirect('chatroom.removed', (frame) {
final roomId = asString(frame.data['room_id']) ?? '';
_joined.remove(roomId);
_handles[roomId]?.applyRemoved(frame.data);
});
core.onDirect('chatroom.resync', (frame) {
for (final id in asList(frame.data['room_ids']) ?? const []) {
if (id is String) _resync(id);
}
});
core.onDirect('sync.required', (_) {
for (final id in [..._joined]) {
_resync(id);
}
});
// 新的连接:重新进入(重连后服务端已不认这条连接上的聊天室)
core.onConnected((_) {
_joined.clear();
for (final handle in [..._handles.values]) {
handle.rejoin();
}
});
}