hide new feature until it is finished

pull/1/head
ansuz 7 years ago
parent 244f436f6e
commit 05aa5ed347

@ -8,23 +8,6 @@ define([
inputs: [],
};
var Messages;
Msg.setEditable = function (bool) {
bool = !bool;
Msg.inputs.forEach(function (input) {
if (bool) {
input.setAttribute('disabled', bool);
} else {
input.removeAttribute('disabled');
}
if (Messages) {
// set placeholder
var placeholder = bool? Messages.disconnected: Messages.contacts_typeHere;
input.setAttribute('placeholder', placeholder);
}
});
};
var Types = {
message: 'MSG',
@ -310,7 +293,7 @@ define([
}
};
var createChatBox = function (common, $container, curvePublic) {
var createChatBox = function (common, $container, curvePublic, messenger) {
var data = getFriend(common, curvePublic);
var proxy = common.getProxy();
@ -357,24 +340,49 @@ define([
var $input = $('<textarea>').appendTo($inputBlock);
$input.attr('placeholder', common.Messages.contacts_typeHere);
Msg.inputs.push($input[0]);
messenger.input = $input[0];
var sending = false;
var send = function () {
if (sending) { return; }
if (!$input.val()) { return; }
var channel = channels[data.channel];
if (channel.sending) {
console.error("still sending");
return;
}
if (!$input.val()) {
console.error("nothing to send");
return;
}
if ($input.attr('disabled')) {
console.error("input is disabled");
return;
}
// Send the message
var msg = [Types.message, proxy.curvePublic, +new Date(), $input.val()];
var msgStr = JSON.stringify(msg);
var cryptMsg = channel.encryptor.encrypt(msgStr);
sending = true;
channel.sending = true;
console.log(channel.wc);
var network = common.getNetwork();
if (!network.webChannels.some(function (wc) {
if (wc.id === channel.wc.id) {
console.error(wc.id, channel.wc.id);
return true;
}
console.error(wc.id, channel.wc.id);
//return wc.id === channel.wc.id;
})) {
console.error('no such channel:' + channel.wc.id);
return;
}
channel.wc.bcast(cryptMsg).then(function () {
$input.val('');
pushMsg(common, channel, cryptMsg);
channel.refresh();
sending = false;
channel.sending = false;
}, function (err) {
sending = false;
channel.sending = false;
console.error(err);
});
};
@ -434,11 +442,12 @@ define([
};
Msg.init = function (common, $listContainer, $msgContainer) {
var messenger = {};
var network = common.getNetwork();
var proxy = common.getProxy();
Msg.hk = network.historyKeeper;
var friends = getFriendList(common);
Messages = Messages || common.Messages;
network.on('message', function(msg, sender) {
onDirectMessage(common, msg, sender);
@ -501,7 +510,7 @@ define([
if (!$chat.length) {
$chat = $('<div>', {'class':'chat'})
.data('key', curvePublic).appendTo($msgContainer);
createChatBox(common, $chat, curvePublic);
createChatBox(common, $chat, curvePublic, messenger);
isNew = true;
}
// Show the correct div
@ -639,6 +648,7 @@ define([
var encryptor = Curve.createEncryptor(keys);
network.join(data.channel).then(function (chan) {
var channel = channels[data.channel] = {
sending: false,
friendEd: f,
keys: keys,
encryptor: encryptor,
@ -656,15 +666,25 @@ define([
userList: [],
mapId: {},
getPreviousMessages: function () {
var oldestMessages = channel.messages[0];
var oldestHash = oldestMessages[0];
var history = channel.messages;
if (!history || !history.length) {
// TODO ask for default history?
return;
}
getMoreHistory(network, chan, oldestHash, 10);
var oldestMessage = history[0];
if (!oldestMessage) {
return; // nothing to fetch
}
var messageHash = oldestMessage[0];
getMoreHistory(network, chan, messageHash, 10);
},
};
chan.on('message', function (msg, sender) {
onMessage(common, msg, sender, chan);
});
var onJoining = function (peer) {
if (peer === Msg.hk) { return; }
if (channel.userList.indexOf(peer) !== -1) { return; }
@ -696,7 +716,37 @@ define([
});
};
messenger.cleanFriendChannels = function () {
Object.keys(channels).forEach(function (id) {
delete channels[id];
});
};
var openFriendChannels = messenger.openFriendChannels = function () {
Object.keys(friends).forEach(openFriendChannel);
};
messenger.setEditable = function (bool) {
bool = !bool;
var input = messenger.input;
if (!input) { return; }
if (bool) {
input.setAttribute('disabled', bool);
} else {
input.removeAttribute('disabled');
}
if (Messages) {
// set placeholder
var placeholder = bool?
common.Messages.disconnected:
common.Messages.contacts_typeHere;
input.setAttribute('placeholder', placeholder);
}
};
openFriendChannels();
var checkNewFriends = function () {
Object.keys(friends).forEach(function (f) {
@ -714,6 +764,8 @@ define([
checkNewFriends();
updateMyData(common);
});
return messenger;
};
// Invitation

@ -128,7 +128,6 @@ define([
common.getFriendListUI = Messaging.getFriendListUI;
common.createData = Messaging.createData;
common.getPendingInvites = Messaging.getPending;
common.enableMessaging = Messaging.setEditable;
common.getLatestMessages = Messaging.getLatestMessages;
// Userlist

@ -42,13 +42,16 @@ define([
Cryptpad.alert(Messages.common_connectionLost, undefined, true);
Cryptpad.enableMessaging(false);
});
Cryptpad.getProxy().on('reconnect', function () {
Cryptpad.getProxy().on('reconnect', function (uid) {
console.error('reconnecting: ', uid);
Cryptpad.findOKButton().click();
Cryptpad.enableMessaging(true);
Cryptpad.getLatestMessages();
APP.messenger.cleanFriendChannels();
APP.messenger.openFriendChannels();
APP.messenger.setEditable(true);
});
Cryptpad.initMessaging(Cryptpad, $list, $messages);
APP.messenger = Cryptpad.initMessaging(Cryptpad, $list, $messages);
var $infoBlock = $('<div>', {'class': 'info'}).appendTo($messages);
$('<h2>').text(Messages.contacts_info1).appendTo($infoBlock);

@ -169,7 +169,8 @@ body {
margin: 10px;
}
.more-history {
.hover;
display: none;
//.hover;
}
}
.chat {

Loading…
Cancel
Save