bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/note/service.js
2019-12-16 18:06:41 -03:00

113 lines
2.9 KiB
JavaScript

import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
import Note from '/imports/api/note';
import Auth from '/imports/ui/services/auth';
import Settings from '/imports/ui/services/settings';
import { Session } from 'meteor/session';
const NOTE_CONFIG = Meteor.settings.public.note;
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
const getNoteId = () => {
const note = Note.findOne({ meetingId: Auth.meetingID }, { fields: { noteId: 1 } });
return note ? note.noteId : '';
};
const getReadOnlyNoteId = () => {
const note = Note.findOne({ meetingId: Auth.meetingID }, { fields: { readOnlyNoteId: 1 } });
return note ? note.readOnlyNoteId : '';
};
const getLang = () => {
const { locale } = Settings.application;
return locale ? locale.toLowerCase() : '';
};
const getNoteParams = () => {
const { config } = NOTE_CONFIG;
const User = Users.findOne({ userId: Auth.userID }, { fields: { name: 1, color: 1 } });
config.userName = User.name;
config.userColor = User.color;
config.lang = getLang();
const params = [];
for (const key in config) {
if (config.hasOwnProperty(key)) {
params.push(`${key}=${encodeURIComponent(config[key])}`);
}
}
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.locked && 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;
};
const getNoteURL = () => {
const noteId = getNoteId();
const params = getNoteParams();
const url = Auth.authenticateURL(`${NOTE_CONFIG.url}/p/${noteId}?${params}`);
return url;
};
const getRevs = () => {
const note = Note.findOne({ meetingId: Auth.meetingID }, { fields: { revs: 1 } });
return note ? note.revs : 0;
};
const setLastRevs = (revs) => {
const lastRevs = getLastRevs();
if (revs !== 0 && revs > lastRevs) {
Session.set('noteLastRevs', revs);
}
};
const getLastRevs = () => {
const lastRevs = Session.get('noteLastRevs');
if (!lastRevs) return -1;
return lastRevs;
};
const hasUnreadNotes = () => {
const opened = isPanelOpened();
if (opened) return false;
const revs = getRevs();
const lastRevs = getLastRevs();
return (revs !== 0 && revs > lastRevs);
}
const isEnabled = () => {
const note = Note.findOne({ meetingId: Auth.meetingID });
return NOTE_CONFIG.enabled && note;
};
const isPanelOpened = () => Session.get('openPanel') === 'note';
export default {
getNoteURL,
getReadOnlyURL,
isLocked,
isEnabled,
isPanelOpened,
getRevs,
setLastRevs,
getLastRevs,
hasUnreadNotes
};