Skip to content

Commit

Permalink
fix(core): init user info (#2499)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gggpound authored Jun 13, 2024
1 parent 4a72bcc commit b3393ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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

0 comments on commit b3393ef

Please sign in to comment.