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

refactor(flat-stores): make admin message never dismiss #2101

Merged
merged 5 commits into from
Jan 16, 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
1 change: 1 addition & 0 deletions packages/flat-i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"student-left-temporarily": "Student has left",
"user-left-temporarily": "has left",
"the-room-has-ended-and-is-about-to-exit": "The room has ended and is about to exit...",
"the-room-is-about-to-end": "The room is about to reach {{roomType}} duration limit and will end at {{expireAt}} ({{minutes}} minutes left)",
"you-have-entered-the-room-at-another-device": "You have entered the room at another device",
"class-picker-text": {
"BigClass": "Large number of students",
Expand Down
1 change: 1 addition & 0 deletions packages/flat-i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"current-status": "当前状态:",
"current-mode": "当前模式:",
"the-room-has-ended-and-is-about-to-exit": "房间已结束,即将退出...",
"the-room-is-about-to-end": "房间即将到达{{roomType}}时长上限,将于 {{expireAt}} ({{minutes}} 分钟后) 结束",
"you-have-entered-the-room-at-another-device": "你已在另外一台设备进入房间",
"teacher-left-temporarily": "老师暂时离开",
"student-left-temporarily": "学生暂时离开",
Expand Down
5 changes: 5 additions & 0 deletions packages/flat-server-api/src/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ export interface JoinRoomResult {
rtmToken: string;
showGuide: boolean;
region: Region;
billing?: {
expireAt: string;
maxUser: number;
vipLevel: number; // 0 = normal, 1 = pro
};
}

export function joinRoom(uuid: string): Promise<JoinRoomResult> {
Expand Down
47 changes: 45 additions & 2 deletions packages/flat-stores/src/classroom-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
IServiceWhiteboard,
} from "@netless/flat-services";
import { preferencesStore } from "../preferences-store";
import { sampleSize } from "lodash-es";
import { noop, sampleSize } from "lodash-es";
import { format } from "date-fns";

export * from "./constants";
export * from "./chat-store";
Expand Down Expand Up @@ -218,10 +219,14 @@ export class ClassroomStore {

this.sideEffect.addDisposer(
this.rtm.events.on("admin-message", ({ text }) => {
void message.info(text);
this.handleAdminMessage(text);
}),
);

this.sideEffect.addDisposer(() => {
this.hideLastAdminMessage();
});

if (!this.isCreator) {
this.sideEffect.addDisposer(
this.rtm.events.on("update-room-status", event => {
Expand Down Expand Up @@ -1470,4 +1475,42 @@ export class ClassroomStore {
});
}
}

private hideLastAdminMessage: () => void = noop;

private handleAdminMessage(text: string): void {
this.hideLastAdminMessage();

if (text && text[0] === "{") {
try {
const data = JSON.parse(text);
if (data && typeof data === "object") {
const msg = data as {
roomLevel: 0 | 1;
expireAt: string;
leftMinutes: number;
message: string;
};
// TODO: roomType = derive from msg.roomLevel
const roomType = FlatI18n.getInstance().language === "zh-CN" ? "" : "its";
const expireAt = format(new Date(msg.expireAt), "HH:mm");
const minutes = msg.leftMinutes;
const info = FlatI18n.t("the-room-is-about-to-end", {
roomType,
expireAt,
minutes,
});
this.hideLastAdminMessage = message.info(info, 0);
return;
}
} catch (error) {
console.warn(error);
// fallback to normal message
}
}

if (text) {
this.hideLastAdminMessage = message.info(text, 0);
}
}
}
2 changes: 1 addition & 1 deletion packages/flat-stores/src/global-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class GlobalStore {
}

public get pmiRoomUUID(): string {
return (this.pmiRoomList && this.pmiRoomList[0]?.roomUUID) || "";
return (this.pmiRoomExist && this.pmiRoomList![0]?.roomUUID) || "";
}

public get userUUID(): string | undefined {
Expand Down