// 修改笔记本内容
// [ok] TODO perm未测
// hasBeforeUpdateNote 之前是否更新过note其它信息, 如果有更新, usn不用更新
// TODO abstract这里生成
func (this *NoteService) UpdateNoteContent(updatedUserId, noteId, content, abstract string, hasBeforeUpdateNote bool, usn int) (bool, string, int) {
	// 是否已自定义
	note := this.GetNoteById(noteId)
	if note.NoteId == "" {
		return false, "notExists", 0
	}
	userId := note.UserId.Hex()
	// updatedUserId 要修改userId的note, 此时需要判断是否有修改权限
	if userId != updatedUserId {
		if !shareService.HasUpdatePerm(userId, updatedUserId, noteId) {
			Log("NO AUTH")
			return false, "noAuth", 0
		}
	}

	// abstract重置
	data := bson.M{"UpdatedUserId": bson.ObjectIdHex(updatedUserId),
		"Content":     content,
		"Abstract":    abstract,
		"UpdatedTime": time.Now()}

	if note.IsBlog && note.HasSelfDefined {
		delete(data, "Abstract")
	}

	// usn, 修改笔记不可能单独修改内容
	afterUsn := 0
	// 如果之前没有修改note其它信息, 那么usn++
	if !hasBeforeUpdateNote {
		// 需要验证
		if usn >= 0 && note.Usn != usn {
			return false, "conflict", 0
		}
		afterUsn = userService.IncrUsn(userId)
		db.UpdateByIdAndUserIdField(db.Notes, noteId, userId, "Usn", usn)
	}

	if db.UpdateByIdAndUserIdMap(db.NoteContents, noteId, userId, data) {
		// 这里, 添加历史记录
		noteContentHistoryService.AddHistory(noteId, userId, info.EachHistory{UpdatedUserId: bson.ObjectIdHex(updatedUserId),
			Content:     content,
			UpdatedTime: time.Now(),
		})

		// 更新笔记图片
		noteImageService.UpdateNoteImages(userId, noteId, note.ImgSrc, content)

		return true, "", afterUsn
	}
	return false, "", 0
}
// 修改group标题
func (this *GroupService) UpdateGroupTitle(userId, groupId, title string) (ok bool) {
	return db.UpdateByIdAndUserIdField(db.Groups, groupId, userId, "Title", title)
}
func (this *FileService) UpdateImageTitle(userId, fileId, title string) bool {
	return db.UpdateByIdAndUserIdField(db.Files, fileId, userId, "Title", title)
}
// update album name
func (this *AlbumService) UpdateAlbum(albumId, userId, name string) bool {
	return db.UpdateByIdAndUserIdField(db.Albums, albumId, userId, "Name", name)
}