Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): init user info #2499

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/core/src/services/user-manager/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ const nameMap = {
[UnitRole.Reader]: 'Reader',
[UnitRole.UNRECOGNIZED]: 'UNRECOGNIZED',
};
export const createDefaultUser = (type: UnitRole) => {
export const createDefaultUser = (type?: UnitRole) => {
if (!type) {
return {
userID: '',
name: '',
avatar: '',
anonymous: true,
canBindAnonymous: false,
} as IUser;
}
const user = {
userID: `${nameMap[type]}_${Tools.generateRandomId(8)}`,
name: nameMap[type],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import type { IUser } from '@univerjs/protocol';
import { UnitRole } from '@univerjs/protocol';

import { BehaviorSubject, Subject } from 'rxjs';
import { LifecycleStages, OnLifecycle } from '../lifecycle/lifecycle';
Expand All @@ -26,7 +25,7 @@ export class UserManagerService {
private _model = new Map<string, IUser>();
private _userChange$ = new Subject<{ type: 'add' | 'delete'; user: IUser } | { type: 'clear' }>();
public userChange$ = this._userChange$.asObservable();
private _currentUser$ = new BehaviorSubject<IUser>(createDefaultUser(UnitRole.Owner));
private _currentUser$ = new BehaviorSubject<IUser>(createDefaultUser());
/**
* When the current user undergoes a switch or change
* @memberof UserManagerService
Expand Down
Loading