PromucFlow_constructor/app/client/src/sagas/WebsocketSagas/handleAppLevelSocketEvents.tsx

103 lines
3.3 KiB
TypeScript
Raw Normal View History

import { put, select } from "redux-saga/effects";
import { APP_LEVEL_SOCKET_EVENTS } from "./socketEvents";
2021-06-09 14:32:17 +00:00
import {
newCommentEvent,
newCommentThreadEvent,
updateCommentThreadEvent,
updateCommentEvent,
deleteCommentThreadEvent,
deleteCommentEvent,
2021-06-09 14:32:17 +00:00
} from "actions/commentActions";
import { collabSetAppEditors } from "actions/appCollabActions";
2021-06-09 14:32:17 +00:00
import { newNotificationEvent } from "actions/notificationActions";
import { getCurrentUser } from "selectors/usersSelectors";
import { Toaster } from "components/ads/Toast";
import {
createMessage,
INFO_VERSION_MISMATCH_FOUND_RELOAD_REQUEST,
} from "constants/messages";
import { Variant } from "components/ads/common";
import React from "react";
import { getAppsmithConfigs } from "@appsmith/configs";
2021-06-09 14:32:17 +00:00
export default function* handleAppLevelSocketEvents(event: any) {
const currentUser = yield select(getCurrentUser);
2021-06-09 14:32:17 +00:00
switch (event.type) {
// comments
case APP_LEVEL_SOCKET_EVENTS.INSERT_COMMENT_THREAD: {
const { thread } = event.payload[0];
const isThreadFromEventViewed = thread?.viewedByUsers?.includes(
currentUser?.username,
);
yield put(
newCommentThreadEvent({
...thread,
// This is necessary to be done from the start, as client depends on
// these values to find if there is an unread thread.
isViewed: isThreadFromEventViewed || thread?.resolvedState?.active,
}),
);
2021-06-09 14:32:17 +00:00
return;
}
case APP_LEVEL_SOCKET_EVENTS.INSERT_COMMENT: {
2021-06-09 14:32:17 +00:00
yield put(newCommentEvent(event.payload[0]));
return;
}
case APP_LEVEL_SOCKET_EVENTS.REPLACE_COMMENT_THREAD:
case APP_LEVEL_SOCKET_EVENTS.UPDATE_COMMENT_THREAD: {
2021-07-28 07:02:11 +00:00
const { thread } = event.payload[0];
2021-07-28 07:02:11 +00:00
const isThreadFromEventViewed = thread?.viewedByUsers?.includes(
currentUser?.username,
);
yield put(
updateCommentThreadEvent({
...thread,
isViewed: isThreadFromEventViewed || thread?.resolvedState?.active, // resolved threads can't be unread
2021-07-28 07:02:11 +00:00
}),
);
2021-06-09 14:32:17 +00:00
return;
}
case APP_LEVEL_SOCKET_EVENTS.UPDATE_COMMENT: {
2021-06-09 14:32:17 +00:00
yield put(updateCommentEvent(event.payload[0].comment));
return;
}
case APP_LEVEL_SOCKET_EVENTS.DELETE_COMMENT_THREAD: {
yield put(deleteCommentThreadEvent(event.payload[0].thread));
return;
}
case APP_LEVEL_SOCKET_EVENTS.DELETE_COMMENT: {
yield put(deleteCommentEvent(event.payload[0].comment));
return;
}
2021-06-09 14:32:17 +00:00
// notifications
case APP_LEVEL_SOCKET_EVENTS.INSERT_NOTIFICATION: {
2021-06-09 14:32:17 +00:00
yield put(newNotificationEvent(event.payload[0].notification));
return;
}
// Collab V2 - Realtime Editing
case APP_LEVEL_SOCKET_EVENTS.LIST_ONLINE_APP_EDITORS: {
yield put(collabSetAppEditors(event.payload[0]));
return;
}
// notification on release version
case APP_LEVEL_SOCKET_EVENTS.RELEASE_VERSION_NOTIFICATION: {
const { appVersion } = getAppsmithConfigs();
if (appVersion.id != event.payload[0]) {
Toaster.show({
text: createMessage(INFO_VERSION_MISMATCH_FOUND_RELOAD_REQUEST),
variant: Variant.info,
actionElement: (
<span onClick={() => location.reload(true)}>REFRESH</span>
),
autoClose: false,
});
}
return;
}
2021-06-09 14:32:17 +00:00
}
}