Fix an issue with last known hash in the messenger
This commit is contained in:
parent
dbad925e5e
commit
2a46b8f855
@ -387,6 +387,38 @@ define([
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var getChannelMessagesSince = function (chan, data, keys) {
|
||||||
|
console.log('Fetching [%s] messages since [%s]', chan.id, data.lastKnownHash || '');
|
||||||
|
|
||||||
|
if (chan.isPadChat) {
|
||||||
|
// We need to use GET_HISTORY_RANGE to make sure we won't get the full history
|
||||||
|
var txid = Util.uid();
|
||||||
|
initRangeRequest(txid, chan.id, undefined);
|
||||||
|
var msg0 = ['GET_HISTORY_RANGE', chan.id, {
|
||||||
|
//from: hash,
|
||||||
|
count: 10,
|
||||||
|
txid: txid,
|
||||||
|
}
|
||||||
|
];
|
||||||
|
network.sendto(network.historyKeeper, JSON.stringify(msg0)).then(function () {
|
||||||
|
}, function (err) {
|
||||||
|
throw new Error(err);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cfg = {
|
||||||
|
validateKey: keys ? keys.validateKey : undefined,
|
||||||
|
owners: [proxy.edPublic, data.edPublic],
|
||||||
|
lastKnownHash: data.lastKnownHash
|
||||||
|
};
|
||||||
|
var msg = ['GET_HISTORY', chan.id, cfg];
|
||||||
|
network.sendto(network.historyKeeper, JSON.stringify(msg))
|
||||||
|
.then(function () {}, function (err) {
|
||||||
|
throw new Error(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var onChannelReady = function (chanId) {
|
var onChannelReady = function (chanId) {
|
||||||
var cb = joining[chanId];
|
var cb = joining[chanId];
|
||||||
if (typeof(cb) !== 'function') {
|
if (typeof(cb) !== 'function') {
|
||||||
@ -469,16 +501,32 @@ define([
|
|||||||
if ((parsed.validateKey || parsed.owners) && parsed.channel) {
|
if ((parsed.validateKey || parsed.owners) && parsed.channel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (parsed.channel && channels[parsed.channel]) {
|
||||||
|
// Error in initial history
|
||||||
|
// History cleared while we're in the channel
|
||||||
|
if (parsed.error === 'ECLEARED') {
|
||||||
|
messenger.setChannelHead(parsed.channel, '', function () {});
|
||||||
|
emit('CLEAR_CHANNEL', parsed.channel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// History cleared while we were offline
|
||||||
|
// ==> we asked for an invalid last known hash
|
||||||
|
if (parsed.error && parsed.errorCode === "EINVAL") {
|
||||||
|
messenger.setChannelHead(parsed.channel, '', function () {
|
||||||
|
getChannelMessagesSince(getChannel(parsed.channel), {}, {});
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// End of initial history
|
// End of initial history
|
||||||
if (parsed.state && parsed.state === 1 && parsed.channel) {
|
if (parsed.state && parsed.state === 1 && parsed.channel) {
|
||||||
if (channels[parsed.channel]) {
|
|
||||||
// parsed.channel is Ready
|
// parsed.channel is Ready
|
||||||
// channel[parsed.channel].ready();
|
// channel[parsed.channel].ready();
|
||||||
channels[parsed.channel].ready = true;
|
channels[parsed.channel].ready = true;
|
||||||
onChannelReady(parsed.channel);
|
onChannelReady(parsed.channel);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Initial history message
|
// Initial history message
|
||||||
var chan = parsed[3];
|
var chan = parsed[3];
|
||||||
if (!chan || !channels[chan]) { return; }
|
if (!chan || !channels[chan]) { return; }
|
||||||
@ -495,7 +543,6 @@ define([
|
|||||||
//channels[chan.id].notify();
|
//channels[chan.id].notify();
|
||||||
}
|
}
|
||||||
//channels[chan.id].refresh();
|
//channels[chan.id].refresh();
|
||||||
// TODO emit message event
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -547,38 +594,6 @@ define([
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var getChannelMessagesSince = function (chan, data, keys) {
|
|
||||||
console.log('Fetching [%s] messages since [%s]', chan.id, data.lastKnownHash || '');
|
|
||||||
|
|
||||||
if (chan.isPadChat) {
|
|
||||||
// We need to use GET_HISTORY_RANGE to make sure we won't get the full history
|
|
||||||
var txid = Util.uid();
|
|
||||||
initRangeRequest(txid, chan.id, undefined);
|
|
||||||
var msg0 = ['GET_HISTORY_RANGE', chan.id, {
|
|
||||||
//from: hash,
|
|
||||||
count: 10,
|
|
||||||
txid: txid,
|
|
||||||
}
|
|
||||||
];
|
|
||||||
network.sendto(network.historyKeeper, JSON.stringify(msg0)).then(function () {
|
|
||||||
}, function (err) {
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var cfg = {
|
|
||||||
validateKey: keys ? keys.validateKey : undefined,
|
|
||||||
owners: [proxy.edPublic, data.edPublic],
|
|
||||||
lastKnownHash: data.lastKnownHash
|
|
||||||
};
|
|
||||||
var msg = ['GET_HISTORY', chan.id, cfg];
|
|
||||||
network.sendto(network.historyKeeper, JSON.stringify(msg))
|
|
||||||
.then(function () {}, function (err) {
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var openChannel = function (data) {
|
var openChannel = function (data) {
|
||||||
var keys = data.keys;
|
var keys = data.keys;
|
||||||
var encryptor = data.encryptor || Curve.createEncryptor(keys);
|
var encryptor = data.encryptor || Curve.createEncryptor(keys);
|
||||||
|
|||||||
@ -202,6 +202,9 @@ define([
|
|||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var clearChannel = function (id) {
|
||||||
|
$(getChat(id)).find('.cp-app-contacts-messages').html('');
|
||||||
|
};
|
||||||
markup.chatbox = function (id, data, curvePublic) {
|
markup.chatbox = function (id, data, curvePublic) {
|
||||||
var moreHistory = h('span.cp-app-contacts-more-history.fa.fa-history', {
|
var moreHistory = h('span.cp-app-contacts-more-history.fa.fa-history', {
|
||||||
title: Messages.contacts_fetchHistory,
|
title: Messages.contacts_fetchHistory,
|
||||||
@ -277,14 +280,14 @@ define([
|
|||||||
UI.alert(Messages.contacts_removeHistoryServerError);
|
UI.alert(Messages.contacts_removeHistoryServerError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO clear the UI
|
clearChannel(id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var avatar = h('div.cp-avatar');
|
var avatar = h('div.cp-avatar');
|
||||||
|
|
||||||
var headerContent = [avatar, moreHistory, data.isFriendCHat ? removeHistory : undefined];
|
var headerContent = [avatar, moreHistory, data.isFriendChat ? removeHistory : undefined];
|
||||||
if (isApp) {
|
if (isApp) {
|
||||||
headerContent = [
|
headerContent = [
|
||||||
h('div.cp-app-contacts-header-title', Messages.contacts_padTitle),
|
h('div.cp-app-contacts-header-title', Messages.contacts_padTitle),
|
||||||
@ -814,6 +817,10 @@ define([
|
|||||||
onMessengerReady();
|
onMessengerReady();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (obj.ev === 'CLEAR_CHANNEL') {
|
||||||
|
clearChannel(obj.data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (obj.ev === 'PADCHAT_READY') {
|
if (obj.ev === 'PADCHAT_READY') {
|
||||||
onPadChatReady(obj.data);
|
onPadChatReady(obj.data);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user