feat: server update message in SSE
This commit is contained in:
+27
-26
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vocechat-web",
|
||||
"version": "0.4.6",
|
||||
"version": "0.4.9",
|
||||
"homepage": "https://voce.chat",
|
||||
"dependencies": {
|
||||
"@emoji-mart/react": "^1.1.1",
|
||||
@@ -13,31 +13,31 @@
|
||||
"@toast-ui/editor": "^3.2.2",
|
||||
"@toast-ui/editor-plugin-code-syntax-highlight": "^3.1.0",
|
||||
"@toast-ui/react-editor": "^3.2.3",
|
||||
"@types/node": "^20.2.5",
|
||||
"@types/react": "^18.2.7",
|
||||
"@types/react-dom": "^18.2.4",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/react": "^18.2.12",
|
||||
"@types/react-dom": "^18.2.5",
|
||||
"@udecode/plate": "16.8",
|
||||
"@uiball/loaders": "^1.2.6",
|
||||
"@uiball/loaders": "^1.3.0",
|
||||
"agora-rtc-sdk-ng": "^4.17.2",
|
||||
"bfj": "^7.0.2",
|
||||
"broadcast-channel": "^5.1.0",
|
||||
"browserslist": "^4.21.7",
|
||||
"browserslist": "^4.21.8",
|
||||
"clsx": "^1.2.1",
|
||||
"copy-image-clipboard": "^2.1.2",
|
||||
"css-loader": "^6.8.1",
|
||||
"css-minimizer-webpack-plugin": "^5.0.0",
|
||||
"dayjs": "^1.11.7",
|
||||
"dotenv": "^16.1.3",
|
||||
"css-minimizer-webpack-plugin": "^5.0.1",
|
||||
"dayjs": "^1.11.8",
|
||||
"dotenv": "^16.1.4",
|
||||
"dotenv-expand": "^10.0.0",
|
||||
"emoji-mart": "5.5.2",
|
||||
"eslint": "^8.41.0",
|
||||
"eslint": "^8.42.0",
|
||||
"file-loader": "^6.2.0",
|
||||
"firebase": "^9.22.1",
|
||||
"firebase": "^9.22.2",
|
||||
"framer-motion": "^10.12.16",
|
||||
"fs-extra": "^11.1.1",
|
||||
"heic2any": "^0.0.4",
|
||||
"html-webpack-plugin": "^5.5.1",
|
||||
"i18next": "^22.5.0",
|
||||
"html-webpack-plugin": "^5.5.3",
|
||||
"i18next": "^22.5.1",
|
||||
"i18next-browser-languagedetector": "^7.0.2",
|
||||
"i18next-http-backend": "^2.2.1",
|
||||
"linkify-plugin-mention": "^4.1.1",
|
||||
@@ -54,19 +54,19 @@
|
||||
"react-dnd": "16.0.1",
|
||||
"react-dnd-html5-backend": "16.0.1",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-error-boundary": "^4.0.9",
|
||||
"react-error-boundary": "^4.0.10",
|
||||
"react-helmet": "^6.1.0",
|
||||
"react-hot-toast": "^2.4.1",
|
||||
"react-i18next": "^12.3.1",
|
||||
"react-redux": "^8.0.7",
|
||||
"react-redux": "^8.1.0",
|
||||
"react-refresh": "0.14.0",
|
||||
"react-router-dom": "^6.11.2",
|
||||
"react-router-dom": "^6.13.0",
|
||||
"react-scripts": "^5.0.1",
|
||||
"react-syntax-highlighter": "^15.5.0",
|
||||
"react-textarea-autosize": "^8.4.1",
|
||||
"react-use-wizard": "^2.2.1",
|
||||
"react-viewport-list": "^7.1.1",
|
||||
"react-virtuoso": "^4.3.8",
|
||||
"react-virtuoso": "^4.3.10",
|
||||
"resolve": "^1.22.3",
|
||||
"rooks": "^7.14.1",
|
||||
"slate": "^0.94.1",
|
||||
@@ -77,10 +77,10 @@
|
||||
"styled-components": "^5.3.11",
|
||||
"terser-webpack-plugin": "^5.3.9",
|
||||
"tippy.js": "^6.3.7",
|
||||
"typescript": "^5.0.4",
|
||||
"wavesurfer.js": "^6.6.3",
|
||||
"webpack": "^5.85.0",
|
||||
"webpack-dev-server": "^4.15.0",
|
||||
"typescript": "^5.1.3",
|
||||
"wavesurfer.js": "^6.6.4",
|
||||
"webpack": "^5.87.0",
|
||||
"webpack-dev-server": "^4.15.1",
|
||||
"webpack-manifest-plugin": "^5.0.0",
|
||||
"workbox-background-sync": "^7.0.0",
|
||||
"workbox-broadcast-update": "^7.0.0",
|
||||
@@ -122,15 +122,16 @@
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.22.1",
|
||||
"@ianvs/prettier-plugin-sort-imports": "^4.0.1",
|
||||
"@babel/core": "^7.22.5",
|
||||
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
|
||||
"@ianvs/prettier-plugin-sort-imports": "^4.0.2",
|
||||
"@types/emoji-mart": "^3.0.9",
|
||||
"@types/masonry-layout": "^4.2.5",
|
||||
"@types/react-helmet": "^6.1.6",
|
||||
"@types/react-syntax-highlighter": "^15.5.7",
|
||||
"@types/wavesurfer.js": "^6.0.6",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.8",
|
||||
"@typescript-eslint/parser": "^5.59.8",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.11",
|
||||
"@typescript-eslint/parser": "^5.59.11",
|
||||
"@welldone-software/why-did-you-render": "^7.0.1",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"babel-loader": "^9.1.2",
|
||||
@@ -147,7 +148,7 @@
|
||||
"md5-file": "^5.0.0",
|
||||
"patch-package": "^7.0.0",
|
||||
"postcss": "^8.4.24",
|
||||
"postcss-loader": "^7.3.2",
|
||||
"postcss-loader": "^7.3.3",
|
||||
"postinstall-postinstall": "^2.1.0",
|
||||
"prettier": "^2.8.8",
|
||||
"tailwindcss": "^3.3.2"
|
||||
|
||||
@@ -109,6 +109,7 @@ export const ChatPrefixes = {
|
||||
};
|
||||
export const vapidKey = `BOmzyZhw-DcIGYQ77mzQUVqLlcvn0bm_76P_kc7rpwRxzXNbui-JP8iPyEQYfyoxyJeq43Ud4IiIsJSMNHNujn0`;
|
||||
export const tokenHeader = "X-API-Key";
|
||||
export const KEY_SERVER_VERSION = "VC_SERVER_VERSION"; //
|
||||
export const FILE_SLICE_SIZE = 1000 * 1000; //
|
||||
export const FILE_IMAGE_SIZE = 1000 * 10000 * 8; //10mb
|
||||
export const KEY_MOBILE_APP_TIP = "MOBILE_APP_TIP";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createApi } from "@reduxjs/toolkit/query/react";
|
||||
import { unescape } from "lodash";
|
||||
|
||||
import { ChatContext } from "@/types/common";
|
||||
import { ChatMessage, ContentTypeKey, UploadFileResponse } from "@/types/message";
|
||||
|
||||
@@ -21,7 +21,13 @@ import {
|
||||
TestEmailDTO
|
||||
} from "@/types/server";
|
||||
import { User } from "@/types/user";
|
||||
import BASE_URL, { ContentTypes, IS_OFFICIAL_DEMO, PAYMENT_URL_PREFIX } from "../config";
|
||||
import { compareVersion } from "@/utils";
|
||||
import BASE_URL, {
|
||||
ContentTypes,
|
||||
IS_OFFICIAL_DEMO,
|
||||
KEY_SERVER_VERSION,
|
||||
PAYMENT_URL_PREFIX
|
||||
} from "../config";
|
||||
import { updateInfo } from "../slices/server";
|
||||
import { updateCallInfo, upsertVoiceList } from "../slices/voice";
|
||||
import { RootState } from "../store";
|
||||
@@ -68,6 +74,7 @@ export const serverApi = createApi({
|
||||
async onQueryStarted(data, { dispatch, queryFulfilled }) {
|
||||
try {
|
||||
const resp = await queryFulfilled;
|
||||
localStorage.setItem(KEY_SERVER_VERSION, resp.data);
|
||||
dispatch(updateInfo({ version: resp.data }));
|
||||
} catch {
|
||||
console.error("get server version error");
|
||||
@@ -260,10 +267,13 @@ export const serverApi = createApi({
|
||||
}
|
||||
}
|
||||
}),
|
||||
updateServer: builder.mutation<void, Server>({
|
||||
updateServer: builder.mutation<void, Partial<Server>>({
|
||||
query: (data) => ({
|
||||
url: "admin/system/organization",
|
||||
method: "POST",
|
||||
method:
|
||||
compareVersion(localStorage.getItem(KEY_SERVER_VERSION) ?? "", "0.3.7") > 0
|
||||
? "PUT"
|
||||
: "POST",
|
||||
body: data
|
||||
}),
|
||||
async onQueryStarted(data, { dispatch, queryFulfilled, getState }) {
|
||||
|
||||
@@ -14,11 +14,12 @@ export default function useLogout() {
|
||||
const dispatch = useDispatch();
|
||||
const [logout, { isLoading, isSuccess }] = useLazyLogoutQuery();
|
||||
const clearLocalData = () => {
|
||||
dispatch(resetChannels());
|
||||
dispatch(resetUsers());
|
||||
// 和消息相关的数据
|
||||
dispatch(resetFootprint());
|
||||
dispatch(resetChannelMsg());
|
||||
dispatch(resetUserMsg());
|
||||
dispatch(resetChannels());
|
||||
dispatch(resetUsers());
|
||||
dispatch(resetMessage());
|
||||
dispatch(resetReactionMessage());
|
||||
dispatch(resetFileMessage());
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from "@/app/slices/channels";
|
||||
import {
|
||||
removePinChats,
|
||||
resetFootprint,
|
||||
updateAutoDeleteSetting,
|
||||
updateMute,
|
||||
updateReadChannels,
|
||||
@@ -22,8 +23,15 @@ import {
|
||||
updateUsersVersion,
|
||||
upsertPinChats
|
||||
} from "@/app/slices/footprint";
|
||||
import { clearChannelMessage, removeChannelSession } from "@/app/slices/message.channel";
|
||||
import { removeUserSession } from "@/app/slices/message.user";
|
||||
import { resetMessage } from "@/app/slices/message";
|
||||
import {
|
||||
clearChannelMessage,
|
||||
removeChannelSession,
|
||||
resetChannelMsg
|
||||
} from "@/app/slices/message.channel";
|
||||
import { resetFileMessage } from "@/app/slices/message.file";
|
||||
import { resetReactionMessage } from "@/app/slices/message.reaction";
|
||||
import { removeUserSession, resetUserMsg } from "@/app/slices/message.user";
|
||||
import { updateInfo } from "@/app/slices/server";
|
||||
import { setReady } from "@/app/slices/ui";
|
||||
import { updateContactStatus, updateUsersByLogs, updateUsersStatus } from "@/app/slices/users";
|
||||
@@ -106,10 +114,12 @@ export default function useStreaming() {
|
||||
}
|
||||
// 开始初始化
|
||||
const params: {
|
||||
limit: string;
|
||||
"api-key": string;
|
||||
after_mid?: string;
|
||||
users_version?: string;
|
||||
} = {
|
||||
limit: "500",
|
||||
"api-key": _token
|
||||
};
|
||||
// 如果afterMid是0,则不传该参数
|
||||
@@ -147,15 +157,31 @@ export default function useStreaming() {
|
||||
case "heartbeat":
|
||||
keepAlive();
|
||||
break;
|
||||
case "message_cleared": {
|
||||
dispatch(resetFootprint());
|
||||
dispatch(resetChannelMsg());
|
||||
dispatch(resetUserMsg());
|
||||
dispatch(resetMessage());
|
||||
dispatch(resetReactionMessage());
|
||||
dispatch(resetFileMessage());
|
||||
break;
|
||||
}
|
||||
case "ready":
|
||||
ready = true;
|
||||
// 有时候,heartbeat不会发?
|
||||
keepAlive();
|
||||
dispatch(setReady());
|
||||
break;
|
||||
case "organization_config_changed": {
|
||||
const { name, description } = data;
|
||||
dispatch(updateInfo({ name, description }));
|
||||
case "server_config_changed": {
|
||||
const { type, ...rest } = data;
|
||||
const { organization_name, organization_logo, organization_description, ...tmp } = rest;
|
||||
const transformed = {
|
||||
name: organization_name,
|
||||
description: organization_description,
|
||||
...tmp
|
||||
};
|
||||
const purified = omitBy(transformed, isNull);
|
||||
dispatch(updateInfo(purified));
|
||||
break;
|
||||
}
|
||||
case "group_message_cleared": {
|
||||
|
||||
@@ -5,11 +5,7 @@ import { useDispatch } from "react-redux";
|
||||
import { useWizard } from "react-use-wizard";
|
||||
|
||||
import { useLoginMutation } from "@/app/services/auth";
|
||||
import {
|
||||
useCreateAdminMutation,
|
||||
useGetServerQuery,
|
||||
useUpdateServerMutation
|
||||
} from "@/app/services/server";
|
||||
import { useCreateAdminMutation, useUpdateServerMutation } from "@/app/services/server";
|
||||
import { updateInitialized } from "@/app/slices/auth.data";
|
||||
import { useAppSelector } from "@/app/store";
|
||||
import StyledButton from "@/components/styled/Button";
|
||||
@@ -27,7 +23,6 @@ const AdminAccount: FC<Props> = ({ serverName }) => {
|
||||
const [createAdmin, { isLoading: isSigningUp, isError: signUpError, isSuccess: signUpOk }] =
|
||||
useCreateAdminMutation();
|
||||
const [login, { isLoading: isLoggingIn, isError: loginError }] = useLoginMutation();
|
||||
const { data: serverData } = useGetServerQuery();
|
||||
const [updateServer, { isLoading: isUpdatingServer, isSuccess: isUpdatedServer }] =
|
||||
useUpdateServerMutation();
|
||||
|
||||
@@ -58,11 +53,10 @@ const AdminAccount: FC<Props> = ({ serverName }) => {
|
||||
|
||||
// After logged in
|
||||
useEffect(() => {
|
||||
if (loggedIn && serverData) {
|
||||
if (loggedIn) {
|
||||
dispatch(updateInitialized(true));
|
||||
// Set server name
|
||||
updateServer({
|
||||
...serverData,
|
||||
name: serverName
|
||||
});
|
||||
}
|
||||
|
||||
+12
-5
@@ -1,5 +1,6 @@
|
||||
import { Channel } from "./channel";
|
||||
import { ContentType } from "./message";
|
||||
import { SystemCommon } from "./server";
|
||||
import { ContactInfo, User } from "./user";
|
||||
|
||||
export interface ReadyEvent {
|
||||
@@ -178,10 +179,11 @@ interface KickFromGroupEvent {
|
||||
gid: number;
|
||||
reason: string;
|
||||
}
|
||||
interface OrgInfoChangedEvent {
|
||||
type: "organization_config_changed";
|
||||
name: string;
|
||||
description: string;
|
||||
interface ServerConfigChangedEvent extends SystemCommon {
|
||||
type: "server_config_changed";
|
||||
organization_name: string;
|
||||
organization_description: string;
|
||||
organization_logo: string;
|
||||
}
|
||||
|
||||
interface GroupChangedEvent {
|
||||
@@ -220,6 +222,10 @@ interface UserCallEvent {
|
||||
target: number;
|
||||
uid: number;
|
||||
}
|
||||
interface MessageClearedEvent {
|
||||
type: "message_cleared";
|
||||
mid: number;
|
||||
}
|
||||
|
||||
export type ServerEvent =
|
||||
| ReadyEvent
|
||||
@@ -241,4 +247,5 @@ export type ServerEvent =
|
||||
| HeartbeatEvent
|
||||
| GroupClearEvent
|
||||
| UserCallEvent
|
||||
| OrgInfoChangedEvent;
|
||||
| ServerConfigChangedEvent
|
||||
| MessageClearedEvent;
|
||||
|
||||
Reference in New Issue
Block a user