2021-07-16 08:23:16 +08:00
|
|
|
import Users from '/imports/api/users';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
2021-10-20 04:35:39 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
2021-07-16 08:23:16 +08:00
|
|
|
|
|
|
|
const isModerator = () => {
|
2024-05-29 21:26:11 +08:00
|
|
|
const ROLE_MODERATOR = window.meetingClientSettings.public.user.role_moderator;
|
|
|
|
|
2021-07-16 08:23:16 +08:00
|
|
|
const user = Users.findOne(
|
|
|
|
{
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
userId: Auth.userID,
|
|
|
|
},
|
|
|
|
{ fields: { role: 1 } },
|
|
|
|
);
|
|
|
|
|
|
|
|
if (user && user.role === ROLE_MODERATOR) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2021-10-15 01:00:25 +08:00
|
|
|
const getLearningDashboardAccessToken = () => ((
|
|
|
|
Meetings.findOne(
|
2024-03-26 19:57:28 +08:00
|
|
|
{ meetingId: Auth.meetingID },
|
2021-10-15 01:00:25 +08:00
|
|
|
{
|
2024-03-26 19:57:28 +08:00
|
|
|
fields: { 'learningDashboard.learningDashboardAccessToken': 1 },
|
2021-07-20 01:02:32 +08:00
|
|
|
},
|
2024-03-26 19:57:28 +08:00
|
|
|
) || {})?.learningDashboard?.learningDashboardAccessToken || null);
|
2021-10-15 01:00:25 +08:00
|
|
|
|
|
|
|
const setLearningDashboardCookie = () => {
|
|
|
|
const learningDashboardAccessToken = getLearningDashboardAccessToken();
|
|
|
|
if (learningDashboardAccessToken !== null) {
|
2021-12-15 21:35:14 +08:00
|
|
|
const lifetime = new Date();
|
|
|
|
lifetime.setTime(lifetime.getTime() + (3600000)); // 1h (extends 7d when open Dashboard)
|
|
|
|
document.cookie = `ld-${Auth.meetingID}=${getLearningDashboardAccessToken()}; expires=${lifetime.toGMTString()}; path=/`;
|
2021-10-15 01:00:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2021-07-16 08:23:16 +08:00
|
|
|
|
2021-08-27 02:04:06 +08:00
|
|
|
const openLearningDashboardUrl = (lang) => {
|
2024-03-07 01:28:18 +08:00
|
|
|
const APP = window.meetingClientSettings.public.app;
|
2021-10-15 01:00:25 +08:00
|
|
|
if (getLearningDashboardAccessToken() && setLearningDashboardCookie()) {
|
2021-11-19 05:52:20 +08:00
|
|
|
window.open(`${APP.learningDashboardBase}/?meeting=${Auth.meetingID}&lang=${lang}`, '_blank');
|
2021-10-15 01:00:25 +08:00
|
|
|
} else {
|
2021-11-19 05:52:20 +08:00
|
|
|
window.open(`${APP.learningDashboardBase}/?meeting=${Auth.meetingID}&sessionToken=${Auth.sessionToken}&lang=${lang}`, '_blank');
|
2021-10-15 01:00:25 +08:00
|
|
|
}
|
2021-07-16 08:23:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
isModerator,
|
2021-08-25 22:38:35 +08:00
|
|
|
getLearningDashboardAccessToken,
|
2021-10-15 01:00:25 +08:00
|
|
|
setLearningDashboardCookie,
|
2021-08-25 22:38:35 +08:00
|
|
|
openLearningDashboardUrl,
|
2021-07-16 08:23:16 +08:00
|
|
|
};
|