|
|
@ -120,7 +120,7 @@ define([
|
|
|
|
var network = ctx.store.network;
|
|
|
|
var network = ctx.store.network;
|
|
|
|
console.log('Fetching [%s] messages since [%s]', channel.id, data.lastKnownHash || '');
|
|
|
|
console.log('Fetching [%s] messages since [%s]', channel.id, data.lastKnownHash || '');
|
|
|
|
|
|
|
|
|
|
|
|
if (channel.isPadChat) {
|
|
|
|
if (channel.isPadChat || channel.isTeamChat) {
|
|
|
|
// We need to use GET_HISTORY_RANGE to make sure we won't get the full history
|
|
|
|
// We need to use GET_HISTORY_RANGE to make sure we won't get the full history
|
|
|
|
var txid = Util.uid();
|
|
|
|
var txid = Util.uid();
|
|
|
|
initRangeRequest(ctx, txid, channel.id, undefined);
|
|
|
|
initRangeRequest(ctx, txid, channel.id, undefined);
|
|
|
@ -137,8 +137,6 @@ define([
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// XXX team chat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Friend chat, intial history
|
|
|
|
// Friend chat, intial history
|
|
|
|
var proxy = ctx.store.proxy;
|
|
|
|
var proxy = ctx.store.proxy;
|
|
|
|
var friend = getFriendFromChannel(ctx, channel.id) || {};
|
|
|
|
var friend = getFriendFromChannel(ctx, channel.id) || {};
|
|
|
@ -165,6 +163,8 @@ define([
|
|
|
|
friend.lastKnownHash = hash;
|
|
|
|
friend.lastKnownHash = hash;
|
|
|
|
} else if (channel.isPadChat) {
|
|
|
|
} else if (channel.isPadChat) {
|
|
|
|
// Nothing to do
|
|
|
|
// Nothing to do
|
|
|
|
|
|
|
|
} else if (channel.isTeamChat) {
|
|
|
|
|
|
|
|
// Nothing to do
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// TODO room
|
|
|
|
// TODO room
|
|
|
|
return void cb({error: 'NOT_IMPLEMENTED'});
|
|
|
|
return void cb({error: 'NOT_IMPLEMENTED'});
|
|
|
@ -453,6 +453,7 @@ define([
|
|
|
|
id: data.channel,
|
|
|
|
id: data.channel,
|
|
|
|
isFriendChat: data.isFriendChat,
|
|
|
|
isFriendChat: data.isFriendChat,
|
|
|
|
isPadChat: data.isPadChat,
|
|
|
|
isPadChat: data.isPadChat,
|
|
|
|
|
|
|
|
isTeamChat: data.isTeamChat,
|
|
|
|
padChan: data.padChan, // Channel ID of the pad linked to this pad chat
|
|
|
|
padChan: data.padChan, // Channel ID of the pad linked to this pad chat
|
|
|
|
readOnly: data.readOnly,
|
|
|
|
readOnly: data.readOnly,
|
|
|
|
ready: false,
|
|
|
|
ready: false,
|
|
|
@ -671,6 +672,17 @@ define([
|
|
|
|
}]);
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Team chat room
|
|
|
|
|
|
|
|
if (data && data.teamChat) {
|
|
|
|
|
|
|
|
var tCChannel = ctx.channels[data.teamChat];
|
|
|
|
|
|
|
|
if (!tCChannel) { return void cb({error: 'NO_SUCH_CHANNEL'}); }
|
|
|
|
|
|
|
|
return void cb([{
|
|
|
|
|
|
|
|
id: tCChannel.id,
|
|
|
|
|
|
|
|
isTeamChat: true,
|
|
|
|
|
|
|
|
messages: tCChannel.messages
|
|
|
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Existing friends...
|
|
|
|
// Existing friends...
|
|
|
|
var rooms = Object.keys(ctx.channels).map(function (id) {
|
|
|
|
var rooms = Object.keys(ctx.channels).map(function (id) {
|
|
|
|
var r = ctx.channels[id];
|
|
|
|
var r = ctx.channels[id];
|
|
|
@ -683,6 +695,8 @@ define([
|
|
|
|
curvePublic = friend.curvePublic;
|
|
|
|
curvePublic = friend.curvePublic;
|
|
|
|
} else if (r.isPadChat) {
|
|
|
|
} else if (r.isPadChat) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else if (r.isTeamChat) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// TODO room get metadata (name) && lastKnownHash
|
|
|
|
// TODO room get metadata (name) && lastKnownHash
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -752,6 +766,52 @@ define([
|
|
|
|
openChannel(ctx, chanData);
|
|
|
|
openChannel(ctx, chanData);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var openTeamChat = function (ctx, clientId, data, _cb) {
|
|
|
|
|
|
|
|
var teams = ctx.store.modules['team'];
|
|
|
|
|
|
|
|
var team = teams.getTeam(data.teamId);
|
|
|
|
|
|
|
|
if (!team) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var chatData = team.getChatData();
|
|
|
|
|
|
|
|
var chanId = chatData.channel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cb = Util.once(Util.mkAsync(function () {
|
|
|
|
|
|
|
|
ctx.emit('TEAMCHAT_READY', chanId, [clientId]);
|
|
|
|
|
|
|
|
_cb({
|
|
|
|
|
|
|
|
channel: chanId
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var channel = ctx.channels[chanId];
|
|
|
|
|
|
|
|
if (channel) {
|
|
|
|
|
|
|
|
return void channel.onReady.reg(function () {
|
|
|
|
|
|
|
|
if (channel.clients.indexOf(clientId) === -1) {
|
|
|
|
|
|
|
|
channel.clients.push(clientId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cb();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var secret = chatData.secret;
|
|
|
|
|
|
|
|
if (secret.keys.cryptKey) {
|
|
|
|
|
|
|
|
secret.keys.cryptKey = convertToUint8(secret.keys.cryptKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var encryptor = Crypto.createEncryptor(secret.keys);
|
|
|
|
|
|
|
|
var vKey = (secret.keys && secret.keys.validateKey) || chatData.validateKey;
|
|
|
|
|
|
|
|
var chanData = {
|
|
|
|
|
|
|
|
teamId: data.teamId,
|
|
|
|
|
|
|
|
readOnly: typeof(secret.keys) === "object" && !secret.keys.validateKey,
|
|
|
|
|
|
|
|
encryptor: encryptor,
|
|
|
|
|
|
|
|
channel: chanId,
|
|
|
|
|
|
|
|
isTeamChat: true,
|
|
|
|
|
|
|
|
decrypt: function (msg) {
|
|
|
|
|
|
|
|
return encryptor.decrypt(msg, vKey);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
clients: [clientId],
|
|
|
|
|
|
|
|
onReady: cb
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
openChannel(ctx, chanData);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var clearOwnedChannel = function (ctx, id, cb) {
|
|
|
|
var clearOwnedChannel = function (ctx, id, cb) {
|
|
|
|
var channel = ctx.clients[id];
|
|
|
|
var channel = ctx.clients[id];
|
|
|
|
if (!channel) { return void cb({error: 'NO_CHANNEL'}); }
|
|
|
|
if (!channel) { return void cb({error: 'NO_CHANNEL'}); }
|
|
|
@ -877,6 +937,10 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
messenger.openTeamChat = function (data, cId, cb) {
|
|
|
|
|
|
|
|
openTeamChat(ctx, cId, data, cb);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
messenger.removeClient = function (clientId) {
|
|
|
|
messenger.removeClient = function (clientId) {
|
|
|
|
removeClient(ctx, clientId);
|
|
|
|
removeClient(ctx, clientId);
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -892,6 +956,9 @@ define([
|
|
|
|
if (cmd === 'GET_USERLIST') {
|
|
|
|
if (cmd === 'GET_USERLIST') {
|
|
|
|
return void getUserList(ctx, data, cb);
|
|
|
|
return void getUserList(ctx, data, cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd === 'OPEN_TEAM_CHAT') {
|
|
|
|
|
|
|
|
return void openTeamChat(ctx, clientId, data, cb);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (cmd === 'OPEN_PAD_CHAT') {
|
|
|
|
if (cmd === 'OPEN_PAD_CHAT') {
|
|
|
|
return void openPadChat(ctx, clientId, data, cb);
|
|
|
|
return void openPadChat(ctx, clientId, data, cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|