[IMPROVE] Remove index files from action-links, accounts and assets (#17607)
parent
cb46fb3e39
commit
6ed0e44722
@ -1 +0,0 @@ |
||||
export * from './server/index'; |
@ -1,27 +1,58 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { handleError } from '../../../utils'; |
||||
import { actionLinks } from '../../both/lib/actionLinks'; |
||||
// Action Links Handler. This method will be called off the client.
|
||||
import { handleError } from '../../../utils/client'; |
||||
import { Messages, Subscriptions } from '../../../models/client'; |
||||
|
||||
actionLinks.run = (name, messageId, instance) => { |
||||
const message = actionLinks.getMessage(name, messageId); |
||||
// Action Links namespace creation.
|
||||
export const actionLinks = { |
||||
actions: {}, |
||||
register(name, funct) { |
||||
actionLinks.actions[name] = funct; |
||||
}, |
||||
getMessage(name, messageId) { |
||||
const userId = Meteor.userId(); |
||||
if (!userId) { |
||||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { function: 'actionLinks.getMessage' }); |
||||
} |
||||
|
||||
const message = Messages.findOne({ _id: messageId }); |
||||
if (!message) { |
||||
throw new Meteor.Error('error-invalid-message', 'Invalid message', { function: 'actionLinks.getMessage' }); |
||||
} |
||||
|
||||
const subscription = Subscriptions.findOne({ |
||||
rid: message.rid, |
||||
'u._id': userId, |
||||
}); |
||||
if (!subscription) { |
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { function: 'actionLinks.getMessage' }); |
||||
} |
||||
|
||||
if (!message.actionLinks || !message.actionLinks[name]) { |
||||
throw new Meteor.Error('error-invalid-actionlink', 'Invalid action link', { function: 'actionLinks.getMessage' }); |
||||
} |
||||
|
||||
const actionLink = message.actionLinks[name]; |
||||
return message; |
||||
}, |
||||
run(name, messageId, instance) { |
||||
const message = actionLinks.getMessage(name, messageId); |
||||
|
||||
let ranClient = false; |
||||
const actionLink = message.actionLinks[name]; |
||||
|
||||
if (actionLinks && actionLinks.actions && actionLinks.actions[actionLink.method_id]) { |
||||
// run just on client side
|
||||
actionLinks.actions[actionLink.method_id](message, actionLink.params, instance); |
||||
let ranClient = false; |
||||
|
||||
ranClient = true; |
||||
} |
||||
if (actionLinks && actionLinks.actions && actionLinks.actions[actionLink.method_id]) { |
||||
// run just on client side
|
||||
actionLinks.actions[actionLink.method_id](message, actionLink.params, instance); |
||||
|
||||
// and run on server side
|
||||
Meteor.call('actionLinkHandler', name, messageId, (err) => { |
||||
if (err && !ranClient) { |
||||
handleError(err); |
||||
ranClient = true; |
||||
} |
||||
}); |
||||
|
||||
// and run on server side
|
||||
Meteor.call('actionLinkHandler', name, messageId, (err) => { |
||||
if (err && !ranClient) { |
||||
handleError(err); |
||||
} |
||||
}); |
||||
}, |
||||
}; |
||||
|
@ -1,8 +0,0 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
if (Meteor.isClient) { |
||||
module.exports = require('./client/index.js'); |
||||
} |
||||
if (Meteor.isServer) { |
||||
module.exports = require('./server/index.js'); |
||||
} |
@ -1,6 +1,6 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { Messages, Subscriptions } from '../../../models'; |
||||
import { Messages, Subscriptions } from '../../../models/server'; |
||||
|
||||
// Action Links namespace creation.
|
||||
export const actionLinks = { |
@ -1 +0,0 @@ |
||||
export * from './server/index'; |
@ -1 +0,0 @@ |
||||
export * from './server/index'; |
@ -1 +0,0 @@ |
||||
export { default } from './server/bigbluebutton-api'; |
@ -0,0 +1 @@ |
||||
export { default } from './bigbluebutton-api'; |
@ -1 +0,0 @@ |
||||
import './server/index'; |
@ -0,0 +1,5 @@ |
||||
import { actionLinks } from '../../../action-links/client'; |
||||
|
||||
actionLinks.register('createLivechatCall', function(message, params, instance) { |
||||
instance.tabBar.open('video'); |
||||
}); |
@ -0,0 +1,26 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; |
||||
|
||||
import { actionLinks } from '../../../action-links/server'; |
||||
import { Notifications } from '../../../notifications/server'; |
||||
import { Messages, LivechatRooms } from '../../../models/server'; |
||||
import { settings } from '../../../settings/server'; |
||||
import { Livechat } from './Livechat'; |
||||
|
||||
actionLinks.register('denyLivechatCall', function(message/* , params*/) { |
||||
const user = Meteor.user(); |
||||
|
||||
Messages.createWithTypeRoomIdMessageAndUser('command', message.rid, 'endCall', user); |
||||
Notifications.notifyRoom(message.rid, 'deleteMessage', { _id: message._id }); |
||||
|
||||
const language = user.language || settings.get('Language') || 'en'; |
||||
|
||||
Livechat.closeRoom({ |
||||
user, |
||||
room: LivechatRooms.findOneById(message.rid), |
||||
comment: TAPi18n.__('Videocall_declined', { lng: language }), |
||||
}); |
||||
Meteor.defer(() => { |
||||
Messages.setHiddenById(message._id); |
||||
}); |
||||
}); |
Loading…
Reference in new issue