Commit 8c0e0a68 authored by Nelson GONCALVES's avatar Nelson GONCALVES
Browse files

Resolve hooks using returned values instead of callbacks

parent 17440dff
...@@ -215,19 +215,18 @@ exports.authFailure = function(hook_name, context, cb) { ...@@ -215,19 +215,18 @@ exports.authFailure = function(hook_name, context, cb) {
laclasseLogger.warn('authFailure: Redirect to SSO: ',url); laclasseLogger.warn('authFailure: Redirect to SSO: ',url);
// signal that we have handled it // signal that we have handled it
cb([true]); return cb([true]);
} }
exports.handleMessage = function (hook_name, context, cb) { exports.handleMessage = async function (hook_name, context, cb) {
// skip if we don't have any information to set // skip if we don't have any information to set
var session = context.client.client.request.session; var session = context.client.client.request.session;
if (!session || !session.user || !session.user.display_name) return cb(); if (!session || !session.user || !session.user.display_name) return cb();
authorManager.getAuthor4Token(context.message.token).then(function (author) { await authorManager.getAuthor4Token(context.message.token).then(function (author) {
authorManager.setAuthorName(author, context.client.client.request.session.user.display_name); authorManager.setAuthorName(author, context.client.client.request.session.user.display_name);
cb();
}).catch(function (error) { }).catch(function (error) {
console.error('handleMessage: could not get authorid for token %s', context.message.token, error); console.error('handleMessage: could not get authorid for token %s', context.message.token, error);
cb();
}); });
return cb();
}; };
\ No newline at end of file
...@@ -82,4 +82,6 @@ exports.expressCreateServer = function (hook_name, args, cb) { ...@@ -82,4 +82,6 @@ exports.expressCreateServer = function (hook_name, args, cb) {
importHandler.doImport(req, res, req.params.pad); importHandler.doImport(req, res, req.params.pad);
}); });
return cb();
} }
var PadMessageHandler = require("ep_etherpad-lite/node/handler/PadMessageHandler.js"); var PadMessageHandler = require("ep_etherpad-lite/node/handler/PadMessageHandler.js");
exports.userLeave = function(hook, session, callback) { exports.userLeave = function(hook, session, cb) {
const userCount = PadMessageHandler.padUsersCount(session.padId).padUsersCount const userCount = PadMessageHandler.padUsersCount(session.padId).padUsersCount
console.log('%s left pad %s - %d user(s) still editing the pad', session.author, session.padId, userCount); console.log('%s left pad %s - %d user(s) still editing the pad', session.author, session.padId, userCount);
/** /**
* TODO * TODO
* 2- If no author call a webhook on laclasse-service to trigger saving of file * 2- If no author call a webhook on laclasse-service to trigger saving of file
*/ */
return cb();
}; };
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment