Skip to content

Commit

Permalink
Name creation websocket events
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemmmy committed Feb 12, 2020
1 parent db4c9ff commit 107eb82
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/names.js
Expand Up @@ -23,6 +23,7 @@ var utils = require('./utils.js'),
config = require('./../config.js'),
schemas = require('./schemas.js'),
webhooks = require('./webhooks.js'),
websockets = require('./websockets.js'),
krist = require('./krist.js');

function Names() {}
Expand Down Expand Up @@ -64,6 +65,20 @@ Names.createName = function(name, owner) {
unpaid: Names.getNameCost()
}).then(function(name) {
webhooks.callNameWebhooks(name);

websockets.broadcastEvent({
type: 'event',
event: 'name',
name: Names.nameToJSON(name)
}, function(ws) {
return new Promise(function(resolve, reject) {
if ((!ws.isGuest && (ws.auth === owner) && ws.subscriptionLevel.indexOf("ownNames") >= 0) || ws.subscriptionLevel.indexOf("names") >= 0) {
return resolve();
}

reject();
});
});
});
};

Expand All @@ -77,4 +92,4 @@ Names.nameToJSON = function(name) {
};
};

module.exports = Names;
module.exports = Names;

0 comments on commit 107eb82

Please sign in to comment.