fix note sync; add marker to mark dirty & sync error note and

This commit is contained in:
life
2017-01-19 18:38:54 +08:00
parent 6f6212b00f
commit ee0d4fa803
9 changed files with 321 additions and 126 deletions

73
node_modules/note.js generated vendored
View File

@@ -616,7 +616,7 @@ var Note = {
var me = this;
// 修复内容, 修改图片, 附件链接为本地链接
content = me.fixNoteContent(content);
db.notes.update({NoteId: noteId}, { $set: {Content: content, InitSync: false, IsContentDirty: false} }, {}, function (err, numReplaced) {
db.notes.update({NoteId: noteId}, { $set: {Err: null, Content: content, InitSync: false, IsContentDirty: false} }, {}, function (err, numReplaced) {
if(err) {
log(err);
callback && callback(false);
@@ -965,6 +965,7 @@ var Note = {
// 不要服务器上的
delete note['UpdatedTime'];
delete note['CreatedTime'];
note.Err = null;
db.notes.update({NoteId: note.NoteId}, {$set: note}, {}, function (err, cnt) { // Callback is optional
// console.log('re:');
@@ -1329,15 +1330,6 @@ var Note = {
// 因为在处理冲突的时候有些成为更新了, 所以必须在此之后调用
// console.log('has updates...');
// console.log(noteSyncInfo.updates);
// 处理更新的
if (!Common.isEmpty(noteSyncInfo.updates)) {
Web.updateSyncNote(noteSyncInfo.updates);
}
if (!Common.isEmpty(noteSyncInfo.changeUpdates)) {
Web.updateChangeUpdates(noteSyncInfo.changeUpdates);
}
});
// 发送改变的冲突
@@ -1378,6 +1370,36 @@ var Note = {
})(i);
}
// errors
Web.updateErrors(noteSyncInfo.errors);
// 1. pull
// 更新的
if (!Common.isEmpty(noteSyncInfo.updates)) {
Web.updateSyncNote(noteSyncInfo.updates);
}
// 处理添加的
var addNotes = noteSyncInfo.adds;
if (!isEmpty(addNotes)) {
console.log(' has add note...', addNotes);
Web.addSyncNote(addNotes);
}
// 处理删除的
Web.deleteSyncNote(noteSyncInfo.deletes);
// 2. push
// 处理添加的
if (!Common.isEmpty(noteSyncInfo.changeAdds)) {
Web.updateChangeAdds(noteSyncInfo.changeAdds);
}
// 处理更新的
if (!Common.isEmpty(noteSyncInfo.changeUpdates)) {
Web.updateChangeUpdates(noteSyncInfo.changeUpdates);
}
// 服务器没有, 但是是发送更新的, 所以需要作为添加以后再send changes
if(noteSyncInfo.changeNeedAdds) {
var needAddNotes = noteSyncInfo.changeNeedAdds;
@@ -1388,16 +1410,6 @@ var Note = {
}
}
// 处理添加的
var addNotes = noteSyncInfo.adds;
if (!isEmpty(addNotes)) {
console.log(' has add note...', addNotes);
Web.addSyncNote(addNotes);
}
// 处理删除的
Web.deleteSyncNote(noteSyncInfo.deletes);
// 为了博客
var changeAdds = noteSyncInfo.changeAdds || [];
var changeUpdates = noteSyncInfo.changeUpdates || [];
@@ -1847,6 +1859,27 @@ var Note = {
Api.exportPdf(serverNoteId, callback);
}
})
},
// 设置笔记同步错误信息
setError: function (noteId, err, ret, callback) {
var me = this;
var Err = {};
try {
if (err && typeof err == 'object') {
Err.err = err.toString();
}
} catch(e) {
}
if (typeof ret == 'object' && 'Msg' in ret) {
Err.msg = ret.Msg;
} else {
Err.msg = ret + '';
}
db.notes.update({NoteId: noteId}, { $set: {Err: msg} }, {}, function (err, numReplaced) {
return callback && callback(true);
});
}
};