|
|
|
@ -1,10 +1,40 @@ |
|
|
|
|
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) => { |
|
|
|
|
// 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' }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return message; |
|
|
|
|
}, |
|
|
|
|
run(name, messageId, instance) { |
|
|
|
|
const message = actionLinks.getMessage(name, messageId); |
|
|
|
|
|
|
|
|
|
const actionLink = message.actionLinks[name]; |
|
|
|
@ -24,4 +54,5 @@ actionLinks.run = (name, messageId, instance) => { |
|
|
|
|
handleError(err); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|