bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/note/service.js

93 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-12-13 04:10:27 +08:00
import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
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';
2018-12-13 04:10:27 +08:00
const NOTE_CONFIG = Meteor.settings.public.note;
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
2018-12-13 04:10:27 +08:00
const getNoteId = () => {
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
};
const getReadOnlyNoteId = () => {
const note = Note.findOne({ meetingId: Auth.meetingID }, { fields: { readOnlyNoteId: 1 } });
2019-05-09 04:34:19 +08:00
return note ? note.readOnlyNoteId : '';
};
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 = () => {
2019-05-09 04:34:19 +08:00
const { config } = NOTE_CONFIG;
const User = Users.findOne({ userId: Auth.userID }, { fields: { name: 1, color: 1 } });
2019-01-10 02:09:05 +08:00
config.userName = User.name;
config.userColor = User.color;
2018-12-13 04:10:27 +08:00
config.lang = getLang();
2019-05-09 04:34:19 +08:00
const params = [];
for (const key in config) {
2018-12-13 04:10:27 +08:00
if (config.hasOwnProperty(key)) {
params.push(`${key}=${encodeURIComponent(config[key])}`);
2018-12-13 04:10:27 +08:00
}
}
return params.join('&');
};
const isLocked = () => {
const meeting = Meetings.findOne({ meetingId: Auth.meetingID }, { fields: { 'lockSettingsProps.disableNote': 1 } });
const user = Users.findOne({ userId: Auth.userID }, { fields: { locked: 1, role: 1 } });
if (meeting.lockSettingsProps && user.role !== ROLE_MODERATOR) {
return meeting.lockSettingsProps.disableNote;
}
return false;
};
const getReadOnlyURL = () => {
const readOnlyNoteId = getReadOnlyNoteId();
const url = Auth.authenticateURL(`${NOTE_CONFIG.url}/p/${readOnlyNoteId}`);
return url;
};
2018-12-13 04:10:27 +08:00
const getNoteURL = () => {
const noteId = getNoteId();
2018-12-13 04:10:27 +08:00
const params = getNoteParams();
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 = () => {
const note = Note.findOne({ meetingId: Auth.meetingID }, { fields: { revs: 1 } });
2019-06-01 04:02:33 +08:00
return note ? note.revs : 0;
};
const isEnabled = () => {
const note = Note.findOne({ meetingId: Auth.meetingID });
return NOTE_CONFIG.enabled && note;
};
2020-02-07 03:46:21 +08:00
const toggleNotePanel = () => {
Session.set(
'openPanel',
isPanelOpened() ? 'userlist' : 'note',
2020-02-07 03:46:21 +08:00
);
};
const isPanelOpened = () => Session.get('openPanel') === 'note';
2019-06-01 04:02:33 +08:00
2018-12-13 04:10:27 +08:00
export default {
getNoteURL,
getReadOnlyURL,
2020-02-07 03:46:21 +08:00
toggleNotePanel,
isLocked,
isEnabled,
2019-06-01 04:02:33 +08:00
isPanelOpened,
getRevs,
2018-12-13 04:10:27 +08:00
};