This commit is contained in:
life
2015-02-27 22:29:38 +08:00
parent 3a179380db
commit 6df80d2fed
12 changed files with 45413 additions and 100 deletions

74
node_modules/note.js generated vendored
View File

@@ -44,7 +44,8 @@ var Note = {
var me = this;
var userId = User.getCurActiveUserId();
noteOrContent['UserId'] = userId;
console.log('updateNoteOrContent: ' + noteOrContent.NoteId);
console.log('updateNoteOrContent: ');
console.log(noteOrContent);
var date = new Date();
noteOrContent.UpdatedTime = date;
@@ -394,7 +395,7 @@ var Note = {
inSyncContent: {}, // 正在同步中的
getNoteContent: function(noteId, callback) {
var me = this;
log('getNoteContent------')
console.log('getNoteContent------')
// 如果是正在sync的话, 返回
if(me.inSyncContent[noteId]) {
return;
@@ -620,10 +621,10 @@ var Note = {
console.log(err);
console.log(cnt);
if(err) {
console.log(err);
console.error(err);
callback && callback(false);
} else {
log('强制更新...');
console.log('强制更新...');
callback && callback(note);
// 下载内容, 图片, 附件
@@ -875,8 +876,8 @@ var Note = {
var me = this;
var conflictNotes = noteSyncInfo.conflicts;
log('fix note conflicts');
log(conflictNotes);
console.log('fix note conflicts');
console.log(conflictNotes);
// 这里为什么要同步? 因为fixConflicts后要进行send changes, 这些有冲突的不能发送changes
if(conflictNotes) {
async.eachSeries(conflictNotes, function(note, cb) { // note是服务器上最新的, note.NoteId, ServerNoteId已转换
@@ -911,35 +912,43 @@ var Note = {
console.log('changeConflicts');
console.log(changeConflicts);
for(var i in changeConflicts) {
var note = changeConflicts[i]; // note是本地的note
// 复制一份
me.copyNoteForConfict(note.NoteId, function(newNote) {
if(newNote) {
// 更新之前的, 要先从服务器上得到服务版的
// 这里的note是本地的, 所以将服务器上的覆盖它
if(!Api) {
Api = require('api');
}
Api.getNote(note.ServerNoteId, function(serverNote) {
serverNote.ServerNoteId = serverNote.NoteId;
serverNote.NoteId = note.NoteId;
me.updateNoteForceForConflict(serverNote, function(note2) {
if(!note2) {
// 前端来处理, 全量sync时不用前端一个个处理
Web.fixSyncConflict(note2, newNote);
}
(function(i) {
var note = changeConflicts[i]; // note是本地的note
// 复制一份
me.copyNoteForConfict(note.NoteId, function(newNote) {
if(newNote) {
// 更新之前的, 要先从服务器上得到服务版的
// 这里的note是本地的, 所以将服务器上的覆盖它
if(!Api) {
Api = require('api');
}
Api.getNote(note.ServerNoteId, function(serverNote) {
serverNote.ServerNoteId = serverNote.NoteId;
serverNote.NoteId = note.NoteId;
console.error("changeConflicts -> get note from server");
console.log(serverNote);
console.log(note);
me.updateNoteForceForConflict(serverNote, function(note2) {
if(!note2) {
// 前端来处理, 全量sync时不用前端一个个处理
Web.fixSyncConflict(note2, newNote);
}
});
});
});
} else {
}
});
} else {
}
});
})(i);
}
// 服务器没有, 但是是发送更新的, 所以需要作为添加以后再send changes
if(noteSyncInfo.changeNeedAdds) {
var needAddNotes = noteSyncInfo.changeNeedAdds;
for(var i in needAddNotes) {
log('need add ');
console.log('need add ');
var note = needAddNotes[i];
me.setIsNew(note.NoteId);
}
@@ -947,13 +956,12 @@ var Note = {
// 处理添加的
var addNotes = noteSyncInfo.adds;
log('has add...');
log(addNotes);
console.log('has add...');
console.log(addNotes);
Web.addSyncNote(addNotes);
log('has updates...');
log(noteSyncInfo);
log(noteSyncInfo.updates);
console.log('has updates...');
console.log(noteSyncInfo.updates);
// 处理更新的
Web.updateSyncNote(noteSyncInfo.updates);