|
|
@ -9,10 +9,15 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var Messages;
|
|
|
|
var Messages;
|
|
|
|
var setEditable = Msg.setEditable = function (bool) {
|
|
|
|
Msg.setEditable = function (bool) {
|
|
|
|
bool = !bool;
|
|
|
|
bool = !bool;
|
|
|
|
Msg.inputs.forEach(function (input) {
|
|
|
|
Msg.inputs.forEach(function (input) {
|
|
|
|
|
|
|
|
if (bool) {
|
|
|
|
input.setAttribute('disabled', bool);
|
|
|
|
input.setAttribute('disabled', bool);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
input.removeAttribute('disabled');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Messages) {
|
|
|
|
if (Messages) {
|
|
|
|
// set placeholder
|
|
|
|
// set placeholder
|
|
|
|
var placeholder = bool? Messages.disconnected: Messages.contacts_typeHere;
|
|
|
|
var placeholder = bool? Messages.disconnected: Messages.contacts_typeHere;
|
|
|
@ -281,6 +286,7 @@ define([
|
|
|
|
var chan = parsed[3];
|
|
|
|
var chan = parsed[3];
|
|
|
|
if (!chan || !channels[chan]) { return; }
|
|
|
|
if (!chan || !channels[chan]) { return; }
|
|
|
|
pushMsg(common, channels[chan], parsed[4]);
|
|
|
|
pushMsg(common, channels[chan], parsed[4]);
|
|
|
|
|
|
|
|
channels[chan].refresh();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var onMessage = function (common, msg, sender, chan) {
|
|
|
|
var onMessage = function (common, msg, sender, chan) {
|
|
|
|
if (!channels[chan.id]) { return; }
|
|
|
|
if (!channels[chan.id]) { return; }
|
|
|
@ -298,12 +304,26 @@ define([
|
|
|
|
var data = getFriend(common, curvePublic);
|
|
|
|
var data = getFriend(common, curvePublic);
|
|
|
|
var proxy = common.getProxy();
|
|
|
|
var proxy = common.getProxy();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Input
|
|
|
|
|
|
|
|
var channel = channels[data.channel];
|
|
|
|
|
|
|
|
|
|
|
|
var $header = $('<div>', {
|
|
|
|
var $header = $('<div>', {
|
|
|
|
'class': 'header',
|
|
|
|
'class': 'header',
|
|
|
|
}).appendTo($container);
|
|
|
|
}).appendTo($container);
|
|
|
|
|
|
|
|
|
|
|
|
var $avatar = $('<div>', {'class': 'avatar'}).appendTo($header);
|
|
|
|
var $avatar = $('<div>', {'class': 'avatar'}).appendTo($header);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// more history...
|
|
|
|
|
|
|
|
$('<span>', {
|
|
|
|
|
|
|
|
'class': 'more-history',
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.text('get more history')
|
|
|
|
|
|
|
|
.click(function () {
|
|
|
|
|
|
|
|
console.log("GETTING HISTORY");
|
|
|
|
|
|
|
|
channel.getPreviousMessages();
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.appendTo($header);
|
|
|
|
|
|
|
|
|
|
|
|
var $removeHistory = $('<span>', {
|
|
|
|
var $removeHistory = $('<span>', {
|
|
|
|
'class': 'remove-history fa fa-eraser',
|
|
|
|
'class': 'remove-history fa fa-eraser',
|
|
|
|
title: common.Messages.contacts_removeHistoryTitle
|
|
|
|
title: common.Messages.contacts_removeHistoryTitle
|
|
|
@ -394,6 +414,15 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Msg.getLatestMessages = function () {
|
|
|
|
|
|
|
|
Object.keys(channels).forEach(function (id) {
|
|
|
|
|
|
|
|
if (id === 'me') { return; }
|
|
|
|
|
|
|
|
var friend = channels[id];
|
|
|
|
|
|
|
|
friend.getMessagesSinceDisconnect();
|
|
|
|
|
|
|
|
friend.refresh();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Msg.init = function (common, $listContainer, $msgContainer) {
|
|
|
|
Msg.init = function (common, $listContainer, $msgContainer) {
|
|
|
|
var network = common.getNetwork();
|
|
|
|
var network = common.getNetwork();
|
|
|
|
var proxy = common.getProxy();
|
|
|
|
var proxy = common.getProxy();
|
|
|
@ -470,6 +499,7 @@ define([
|
|
|
|
$chat.show();
|
|
|
|
$chat.show();
|
|
|
|
|
|
|
|
|
|
|
|
Msg.active = curvePublic;
|
|
|
|
Msg.active = curvePublic;
|
|
|
|
|
|
|
|
// TODO don't mark messages as read unless you have displayed them
|
|
|
|
|
|
|
|
|
|
|
|
refresh(curvePublic);
|
|
|
|
refresh(curvePublic);
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -559,6 +589,37 @@ define([
|
|
|
|
var statusText = status ? 'online' : 'offline';
|
|
|
|
var statusText = status ? 'online' : 'offline';
|
|
|
|
$friend.find('.status').attr('class', 'status '+statusText);
|
|
|
|
$friend.find('.status').attr('class', 'status '+statusText);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var getMoreHistory = function (network, chan, hash, count) {
|
|
|
|
|
|
|
|
var msg = [
|
|
|
|
|
|
|
|
'GET_HISTORY_RANGE',
|
|
|
|
|
|
|
|
chan.id,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
from: hash,
|
|
|
|
|
|
|
|
count: count,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
network.sendto(network.historyKeeper, JSON.stringify(msg)).then(function (a, b, c) {
|
|
|
|
|
|
|
|
console.log(a, b, c);
|
|
|
|
|
|
|
|
}, function (err) {
|
|
|
|
|
|
|
|
throw new Error(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var getChannelMessagesSince = function (network, chan, data, keys) {
|
|
|
|
|
|
|
|
var cfg = {
|
|
|
|
|
|
|
|
validateKey: keys.validateKey,
|
|
|
|
|
|
|
|
owners: [proxy.edPublic, data.edPublic],
|
|
|
|
|
|
|
|
lastKnownHash: data.lastKnownHash
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var msg = ['GET_HISTORY', chan.id, cfg];
|
|
|
|
|
|
|
|
network.sendto(network.historyKeeper, JSON.stringify(msg))
|
|
|
|
|
|
|
|
.then($.noop, function (err) {
|
|
|
|
|
|
|
|
throw new Error(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Open the channels
|
|
|
|
// Open the channels
|
|
|
|
var openFriendChannel = function (f) {
|
|
|
|
var openFriendChannel = function (f) {
|
|
|
@ -578,9 +639,18 @@ define([
|
|
|
|
removeUI: function () { removeUI(data.curvePublic); },
|
|
|
|
removeUI: function () { removeUI(data.curvePublic); },
|
|
|
|
updateUI: function (types) { updateUI(data.curvePublic, types); },
|
|
|
|
updateUI: function (types) { updateUI(data.curvePublic, types); },
|
|
|
|
updateStatus: function () { updateStatus(data.curvePublic); },
|
|
|
|
updateStatus: function () { updateStatus(data.curvePublic); },
|
|
|
|
|
|
|
|
getMessagesSinceDisconnect: function () {
|
|
|
|
|
|
|
|
getChannelMessagesSince(network, chan, data, keys);
|
|
|
|
|
|
|
|
},
|
|
|
|
wc: chan,
|
|
|
|
wc: chan,
|
|
|
|
userList: [],
|
|
|
|
userList: [],
|
|
|
|
mapId: {}
|
|
|
|
mapId: {},
|
|
|
|
|
|
|
|
getPreviousMessages: function () {
|
|
|
|
|
|
|
|
var oldestMessages = channel.messages[0];
|
|
|
|
|
|
|
|
var oldestHash = oldestMessages[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getMoreHistory(network, chan, oldestHash, 10);
|
|
|
|
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
chan.on('message', function (msg, sender) {
|
|
|
|
chan.on('message', function (msg, sender) {
|
|
|
|
onMessage(common, msg, sender, chan);
|
|
|
|
onMessage(common, msg, sender, chan);
|
|
|
@ -609,20 +679,13 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
channel.updateStatus();
|
|
|
|
channel.updateStatus();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var cfg = {
|
|
|
|
|
|
|
|
validateKey: keys.validateKey,
|
|
|
|
getChannelMessagesSince(network, chan, data, keys);
|
|
|
|
owners: [proxy.edPublic, data.edPublic],
|
|
|
|
|
|
|
|
lastKnownHash: data.lastKnownHash
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var msg = ['GET_HISTORY', chan.id, cfg];
|
|
|
|
|
|
|
|
network.sendto(network.historyKeeper, JSON.stringify(msg))
|
|
|
|
|
|
|
|
.then($.noop, function (err) {
|
|
|
|
|
|
|
|
throw new Error(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}, function (err) {
|
|
|
|
}, function (err) {
|
|
|
|
console.error(err);
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Object.keys(friends).forEach(openFriendChannel);
|
|
|
|
Object.keys(friends).forEach(openFriendChannel);
|
|
|
|
|
|
|
|
|
|
|
|
var checkNewFriends = function () {
|
|
|
|
var checkNewFriends = function () {
|
|
|
|