|
|
|
@ -5,6 +5,7 @@ const Util = require("../common-util");
|
|
|
|
|
const nThen = require("nthen");
|
|
|
|
|
const Core = require("./core");
|
|
|
|
|
const Metadata = require("./metadata");
|
|
|
|
|
const HK = require("../hk-util");
|
|
|
|
|
|
|
|
|
|
Channel.clearOwnedChannel = function (Env, safeKey, channelId, cb, Server) {
|
|
|
|
|
if (typeof(channelId) !== 'string' || channelId.length !== 32) {
|
|
|
|
@ -228,7 +229,9 @@ Channel.isNewChannel = function (Env, channel, cb) {
|
|
|
|
|
|
|
|
|
|
Otherwise behaves the same as sending to a channel
|
|
|
|
|
*/
|
|
|
|
|
Channel.writePrivateMessage = function (Env, args, cb, Server) {
|
|
|
|
|
Channel.writePrivateMessage = function (Env, args, _cb, Server, netfluxId) {
|
|
|
|
|
var cb = Util.once(Util.mkAsync(_cb));
|
|
|
|
|
|
|
|
|
|
var channelId = args[0];
|
|
|
|
|
var msg = args[1];
|
|
|
|
|
|
|
|
|
@ -246,6 +249,27 @@ Channel.writePrivateMessage = function (Env, args, cb, Server) {
|
|
|
|
|
return void cb("NOT_IMPLEMENTED");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nThen(function (w) {
|
|
|
|
|
Metadata.getMetadataRaw(Env, channelId, w(function (err, metadata) {
|
|
|
|
|
if (err) {
|
|
|
|
|
w.abort();
|
|
|
|
|
Env.Log.error('HK_WRITE_PRIVATE_MESSAGE', err);
|
|
|
|
|
return void cb('METADATA_ERR');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!metadata || !metadata.restricted) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var session = HK.getNetfluxSession(Env, netfluxId);
|
|
|
|
|
var allowed = HK.listAllowedUsers(metadata);
|
|
|
|
|
|
|
|
|
|
if (HK.isUserSessionAllowed(allowed, session)) { return; }
|
|
|
|
|
|
|
|
|
|
w.abort();
|
|
|
|
|
cb('INSUFFICIENT_PERMISSIONS');
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
// historyKeeper expects something with an 'id' attribute
|
|
|
|
|
// it will fail unless you provide it, but it doesn't need anything else
|
|
|
|
|
var channelStruct = {
|
|
|
|
@ -261,7 +285,6 @@ Channel.writePrivateMessage = function (Env, args, cb, Server) {
|
|
|
|
|
msg // the actual message content. Generally a string
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// XXX RESTRICT respect allow lists
|
|
|
|
|
|
|
|
|
|
// historyKeeper already knows how to handle metadata and message validation, so we just pass it off here
|
|
|
|
|
// if the message isn't valid it won't be stored.
|
|
|
|
@ -272,5 +295,6 @@ Channel.writePrivateMessage = function (Env, args, cb, Server) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
cb();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|