The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/startup/banners.ts

63 lines
1.4 KiB

import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { Notifications } from '../../app/notifications/client';
import { APIClient } from '../../app/utils/client';
import { IBanner, BannerPlatform } from '../../definition/IBanner';
import * as banners from '../lib/banners';
const fetchInitialBanners = async (): Promise<void> => {
const response = (await APIClient.get('v1/banners.getNew', {
platform: BannerPlatform.Web,
})) as {
banners: IBanner[];
};
for (const banner of response.banners) {
banners.open({
...banner.view,
viewId: banner.view.viewId || banner._id,
});
}
};
const handleNewBanner = async (event: { bannerId: string }): Promise<void> => {
const response = (await APIClient.get('v1/banners.getNew', {
platform: BannerPlatform.Web,
bid: event.bannerId,
})) as {
banners: IBanner[];
};
for (const banner of response.banners) {
banners.open({
...banner.view,
viewId: banner.view.viewId || banner._id,
});
}
};
const watchBanners = (): (() => void) => {
fetchInitialBanners();
Notifications.onLogged('new-banner', handleNewBanner);
return (): void => {
Notifications.unLogged(handleNewBanner);
banners.clear();
};
};
Meteor.startup(() => {
let unwatchBanners: () => void | undefined;
Tracker.autorun(() => {
unwatchBanners?.();
if (!Meteor.userId()) {
return;
}
unwatchBanners = Tracker.nonreactive(watchBanners);
});
});