mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-18 09:24:55 +00:00
send changes note.update [ok]
This commit is contained in:
59
node_modules/sync.js
generated
vendored
59
node_modules/sync.js
generated
vendored
@@ -268,7 +268,7 @@ var Sync = {
|
||||
// 2.2 本地是否修改了, 冲突, 报告给前端, 前端处理
|
||||
// 冲突, 将本地修改的笔记复制一份(设置冲突字段, ConflictNoteId), 远程的覆盖本地的
|
||||
if(noteLocal.IsDirty) {
|
||||
log('冲突....')
|
||||
log('note 冲突....')
|
||||
note.ServerNoteId = note.NoteId;
|
||||
note.NoteId = noteLocal.NoteId;
|
||||
me._syncInfo.note.conflicts.push(note);
|
||||
@@ -477,6 +477,7 @@ var Sync = {
|
||||
}
|
||||
else {
|
||||
// 更新
|
||||
// TODO 后端updateNotebook只要传Usn回来即可
|
||||
Notebook.updateNotebookForceForSendChange(notebook.NotebookId, newNotebook);
|
||||
|
||||
if(notebook.LocalIsNew) {
|
||||
@@ -527,14 +528,67 @@ var Sync = {
|
||||
// 调api, 所有执行后再callback();
|
||||
// 一个一个同步执行, 因为要有
|
||||
async.eachSeries(notes, function(note, cb) {
|
||||
/*
|
||||
var api = Api.updateNote;
|
||||
if(note.LocalIsNew) {
|
||||
api = Api.addNote;
|
||||
} else if(note.LocalIsDelete) {
|
||||
api = Api.deleteNote;
|
||||
}
|
||||
*/
|
||||
|
||||
api.call(Api, note, function(newNote) {
|
||||
if(note.LocalIsNew) {
|
||||
// 添加
|
||||
Api.addNote(note, function(newNote) {
|
||||
if(!Common.isOk(newNote)) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
newNote.ServerNoteId = newNote.NoteId;
|
||||
newNote.NoteId = note.NoteId;
|
||||
me._syncInfo.note.changeAdds.push(newNote);
|
||||
|
||||
Note.updateNoteForceForSendChange(newNote);
|
||||
|
||||
me.checkNeedIncSyncAgain(newNote.Usn);
|
||||
|
||||
cb();
|
||||
});
|
||||
} else if(note.LocalIsDelete) {
|
||||
// 删除, 不管它了
|
||||
// TODO
|
||||
Api.deleteTrash(note, function(ret) {
|
||||
if(!Common.isOk(ret)) {
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 更新
|
||||
Api.updateNote(note, function(ret) {
|
||||
if(!Common.isOk(ret)) {
|
||||
if(typeof ret == 'object') {
|
||||
if(ret.msg == 'conflict') {
|
||||
me._syncInfo.note.changeConflicts.push(note);
|
||||
}
|
||||
else if(newNote.Msg == 'notExists') {
|
||||
// 可能服务器上已删除, 此时应该要作为添加而不是更新
|
||||
me._syncInfo.note.changeNeedAdds.push(note);
|
||||
}
|
||||
}
|
||||
return cb();
|
||||
}
|
||||
// 更新成功
|
||||
Note.updateNoteForceForSendChange({NoteId: note.NoteId, Usn: ret.Usn});
|
||||
|
||||
me.checkNeedIncSyncAgain(ret.Usn);
|
||||
|
||||
return cb();
|
||||
});
|
||||
}
|
||||
|
||||
//...... 过时
|
||||
/*
|
||||
api.call(Api, note, function(ret) {
|
||||
// 更新失败
|
||||
if(!newNote) {
|
||||
return cb();
|
||||
@@ -573,6 +627,7 @@ var Sync = {
|
||||
}
|
||||
cb();
|
||||
});
|
||||
*/
|
||||
}, function() {
|
||||
callback && callback();
|
||||
});
|
||||
|
Reference in New Issue
Block a user