feat: add broadcast notify when call config.setClientConfig

make all connection config should up to date
pull/109/head
moonrailgun 2 years ago
parent 798abeb1ec
commit 5ca5c765b8

@ -25,6 +25,8 @@ import {
import { appendUserDMConverse } from '../model/user';
import { sharedEvent } from '../event';
import type { InboxItem } from '../model/inbox';
import { useGlobalConfigStore } from '../store/globalConfig';
import type { GlobalConfig } from '../model/config';
/**
* Redux
@ -285,6 +287,16 @@ function listenNotify(socket: AppSocket, store: AppStore) {
});
});
socket.listen(
'config.updateClientConfig',
(config: Partial<GlobalConfig>) => {
useGlobalConfigStore.setState((state) => ({
...state,
...config,
}));
}
);
// 其他的额外的通知
socketEventListeners.forEach(({ eventName, eventFn }) => {
socket.listen(eventName, eventFn);

@ -43,13 +43,15 @@ export class Config implements Base {
/**
* set global client persist config from mongodb
*
* return all config from db
*/
static async setClientPersistConfig(
this: ReturnModelType<typeof Config>,
key: string,
value: any
): Promise<void> {
await this.findOneAndUpdate(
): Promise<Record<string, any>> {
const newConfig = await this.findOneAndUpdate(
{
name: Config.globalClientConfigName,
},
@ -60,8 +62,11 @@ export class Config implements Base {
},
{
upsert: true,
new: true,
}
);
return newConfig.data;
}
}

@ -100,8 +100,12 @@ class ConfigService extends TcService {
}>
) {
const { key, value } = ctx.params;
await this.adapter.model.setClientPersistConfig(key, value);
const newConfig = await this.adapter.model.setClientPersistConfig(
key,
value
);
await this.cleanActionCache('client', []);
this.broadcastNotify(ctx, 'updateClientConfig', newConfig);
}
async all(ctx: TcContext) {

Loading…
Cancel
Save