2021-10-16 03:07:13 +08:00
|
|
|
import Users from '/imports/api/users';
|
|
|
|
import Meetings from '/imports/api/meetings';
|
|
|
|
import PadsService from '/imports/ui/components/pads/service';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import { Session } from 'meteor/session';
|
|
|
|
import { ACTIONS, PANELS } from '/imports/ui/components/layout/enums';
|
2022-03-10 03:23:38 +08:00
|
|
|
import { isSharedNotesEnabled } from '/imports/ui/services/features';
|
2021-10-16 03:07:13 +08:00
|
|
|
|
2024-03-07 01:28:18 +08:00
|
|
|
const NOTES_CONFIG = window.meetingClientSettings.public.notes;
|
|
|
|
const ROLE_MODERATOR = window.meetingClientSettings.public.user.role_moderator;
|
2021-10-16 03:07:13 +08:00
|
|
|
|
|
|
|
const hasPermission = () => {
|
|
|
|
const user = Users.findOne(
|
|
|
|
{ userId: Auth.userID },
|
|
|
|
{
|
|
|
|
fields: {
|
|
|
|
locked: 1,
|
|
|
|
role: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
if (user.role === ROLE_MODERATOR) return true;
|
|
|
|
|
|
|
|
const meeting = Meetings.findOne(
|
|
|
|
{ meetingId: Auth.meetingID },
|
2024-03-26 19:57:28 +08:00
|
|
|
{ fields: { 'lockSettings.disableNotes': 1 } },
|
2021-10-16 03:07:13 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
if (user.locked) {
|
2024-03-26 19:57:28 +08:00
|
|
|
return !meeting.lockSettings.disableNotes;
|
2021-10-16 03:07:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2023-02-11 19:57:41 +08:00
|
|
|
const getLastRev = () => (Session.get('notesLastRev') || 0);
|
2021-10-16 03:07:13 +08:00
|
|
|
|
2023-02-11 19:57:41 +08:00
|
|
|
const getRev = () => PadsService.getRev(NOTES_CONFIG.id);
|
2021-10-16 03:07:13 +08:00
|
|
|
|
2023-02-11 19:57:41 +08:00
|
|
|
const markNotesAsRead = () => Session.set('notesLastRev', getRev());
|
2021-10-16 03:07:13 +08:00
|
|
|
|
2023-02-11 19:57:41 +08:00
|
|
|
const hasUnreadNotes = () => (getRev() > getLastRev());
|
2021-10-16 03:07:13 +08:00
|
|
|
|
2022-03-10 03:23:38 +08:00
|
|
|
const isEnabled = () => isSharedNotesEnabled();
|
2021-10-16 03:07:13 +08:00
|
|
|
|
|
|
|
const toggleNotesPanel = (sidebarContentPanel, layoutContextDispatch) => {
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: sidebarContentPanel !== PANELS.SHARED_NOTES,
|
|
|
|
});
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value:
|
|
|
|
sidebarContentPanel === PANELS.SHARED_NOTES
|
|
|
|
? PANELS.NONE
|
|
|
|
: PANELS.SHARED_NOTES,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-01-20 02:40:27 +08:00
|
|
|
const pinSharedNotes = (pinned, stopWatching) => {
|
|
|
|
PadsService.pinPad(NOTES_CONFIG.id, pinned, stopWatching);
|
2022-10-24 21:11:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const isSharedNotesPinned = () => {
|
|
|
|
const pinnedPad = PadsService.getPinnedPad();
|
|
|
|
return pinnedPad?.externalId === NOTES_CONFIG.id;
|
|
|
|
};
|
|
|
|
|
2021-10-16 03:07:13 +08:00
|
|
|
export default {
|
|
|
|
ID: NOTES_CONFIG.id,
|
|
|
|
toggleNotesPanel,
|
|
|
|
hasPermission,
|
|
|
|
isEnabled,
|
2023-02-11 19:57:41 +08:00
|
|
|
markNotesAsRead,
|
2021-10-16 03:07:13 +08:00
|
|
|
hasUnreadNotes,
|
2022-10-24 21:11:28 +08:00
|
|
|
isSharedNotesPinned,
|
|
|
|
pinSharedNotes,
|
2021-10-16 03:07:13 +08:00
|
|
|
};
|