Skip to content

Commit a777d05

Browse files
committed
fix side chat for sagews -- was broken for sagews due to some last minute dev
1 parent 6880308 commit a777d05

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { history_path } from "@cocalc/util/misc";
5454
import { initFromSyncDB, handleSyncDBChange, processSyncDBObj } from "./sync";
5555
import { getReplyToRoot, getThreadRootDate, toMsString } from "./utils";
5656
import Fragment from "@cocalc/frontend/misc/fragment-id";
57+
import type { Actions as CodeEditorActions } from "@cocalc/frontend/frame-editors/code-editor/actions";
5758

5859
const MAX_CHATSTREAM = 10;
5960

@@ -66,7 +67,8 @@ export class ChatActions extends Actions<ChatState> {
6667
// this prevents that at least.
6768
private chatStreams: Set<string> = new Set([]);
6869
public frameId: string = "";
69-
public frameTreeActions;
70+
// this might not be set e.g., for deprecated side chat on sagews:
71+
public frameTreeActions?: CodeEditorActions;
7072

7173
set_syncdb = (syncdb: SyncDB, store: ChatStore): void => {
7274
this.syncdb = syncdb;
@@ -499,7 +501,7 @@ export class ChatActions extends Actions<ChatState> {
499501
// that starts with that date.
500502
// safe to call after closing actions.
501503
clearScrollRequest = () => {
502-
this.frameTreeActions.set_frame_data({
504+
this.frameTreeActions?.set_frame_data({
503505
id: this.frameId,
504506
scrollToIndex: null,
505507
scrollToDate: null,
@@ -513,7 +515,7 @@ export class ChatActions extends Actions<ChatState> {
513515
// to virtuoso and directly control things from here.
514516
this.clearScrollRequest();
515517
setTimeout(() => {
516-
this.frameTreeActions.set_frame_data({
518+
this.frameTreeActions?.set_frame_data({
517519
id: this.frameId,
518520
scrollToIndex: index,
519521
scrollToDate: null,
@@ -527,12 +529,12 @@ export class ChatActions extends Actions<ChatState> {
527529

528530
scrollToDate = (date) => {
529531
this.clearScrollRequest();
530-
this.frameTreeActions.set_frame_data({
532+
this.frameTreeActions?.set_frame_data({
531533
id: this.frameId,
532534
fragmentId: toMsString(date),
533535
});
534536
setTimeout(() => {
535-
this.frameTreeActions.set_frame_data({
537+
this.frameTreeActions?.set_frame_data({
536538
id: this.frameId,
537539
// string version of ms since epoch, which is the key
538540
// in the messages immutable Map
@@ -583,7 +585,7 @@ export class ChatActions extends Actions<ChatState> {
583585
};
584586

585587
setHashtagState = (tag: string, state?: HashtagState): void => {
586-
if (!this.store) return;
588+
if (!this.store || this.frameTreeActions == null) return;
587589
// similar code in task list.
588590
let selectedHashtags: SelectedHashtags =
589591
this.frameTreeActions._get_frame_data(this.frameId, "selectedHashtags") ??
@@ -1095,15 +1097,15 @@ export class ChatActions extends Actions<ChatState> {
10951097
};
10961098

10971099
setSearch = (search) => {
1098-
this.frameTreeActions.set_frame_data({ id: this.frameId, search });
1100+
this.frameTreeActions?.set_frame_data({ id: this.frameId, search });
10991101
};
11001102

11011103
setFilterRecentH = (filterRecentH) => {
1102-
this.frameTreeActions.set_frame_data({ id: this.frameId, filterRecentH });
1104+
this.frameTreeActions?.set_frame_data({ id: this.frameId, filterRecentH });
11031105
};
11041106

11051107
setSelectedHashtags = (selectedHashtags) => {
1106-
this.frameTreeActions.set_frame_data({
1108+
this.frameTreeActions?.set_frame_data({
11071109
id: this.frameId,
11081110
selectedHashtags,
11091111
});
@@ -1115,7 +1117,7 @@ export class ChatActions extends Actions<ChatState> {
11151117
} else {
11161118
const fragmentId = toMsString(date);
11171119
Fragment.set({ chat: fragmentId });
1118-
this.frameTreeActions.set_frame_data({ id: this.frameId, fragmentId });
1120+
this.frameTreeActions?.set_frame_data({ id: this.frameId, fragmentId });
11191121
}
11201122
};
11211123
}

src/packages/frontend/chat/chatroom.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ interface Props {
7070
path: string;
7171
is_visible?: boolean;
7272
font_size: number;
73-
desc;
73+
desc?;
7474
}
7575

7676
export function ChatRoom({
@@ -87,12 +87,12 @@ export function ChatRoom({
8787
const input: string = useEditor("input");
8888
const [preview] = useDebounce(input, 250);
8989

90-
const search = desc.get("data-search") ?? "";
91-
const filterRecentH: number = desc.get("data-filterRecentH") ?? 0;
92-
const selectedHashtags = desc.get("data-selectedHashtags");
93-
const scrollToIndex = desc.get("data-scrollToIndex") ?? null;
94-
const scrollToDate = desc.get("data-scrollToDate") ?? null;
95-
const fragmentId = desc.get("data-fragmentId") ?? null;
90+
const search = desc?.get("data-search") ?? "";
91+
const filterRecentH: number = desc?.get("data-filterRecentH") ?? 0;
92+
const selectedHashtags = desc?.get("data-selectedHashtags");
93+
const scrollToIndex = desc?.get("data-scrollToIndex") ?? null;
94+
const scrollToDate = desc?.get("data-scrollToDate") ?? null;
95+
const fragmentId = desc?.get("data-fragmentId") ?? null;
9696

9797
const messages = useEditor("messages");
9898
const [filterRecentHCustom, setFilterRecentHCustom] = useState<string>("");

src/packages/frontend/chat/side-chat.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export default function SideChat({
4848
const input: string = useRedux(["input"], project_id, path);
4949
const search = desc?.get("data-search") ?? "";
5050
const selectedHashtags = desc?.get("data-selectedHashtags");
51-
const scrollToIndex = desc.get("data-scrollToIndex") ?? null;
52-
const scrollToDate = desc.get("data-scrollToDate") ?? null;
53-
const fragmentId = desc.get("data-fragmentId") ?? null;
51+
const scrollToIndex = desc?.get("data-scrollToIndex") ?? null;
52+
const scrollToDate = desc?.get("data-scrollToDate") ?? null;
53+
const fragmentId = desc?.get("data-fragmentId") ?? null;
5454
const addCollab: boolean = useRedux(["add_collab"], project_id, path);
5555
const is_uploading = useRedux(["is_uploading"], project_id, path);
5656
const project_map = useTypedRedux("projects", "project_map");

src/packages/frontend/chat/video/launch-button.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ export default function VideoChatButton({
2929
const [counter, set_counter] = useState<number>(0); // to force updates periodically.
3030
useInterval(() => set_counter(counter + 1), VIDEO_UPDATE_INTERVAL_MS / 2);
3131
const videoChat = useMemo(
32-
() => actions.frameTreeActions.getVideoChat(),
32+
() => actions.frameTreeActions?.getVideoChat(),
3333
[actions],
3434
);
3535

36+
if (videoChat == null) {
37+
// eg sage worksheets...
38+
return null;
39+
}
40+
3641
const click_video_button = debounce(
3742
() => {
3843
if (videoChat.weAreChatting()) {
@@ -60,14 +65,14 @@ export default function VideoChatButton({
6065
<hr />
6166
There following {num_users_chatting} people are using video chat:
6267
<br />
63-
{videoChat.getUserNames().join(", ")}
68+
{videoChat?.getUserNames().join(", ")}
6469
</span>
6570
);
6671
}
6772
}
6873

6974
function render_join(num_users_chatting: number): JSX.Element {
70-
if (videoChat.weAreChatting()) {
75+
if (videoChat?.weAreChatting()) {
7176
return (
7277
<span>
7378
<b>Leave</b> this video chatroom.
@@ -91,7 +96,7 @@ export default function VideoChatButton({
9196
}
9297
}
9398

94-
const num_users_chatting: number = videoChat.numUsersChatting() ?? 0;
99+
const num_users_chatting: number = videoChat?.numUsersChatting() ?? 0;
95100
const style: React.CSSProperties = { cursor: "pointer" };
96101
if (num_users_chatting > 0) {
97102
style.color = "#c9302c";

src/packages/frontend/frame-editors/chat-editor/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class Actions extends CodeEditorActions<ChatEditorState> {
7676
// our store is not exactly a ChatStore but it's close enough
7777
actions.set_syncdb(syncdb, this.store as ChatStore);
7878
actions.frameId = frameId;
79-
actions.frameTreeActions = this;
79+
actions.frameTreeActions = this as any;
8080
this.chatActions[frameId] = actions;
8181
return actions;
8282
}

src/packages/util/smc-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* autogenerated by the update_version script */
2-
exports.version=1727734946;
2+
exports.version=1728224335;

0 commit comments

Comments
 (0)