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-03-30 02:22:52 +08:00
|
|
|
import mapUser from '/imports/ui/services/user/mapUser';
|
2018-12-13 04:10:27 +08:00
|
|
|
|
|
|
|
const NOTE_CONFIG = Meteor.settings.public.note;
|
|
|
|
|
2019-03-29 02:47:11 +08:00
|
|
|
const getNoteId = () => {
|
2019-05-09 04:34:19 +08:00
|
|
|
const note = Note.findOne({ meetingId: Auth.meetingID });
|
|
|
|
return note ? note.noteId : '';
|
2018-12-13 04:10:27 +08:00
|
|
|
};
|
|
|
|
|
2019-03-29 02:47:11 +08:00
|
|
|
const getReadOnlyNoteId = () => {
|
2019-05-09 04:34:19 +08:00
|
|
|
const note = Note.findOne({ meetingId: Auth.meetingID });
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2019-01-10 02:09:05 +08:00
|
|
|
const getCurrentUser = () => {
|
2019-03-30 02:22:52 +08:00
|
|
|
const User = Users.findOne({ userId: Auth.userID });
|
2019-01-10 02:09:05 +08:00
|
|
|
return User;
|
|
|
|
};
|
|
|
|
|
2018-12-13 04:10:27 +08:00
|
|
|
const getNoteParams = () => {
|
2019-05-09 04:34:19 +08:00
|
|
|
const { config } = NOTE_CONFIG;
|
2019-01-10 02:09:05 +08:00
|
|
|
const User = getCurrentUser();
|
|
|
|
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]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return params.join('&');
|
2019-03-29 02:47:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const isLocked = () => {
|
2019-05-09 04:34:19 +08:00
|
|
|
const meeting = Meetings.findOne({ meetingId: Auth.meetingID });
|
2019-03-30 02:22:52 +08:00
|
|
|
const user = getCurrentUser();
|
|
|
|
|
|
|
|
if (meeting.lockSettingsProps && mapUser(user).isLocked) {
|
|
|
|
return meeting.lockSettingsProps.disableNote;
|
|
|
|
}
|
2019-03-29 02:47:11 +08:00
|
|
|
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 = () => {
|
2019-03-29 02:47:11 +08:00
|
|
|
const noteId = getNoteId();
|
2018-12-13 04:10:27 +08:00
|
|
|
const params = getNoteParams();
|
2019-01-26 02:26:13 +08:00
|
|
|
const url = Auth.authenticateURL(NOTE_CONFIG.url + '/p/' + noteId + '?' + params);
|
2018-12-13 04:10:27 +08:00
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
2019-03-30 02:22:52 +08:00
|
|
|
const isEnabled = () => {
|
|
|
|
const note = Note.findOne({ meetingId: Auth.meetingID });
|
|
|
|
return NOTE_CONFIG.enabled && note;
|
|
|
|
};
|
|
|
|
|
2018-12-13 04:10:27 +08:00
|
|
|
export default {
|
|
|
|
getNoteURL,
|
2019-03-29 02:47:11 +08:00
|
|
|
getReadOnlyURL,
|
|
|
|
isLocked,
|
2019-03-30 02:22:52 +08:00
|
|
|
isEnabled,
|
2018-12-13 04:10:27 +08:00
|
|
|
};
|