2018-12-13 04:10:27 +08:00
|
|
|
import Users from '/imports/api/users';
|
2019-03-30 02:22:52 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
2019-03-29 02:47:11 +08:00
|
|
|
import Note from '/imports/api/note';
|
2018-12-13 04:10:27 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import Settings from '/imports/ui/services/settings';
|
2019-06-01 04:02:33 +08:00
|
|
|
import { Session } from 'meteor/session';
|
2021-05-18 04:25:07 +08:00
|
|
|
import { ACTIONS, PANELS } from '../layout/enums';
|
2018-12-13 04:10:27 +08:00
|
|
|
|
|
|
|
const NOTE_CONFIG = Meteor.settings.public.note;
|
2019-08-31 02:43:48 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
2018-12-13 04:10:27 +08:00
|
|
|
|
2019-03-29 02:47:11 +08:00
|
|
|
const getNoteId = () => {
|
2019-08-22 20:05:06 +08:00
|
|
|
const note = Note.findOne({ meetingId: Auth.meetingID }, { fields: { noteId: 1 } });
|
2019-05-09 04:34:19 +08:00
|
|
|
return note ? note.noteId : '';
|
2018-12-13 04:10:27 +08:00
|
|
|
};
|
|
|
|
|
2019-03-29 02:47:11 +08:00
|
|
|
const getReadOnlyNoteId = () => {
|
2019-08-22 20:05:06 +08:00
|
|
|
const note = Note.findOne({ meetingId: Auth.meetingID }, { fields: { readOnlyNoteId: 1 } });
|
2019-05-09 04:34:19 +08:00
|
|
|
return note ? note.readOnlyNoteId : '';
|
2019-03-29 02:47:11 +08:00
|
|
|
};
|
|
|
|
|
2018-12-13 04:10:27 +08:00
|
|
|
const getLang = () => {
|
2019-05-09 04:34:19 +08:00
|
|
|
const { locale } = Settings.application;
|
|
|
|
return locale ? locale.toLowerCase() : '';
|
2018-12-13 04:10:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const getNoteParams = () => {
|
2021-04-27 07:04:34 +08:00
|
|
|
const config = {};
|
2021-02-10 23:24:24 +08:00
|
|
|
const User = Users.findOne({ userId: Auth.userID }, { fields: { name: 1 } });
|
2019-01-10 02:09:05 +08:00
|
|
|
config.userName = User.name;
|
2018-12-13 04:10:27 +08:00
|
|
|
config.lang = getLang();
|
2021-02-09 23:59:59 +08:00
|
|
|
config.rtl = document.documentElement.getAttribute('dir') === 'rtl';
|
2018-12-13 04:10:27 +08:00
|
|
|
|
2021-05-18 04:25:07 +08:00
|
|
|
const params = Object.keys(config).map((key) => `${key}=${encodeURIComponent(config[key])}`).join('&');
|
|
|
|
return params;
|
2019-03-29 02:47:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const isLocked = () => {
|
2019-08-22 20:05:06 +08:00
|
|
|
const meeting = Meetings.findOne({ meetingId: Auth.meetingID }, { fields: { 'lockSettingsProps.disableNote': 1 } });
|
|
|
|
const user = Users.findOne({ userId: Auth.userID }, { fields: { locked: 1, role: 1 } });
|
2019-03-30 02:22:52 +08:00
|
|
|
|
2021-07-08 00:22:54 +08:00
|
|
|
if (meeting.lockSettingsProps && user.role !== ROLE_MODERATOR && user.locked) {
|
2019-03-30 02:22:52 +08:00
|
|
|
return meeting.lockSettingsProps.disableNote;
|
|
|
|
}
|
2019-03-29 02:47:11 +08:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getReadOnlyURL = () => {
|
|
|
|
const readOnlyNoteId = getReadOnlyNoteId();
|
2021-02-09 23:59:59 +08:00
|
|
|
const params = getNoteParams();
|
|
|
|
const url = Auth.authenticateURL(`${NOTE_CONFIG.url}/p/${readOnlyNoteId}?${params}`);
|
2019-03-29 02:47:11 +08:00
|
|
|
return url;
|
|
|
|
};
|
2018-12-13 04:10:27 +08:00
|
|
|
|
|
|
|
const getNoteURL = () => {
|
2019-03-29 02:47:11 +08:00
|
|
|
const noteId = getNoteId();
|
2018-12-13 04:10:27 +08:00
|
|
|
const params = getNoteParams();
|
2019-08-22 20:05:06 +08:00
|
|
|
const url = Auth.authenticateURL(`${NOTE_CONFIG.url}/p/${noteId}?${params}`);
|
2018-12-13 04:10:27 +08:00
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
2019-06-01 04:02:33 +08:00
|
|
|
const getRevs = () => {
|
2019-08-22 20:05:06 +08:00
|
|
|
const note = Note.findOne({ meetingId: Auth.meetingID }, { fields: { revs: 1 } });
|
2019-06-01 04:02:33 +08:00
|
|
|
return note ? note.revs : 0;
|
|
|
|
};
|
|
|
|
|
2021-04-27 07:04:34 +08:00
|
|
|
const getLastRevs = () => {
|
|
|
|
const lastRevs = Session.get('noteLastRevs');
|
|
|
|
|
|
|
|
if (!lastRevs) return -1;
|
|
|
|
return lastRevs;
|
|
|
|
};
|
|
|
|
|
2019-12-17 05:06:41 +08:00
|
|
|
const setLastRevs = (revs) => {
|
|
|
|
const lastRevs = getLastRevs();
|
|
|
|
|
|
|
|
if (revs !== 0 && revs > lastRevs) {
|
|
|
|
Session.set('noteLastRevs', revs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-18 04:25:07 +08:00
|
|
|
const hasUnreadNotes = (sidebarContentPanel) => {
|
|
|
|
if (sidebarContentPanel === PANELS.SHARED_NOTES) return false;
|
2019-12-17 05:06:41 +08:00
|
|
|
|
|
|
|
const revs = getRevs();
|
|
|
|
const lastRevs = getLastRevs();
|
|
|
|
|
|
|
|
return (revs !== 0 && revs > lastRevs);
|
2020-05-26 01:32:24 +08:00
|
|
|
};
|
2019-12-17 05:06:41 +08:00
|
|
|
|
2019-03-30 02:22:52 +08:00
|
|
|
const isEnabled = () => {
|
|
|
|
const note = Note.findOne({ meetingId: Auth.meetingID });
|
|
|
|
return NOTE_CONFIG.enabled && note;
|
|
|
|
};
|
|
|
|
|
2021-08-05 19:03:24 +08:00
|
|
|
const toggleNotePanel = (sidebarContentPanel, layoutContextDispatch) => {
|
|
|
|
layoutContextDispatch({
|
2021-05-18 04:25:07 +08:00
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: sidebarContentPanel !== PANELS.SHARED_NOTES,
|
|
|
|
});
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-05-18 04:25:07 +08:00
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value: sidebarContentPanel === PANELS.SHARED_NOTES
|
|
|
|
? PANELS.NONE
|
|
|
|
: PANELS.SHARED_NOTES,
|
|
|
|
});
|
2020-02-07 03:46:21 +08:00
|
|
|
};
|
|
|
|
|
2018-12-13 04:10:27 +08:00
|
|
|
export default {
|
|
|
|
getNoteURL,
|
2019-03-29 02:47:11 +08:00
|
|
|
getReadOnlyURL,
|
2020-02-07 03:46:21 +08:00
|
|
|
toggleNotePanel,
|
2019-03-29 02:47:11 +08:00
|
|
|
isLocked,
|
2019-03-30 02:22:52 +08:00
|
|
|
isEnabled,
|
2019-06-01 04:02:33 +08:00
|
|
|
getRevs,
|
2019-12-17 05:06:41 +08:00
|
|
|
setLastRevs,
|
|
|
|
getLastRevs,
|
2020-05-26 01:32:24 +08:00
|
|
|
hasUnreadNotes,
|
2018-12-13 04:10:27 +08:00
|
|
|
};
|