已删除的笔记还显示 #226
This commit is contained in:
@ -45,7 +45,9 @@ func (this *BlogService) GetBlogByIdAndUrlTitle(userId string, noteIdOrUrlTitle
|
|||||||
return this.GetBlog(noteIdOrUrlTitle)
|
return this.GetBlog(noteIdOrUrlTitle)
|
||||||
}
|
}
|
||||||
note := info.Note{}
|
note := info.Note{}
|
||||||
db.GetByQ(db.Notes, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(noteIdOrUrlTitle), "IsBlog": true, "IsTrash": false}, ¬e)
|
db.GetByQ(db.Notes, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(noteIdOrUrlTitle),
|
||||||
|
"IsBlog": true,
|
||||||
|
"IsTrash": false, "IsDeleted": false}, ¬e)
|
||||||
return this.GetBlogItem(note)
|
return this.GetBlogItem(note)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +58,7 @@ func (this *BlogService) GetBlog(noteId string) (blog info.BlogItem) {
|
|||||||
}
|
}
|
||||||
func (this *BlogService) GetBlogItem(note info.Note) (blog info.BlogItem) {
|
func (this *BlogService) GetBlogItem(note info.Note) (blog info.BlogItem) {
|
||||||
if note.NoteId == "" || !note.IsBlog {
|
if note.NoteId == "" || !note.IsBlog {
|
||||||
return
|
return info.BlogItem{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 内容
|
// 内容
|
||||||
@ -142,7 +144,7 @@ func (this *BlogService) ReCountBlogTags(userId string) bool {
|
|||||||
// 得到所有博客
|
// 得到所有博客
|
||||||
notes := []info.Note{}
|
notes := []info.Note{}
|
||||||
userIdO := bson.ObjectIdHex(userId)
|
userIdO := bson.ObjectIdHex(userId)
|
||||||
query := bson.M{"UserId": userIdO, "IsTrash": false, "IsBlog": true}
|
query := bson.M{"UserId": userIdO, "IsTrash": false, "IsDeleted": false, "IsBlog": true}
|
||||||
db.ListByQWithFields(db.Notes, query, []string{"Tags"}, ¬es)
|
db.ListByQWithFields(db.Notes, query, []string{"Tags"}, ¬es)
|
||||||
|
|
||||||
db.DeleteAll(db.TagCounts, bson.M{"UserId": userIdO, "IsBlog": true})
|
db.DeleteAll(db.TagCounts, bson.M{"UserId": userIdO, "IsBlog": true})
|
||||||
@ -184,7 +186,7 @@ Posts: []
|
|||||||
*/
|
*/
|
||||||
func (this *BlogService) ListBlogsArchive(userId, notebookId string, year, month int, sortField string, isAsc bool) []info.Archive {
|
func (this *BlogService) ListBlogsArchive(userId, notebookId string, year, month int, sortField string, isAsc bool) []info.Archive {
|
||||||
// _, notes := noteService.ListNotes(userId, notebookId, false, 1, 99999, sortField, isAsc, true);
|
// _, notes := noteService.ListNotes(userId, notebookId, false, 1, 99999, sortField, isAsc, true);
|
||||||
q := bson.M{"UserId": bson.ObjectIdHex(userId), "IsBlog": true, "IsTrash": false}
|
q := bson.M{"UserId": bson.ObjectIdHex(userId), "IsBlog": true, "IsTrash": false, "IsDeleted": false}
|
||||||
if notebookId != "" {
|
if notebookId != "" {
|
||||||
q["NotebookId"] = bson.ObjectIdHex(notebookId)
|
q["NotebookId"] = bson.ObjectIdHex(notebookId)
|
||||||
}
|
}
|
||||||
@ -291,9 +293,10 @@ func (this *BlogService) SearchBlogByTags(tags []string, userId string, pageNumb
|
|||||||
|
|
||||||
// 不是trash的
|
// 不是trash的
|
||||||
query := bson.M{"UserId": bson.ObjectIdHex(userId),
|
query := bson.M{"UserId": bson.ObjectIdHex(userId),
|
||||||
"IsTrash": false,
|
"IsTrash": false,
|
||||||
"IsBlog": true,
|
"IsDeleted": false,
|
||||||
"Tags": bson.M{"$all": tags}}
|
"IsBlog": true,
|
||||||
|
"Tags": bson.M{"$all": tags}}
|
||||||
|
|
||||||
q := db.Notes.Find(query)
|
q := db.Notes.Find(query)
|
||||||
|
|
||||||
@ -366,10 +369,10 @@ func (this *BlogService) PreNextBlog(userId string, sorterField string, isAsc bo
|
|||||||
if !isAsc {
|
if !isAsc {
|
||||||
// 降序
|
// 降序
|
||||||
/*
|
/*
|
||||||
------- pre
|
------- pre
|
||||||
----- now
|
----- now
|
||||||
--- next
|
--- next
|
||||||
--
|
--
|
||||||
*/
|
*/
|
||||||
// 上一篇时间要比它大, 找最小的
|
// 上一篇时间要比它大, 找最小的
|
||||||
sortFieldT1 = bson.M{"$gte": baseTime} // 为什么要相等, 因为将notebook发布成博客, 会统一修改note的publicTime, 此时所有notes都一样
|
sortFieldT1 = bson.M{"$gte": baseTime} // 为什么要相等, 因为将notebook发布成博客, 会统一修改note的publicTime, 此时所有notes都一样
|
||||||
@ -393,12 +396,14 @@ func (this *BlogService) PreNextBlog(userId string, sorterField string, isAsc bo
|
|||||||
sortFieldR2 = sorterField
|
sortFieldR2 = sorterField
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1
|
||||||
// 上一篇, 比基时间要小, 但是是最后一篇, 所以是降序
|
// 上一篇, 比基时间要小, 但是是最后一篇, 所以是降序
|
||||||
note := info.Note{}
|
note := info.Note{}
|
||||||
query := bson.M{"UserId": userIdO,
|
query := bson.M{"UserId": userIdO,
|
||||||
"IsTrash": false,
|
"IsTrash": false,
|
||||||
"IsBlog": true,
|
"IsDeleted": false,
|
||||||
"_id": bson.M{"$ne": bson.ObjectIdHex(noteId)},
|
"IsBlog": true,
|
||||||
|
"_id": bson.M{"$ne": bson.ObjectIdHex(noteId)},
|
||||||
sorterField: sortFieldT1,
|
sorterField: sortFieldT1,
|
||||||
}
|
}
|
||||||
q := db.Notes.Find(query)
|
q := db.Notes.Find(query)
|
||||||
@ -430,7 +435,7 @@ func (this *BlogService) ListAllBlogs(userId, tag string, keywords string, isRec
|
|||||||
skipNum, sortFieldR := parsePageAndSort(page, pageSize, sorterField, isAsc)
|
skipNum, sortFieldR := parsePageAndSort(page, pageSize, sorterField, isAsc)
|
||||||
|
|
||||||
// 不是trash的
|
// 不是trash的
|
||||||
query := bson.M{"IsTrash": false, "IsBlog": true, "Title": bson.M{"$ne": "欢迎来到leanote!"}}
|
query := bson.M{"IsTrash": false, "IsDeleted": false, "IsBlog": true, "Title": bson.M{"$ne": "欢迎来到leanote!"}}
|
||||||
if tag != "" {
|
if tag != "" {
|
||||||
query["Tags"] = bson.M{"$in": []string{tag}}
|
query["Tags"] = bson.M{"$in": []string{tag}}
|
||||||
}
|
}
|
||||||
@ -496,6 +501,9 @@ func (this *BlogService) ListAllBlogs(userId, tag string, keywords string, isRec
|
|||||||
content = noteContent.Abstract
|
content = noteContent.Abstract
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
if len(note.Tags) == 1 && note.Tags[0] == "" {
|
||||||
|
note.Tags = nil
|
||||||
|
}
|
||||||
blogs[i] = info.BlogItem{note, "", content, hasMore, userMap[note.UserId]}
|
blogs[i] = info.BlogItem{note, "", content, hasMore, userMap[note.UserId]}
|
||||||
}
|
}
|
||||||
pageInfo = info.NewPage(page, pageSize, count, nil)
|
pageInfo = info.NewPage(page, pageSize, count, nil)
|
||||||
|
@ -28,7 +28,8 @@ func (this *NoteService) GetNoteById(noteId string) (note info.Note) {
|
|||||||
// 不要传userId, 因为是公开的
|
// 不要传userId, 因为是公开的
|
||||||
func (this *NoteService) GetBlogNote(noteId string) (note info.Note) {
|
func (this *NoteService) GetBlogNote(noteId string) (note info.Note) {
|
||||||
note = info.Note{}
|
note = info.Note{}
|
||||||
db.GetByQ(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId), "IsBlog": true, "IsTrash": false}, ¬e)
|
db.GetByQ(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId),
|
||||||
|
"IsBlog": true, "IsTrash": false, "IsDeleted": false}, ¬e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 通过id, userId得到noteContent
|
// 通过id, userId得到noteContent
|
||||||
@ -734,6 +735,7 @@ func (this *NoteService) SearchNote(key, userId string, pageNumber, pageSize int
|
|||||||
// 不是trash的
|
// 不是trash的
|
||||||
query := bson.M{"UserId": bson.ObjectIdHex(userId),
|
query := bson.M{"UserId": bson.ObjectIdHex(userId),
|
||||||
"IsTrash": false,
|
"IsTrash": false,
|
||||||
|
"IsDeleted": false, // 不能搜索已删除了的
|
||||||
"$or": orQ,
|
"$or": orQ,
|
||||||
}
|
}
|
||||||
if isBlog {
|
if isBlog {
|
||||||
@ -819,14 +821,14 @@ func (this *NoteService) SearchNoteByTags(tags []string, userId string, pageNumb
|
|||||||
//------------
|
//------------
|
||||||
// 统计
|
// 统计
|
||||||
func (this *NoteService) CountNote(userId string) int {
|
func (this *NoteService) CountNote(userId string) int {
|
||||||
q := bson.M{"IsTrash": false}
|
q := bson.M{"IsTrash": false, "IsDeleted": false}
|
||||||
if userId != "" {
|
if userId != "" {
|
||||||
q["UserId"] = bson.ObjectIdHex(userId)
|
q["UserId"] = bson.ObjectIdHex(userId)
|
||||||
}
|
}
|
||||||
return db.Count(db.Notes, q)
|
return db.Count(db.Notes, q)
|
||||||
}
|
}
|
||||||
func (this *NoteService) CountBlog(userId string) int {
|
func (this *NoteService) CountBlog(userId string) int {
|
||||||
q := bson.M{"IsBlog": true, "IsTrash": false}
|
q := bson.M{"IsBlog": true, "IsTrash": false, "IsDeleted": false}
|
||||||
if userId != "" {
|
if userId != "" {
|
||||||
q["UserId"] = bson.ObjectIdHex(userId)
|
q["UserId"] = bson.ObjectIdHex(userId)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user