mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-14 11:05:41 +05:00
Working message sending
This commit is contained in:
parent
e413b7c384
commit
1471dd8959
@ -24,7 +24,8 @@ define([
|
||||
let onFrameworkReady = function (framework) {
|
||||
let content = { updates: [] };
|
||||
|
||||
let myName = window.webxdc.selfName = framework._.sfCommon.getMetadataMgr().getUserData().name;
|
||||
let myName = window.webxdc.selfName = framework._.sfCommon.getMetadataMgr().getUserData().name || "Guest";
|
||||
let myAddr = window.webxdc.selfAddr = framework._.sfCommon.getMetadataMgr().getUserData().uid || "Guest";
|
||||
console.log("Document is ready. My name is:", myName);
|
||||
|
||||
window.webxdc.sendUpdate = (update) => {
|
||||
@ -39,19 +40,30 @@ define([
|
||||
href: update.href,
|
||||
document: update.document,
|
||||
serial: serial,
|
||||
max_serial: serial,
|
||||
};
|
||||
content.updates.push(_update);
|
||||
if (!window.cp_updateListener) {
|
||||
console.log('pushing3', _update);
|
||||
window.cp_pendingUpdates ||= [];
|
||||
window.cp_pendingUpdates.push(_update);
|
||||
}
|
||||
else {
|
||||
window.cp_updateListener(_update);
|
||||
}
|
||||
framework.localChange();
|
||||
};
|
||||
|
||||
framework.onContentUpdate(function (newContent) {
|
||||
if (!newContent.updates) { return; }
|
||||
console.log('New content received from others', newContent.content);
|
||||
console.log('New content received from others', newContent);
|
||||
const length = content.updates.length;
|
||||
const newUpdates = newContent.updates.slice(length);
|
||||
newUpdates.forEach(update => {
|
||||
console.log('pushing', update);
|
||||
content.updates.push(update);
|
||||
if (!window.cp_updateListener) {
|
||||
console.log('pushing2', update);
|
||||
window.cp_pendingUpdates ||= [];
|
||||
window.cp_pendingUpdates.push(update);
|
||||
return;
|
||||
|
||||
@ -30,7 +30,13 @@ window.webxdc = (() => {
|
||||
// });
|
||||
window.cp_updateListener = cb;
|
||||
if (window.cp_pendingUpdates) {
|
||||
window.cp_pendingUpdates.forEach(cb);
|
||||
console.log('pending', window.cp_pendingUpdates);
|
||||
const a = window.cp_pendingUpdates;
|
||||
const maxSerial = a[a.length-1].serial;
|
||||
window.cp_pendingUpdates.forEach(update => {
|
||||
update.max_serial = maxSerial;
|
||||
cb(update);
|
||||
});
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user