From f69487f562a7088db8a4dd7e23cf842dd9d7cccc Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 28 Dec 2022 11:14:27 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=B9=E8=BF=9B=E9=97=AA=E5=8D=A1?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=20https://github.com/siyuan-note/siyuan/issu?= =?UTF-8?q?es/6928?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/go.mod | 3 ++- kernel/go.sum | 4 ++-- kernel/model/flashcard.go | 29 +++++++++++++++++++++++------ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index 4edd40ca4..7d92d53ca 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -45,7 +45,7 @@ require ( github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8 github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a - github.com/siyuan-note/riff v0.0.0-20221223145438-041dea8f7945 + github.com/siyuan-note/riff v0.0.0-20221228031102-17d458a1217b github.com/steambap/captcha v1.4.1 github.com/studio-b12/gowebdav v0.0.0-20221109171924-60ec5ad56012 github.com/vmihailenco/msgpack/v5 v5.3.5 @@ -134,6 +134,7 @@ require ( replace github.com/mattn/go-sqlite3 => github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 //replace github.com/siyuan-note/dejavu => D:\88250\dejavu +//replace github.com/siyuan-note/riff => D:\88250\riff //replace github.com/siyuan-note/httpclient => D:\88250\httpclient //replace github.com/siyuan-note/filelock => D:\88250\filelock //replace github.com/88250/lute => D:\gogogo\src\github.com\88250\lute diff --git a/kernel/go.sum b/kernel/go.sum index dd11d8fc8..d1f5bcca3 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -385,8 +385,8 @@ github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8 h1:cv0U38yu github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8/go.mod h1:aLj3LQVz2iuA3AUfkqk1UvPhqafRpthAVtjV1+ZAq+U= github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a h1:b9VJCE8IccYjsadwNBI11he+Wn25hI9lCma4uYoIYEM= github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a/go.mod h1:t1zRGxK13L/9ZFoGyTD39IbFCbee3CsypDj4b5dt4qM= -github.com/siyuan-note/riff v0.0.0-20221223145438-041dea8f7945 h1:ED7QFLeOu5/PpXK1v0ax82MJrhpgPrxkq6UEhIEOnFA= -github.com/siyuan-note/riff v0.0.0-20221223145438-041dea8f7945/go.mod h1:WnNt0JPjfXp2fjAgbF9rS5W7JC2W0YVcaVmLXIeYF8A= +github.com/siyuan-note/riff v0.0.0-20221228031102-17d458a1217b h1:JDpKOdiyocNsgKFfrF3mB7UoBJz4qcHBUKBig78kVjc= +github.com/siyuan-note/riff v0.0.0-20221228031102-17d458a1217b/go.mod h1:WnNt0JPjfXp2fjAgbF9rS5W7JC2W0YVcaVmLXIeYF8A= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY= diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index 94369a4ab..dc2d75603 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -28,6 +28,7 @@ import ( "github.com/88250/lute" "github.com/88250/lute/ast" "github.com/88250/lute/parse" + "github.com/dustin/go-humanize" "github.com/siyuan-note/logging" "github.com/siyuan-note/riff" "github.com/siyuan-note/siyuan/kernel/cache" @@ -78,8 +79,9 @@ func ReviewFlashcard(deckID string, blockID string, rating riff.Rating) (err err } type Flashcard struct { - DeckID string `json:"deckID"` - BlockID string `json:"blockID"` + DeckID string `json:"deckID"` + BlockID string `json:"blockID"` + NextDues map[riff.Rating]string `json:"nextDues"` } func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) { @@ -97,15 +99,23 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) { deck := Decks[deckID] cards := deck.Dues() + now := time.Now() for _, card := range cards { blockID := card.BlockID() if nil == treenode.GetBlockTree(blockID) { continue } + + nextDues := map[riff.Rating]string{} + for rating, due := range card.NextDues() { + nextDues[rating] = strings.TrimSpace(humanize.RelTime(due, now, "", "")) + } + ret = append(ret, &Flashcard{ - DeckID: deckID, - BlockID: blockID, + DeckID: deckID, + BlockID: blockID, + NextDues: nextDues, }) } if 1 > len(ret) { @@ -116,6 +126,7 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) { func getAllDueFlashcards() (ret []*Flashcard, err error) { blockIDs := map[string]bool{} + now := time.Now() for _, deck := range Decks { cards := deck.Dues() for _, card := range cards { @@ -128,9 +139,15 @@ func getAllDueFlashcards() (ret []*Flashcard, err error) { continue } + nextDues := map[riff.Rating]string{} + for rating, due := range card.NextDues() { + nextDues[rating] = strings.TrimSpace(humanize.RelTime(due, now, "", "")) + } + ret = append(ret, &Flashcard{ - DeckID: deck.ID, - BlockID: blockID, + DeckID: deck.ID, + BlockID: blockID, + NextDues: nextDues, }) blockIDs[blockID] = true }