mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-15 07:31:33 +00:00
当内容相同时, 不冲突, 其它用户用服务器上的
This commit is contained in:
109
node_modules/note.js
generated
vendored
109
node_modules/note.js
generated
vendored
@@ -675,11 +675,16 @@ var Note = {
|
||||
// 更新笔记, 合并之, 内容要重新获取
|
||||
// note是服务器传过来的, 需要处理下fix
|
||||
// note.NoteId是服务器的
|
||||
updateNoteForce: function(note, callback) {
|
||||
// needReloadContent 内容是否需要重新加载, 如果处理冲突没有冲突, 已有内容, 不用更新, 只是把其它的覆盖
|
||||
updateNoteForce: function(note, callback, needReloadContent) {
|
||||
var me = this;
|
||||
|
||||
if(needReloadContent === undefined) {
|
||||
needReloadContent = true;
|
||||
}
|
||||
|
||||
note.IsDirty = false;
|
||||
note.InitSync = true;
|
||||
note.InitSync = needReloadContent;
|
||||
note.LocalIsNew = false;
|
||||
note.LocalIsDelete = false;
|
||||
|
||||
@@ -770,10 +775,12 @@ var Note = {
|
||||
console.log('强制更新...');
|
||||
callback && callback(note);
|
||||
|
||||
/*
|
||||
me.getNoteByServerNoteId(note.ServerNoteId, function(t) {
|
||||
console.log('强制更新后的...');
|
||||
console.log(t);
|
||||
});
|
||||
*/
|
||||
|
||||
// 重新统计之
|
||||
Notebook.reCountNotebookNumberNotes(note.NotebookId);
|
||||
@@ -1032,36 +1039,77 @@ var Note = {
|
||||
console.log('fix note conflicts');
|
||||
console.log(conflictNotes);
|
||||
// 这里为什么要同步? 因为fixConflicts后要进行send changes, 这些有冲突的不能发送changes
|
||||
if(conflictNotes) {
|
||||
async.eachSeries(conflictNotes, function(note, cb) { // note是服务器上最新的, note.NoteId, ServerNoteId已转换
|
||||
var noteId = note.NoteId; // 本地noteId
|
||||
// 复制一份, 本地的复制一份, 然后服务器上的替换本地的
|
||||
// newNote其实是现有的复制一份得到的
|
||||
me.copyNoteForConfict(noteId, function(newNote) {
|
||||
if(newNote) {
|
||||
// 更新之前的
|
||||
me.updateNoteForceForConflict(note, function(note2) {
|
||||
if(note2) {
|
||||
// 前端来处理, 全量sync时不用前端一个个处理
|
||||
Web.fixSyncConflictNote(note2, newNote);
|
||||
}
|
||||
cb();
|
||||
});
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
}, function() {
|
||||
// 最后调用
|
||||
callback && callback();
|
||||
});
|
||||
} else {
|
||||
callback && callback();
|
||||
conflictNotes || (conflictNotes = []);
|
||||
if(!Api) {
|
||||
Api = require('api')
|
||||
}
|
||||
async.eachSeries(conflictNotes, function(serverAndLocalNote, cb) {
|
||||
// var noteId = note.NoteId; // 本地noteId
|
||||
// 复制一份, 本地的复制一份, 然后服务器上的替换本地的
|
||||
// newNote其实是现有的复制一份得到的
|
||||
|
||||
// TODO, 这里, 如果内容是一样的, 则以服务器上的版为准
|
||||
|
||||
console.error('是否真的冲突');
|
||||
var serverNote = serverAndLocalNote.server; // noteId没有转换的
|
||||
var localNote = serverAndLocalNote.local; // 本地的note
|
||||
|
||||
Api.getNoteContent(serverNote.NoteId, function(noteContent) {
|
||||
// 同步到本地
|
||||
if(Common.isOk(noteContent)) {
|
||||
var serverContent = noteContent.Content;
|
||||
|
||||
// 没有冲突, 好, 用服务器端的其它值
|
||||
if(serverContent == localNote.Content) {
|
||||
console.error(localNote.Title + ' 无冲突');
|
||||
// console.log(serverNote);
|
||||
delete serverNote['Content'];
|
||||
delete serverNote['Abstract'];
|
||||
delete serverNote['Desc'];
|
||||
me.updateNoteForce(serverNote, function(updatedNote) {
|
||||
// 作为更新
|
||||
noteSyncInfo.updates.push(updatedNote);
|
||||
cb();
|
||||
}, false);
|
||||
}
|
||||
|
||||
// 不行, 冲突了, 复制一份
|
||||
// TODO 用新的Content, 不要再去取了
|
||||
else {
|
||||
me.copyNoteForConfict(localNote.NoteId, function(newNote) {
|
||||
if(newNote) {
|
||||
// 更新之前的
|
||||
serverNote.ServerNoteId = serverNote.NoteId;
|
||||
serverNote.NoteId = localNote.NoteId;
|
||||
me.updateNoteForceForConflict(serverNote, function(note2) {
|
||||
if(note2) {
|
||||
// 前端来处理, 全量sync时不用前端一个个处理
|
||||
Web.fixSyncConflictNote(note2, newNote);
|
||||
}
|
||||
cb();
|
||||
});
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}, function() {
|
||||
// 最后调用
|
||||
callback && callback();
|
||||
|
||||
// 因为在处理冲突的时候有些成为更新了, 所以必须在此之后调用
|
||||
console.log('has updates...');
|
||||
console.log(noteSyncInfo.updates);
|
||||
// 处理更新的
|
||||
Web.updateSyncNote(noteSyncInfo.updates);
|
||||
});
|
||||
|
||||
// 发送改变的冲突
|
||||
// 复制一份
|
||||
// [待测]
|
||||
// 发送改变的冲突, 有这种情况发生吗?
|
||||
var changeConflicts = noteSyncInfo.changeConflicts;
|
||||
console.log('changeConflicts');
|
||||
console.log(changeConflicts);
|
||||
@@ -1113,11 +1161,6 @@ var Note = {
|
||||
console.log(addNotes);
|
||||
Web.addSyncNote(addNotes);
|
||||
|
||||
console.log('has updates...');
|
||||
console.log(noteSyncInfo.updates);
|
||||
// 处理更新的
|
||||
Web.updateSyncNote(noteSyncInfo.updates);
|
||||
|
||||
// 处理删除的
|
||||
Web.deleteSyncNote(noteSyncInfo.deletes);
|
||||
|
||||
|
Reference in New Issue
Block a user