diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-08-08 22:21:41 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-08-22 09:30:37 +0200 |
commit | cfc19a7ec22a1c60f79427ddbabdf437705efbab (patch) | |
tree | fbc4d54f9edb082ff87c84f864df17514c8e34da /widgets | |
parent | ee961d3b1d5ef412b3daf0ef0b8c18ac8957b365 (diff) | |
download | aerc-cfc19a7ec22a1c60f79427ddbabdf437705efbab.tar.gz |
store: extract marking behavior and add tests
Separate the marking functions from the message store and extract the
marking behavior into its own class with tests.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/account.go | 8 | ||||
-rw-r--r-- | widgets/msglist.go | 6 | ||||
-rw-r--r-- | widgets/msgviewer.go | 3 |
3 files changed, 10 insertions, 7 deletions
diff --git a/widgets/account.go b/widgets/account.go index ceb8d98e..b92a619d 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -9,6 +9,7 @@ import ( "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/lib/marker" "git.sr.ht/~rjarry/aerc/lib/sort" "git.sr.ht/~rjarry/aerc/lib/statusline" "git.sr.ht/~rjarry/aerc/lib/ui" @@ -222,8 +223,10 @@ func (acct *AccountView) SelectedMessage() (*models.MessageInfo, error) { } func (acct *AccountView) MarkedMessages() ([]uint32, error) { - store := acct.Store() - return store.Marked(), nil + if store := acct.Store(); store != nil { + return store.Marker().Marked(), nil + } + return nil, errors.New("no store available") } func (acct *AccountView) SelectedMessagePart() *PartInfo { @@ -301,6 +304,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { acct.host.Beep() } }) + store.SetMarker(marker.New(store)) acct.dirlist.SetMsgStore(msg.Info.Name, store) } case *types.DirectoryContents: diff --git a/widgets/msglist.go b/widgets/msglist.go index e431c2e5..e505608a 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -122,7 +122,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) { AccountName: acct.Name(), MsgInfo: msg, MsgNum: row, - MsgIsMarked: store.IsMarked(t.Uid), + MsgIsMarked: store.Marker().IsMarked(t.Uid), ThreadPrefix: prefix, ThreadSameSubject: normalizedSubject == lastSubject, } @@ -150,7 +150,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) { AccountName: acct.Name(), MsgInfo: msg, MsgNum: row, - MsgIsMarked: store.IsMarked(uid), + MsgIsMarked: store.Marker().IsMarked(uid), } if ml.drawRow(textWidth, ctx, uid, row, &needsHeaders, fmtCtx) { break @@ -244,7 +244,7 @@ func (ml *MessageList) drawRow(textWidth int, ctx *ui.Context, uid uint32, row i } // marked message - if store.IsMarked(msg.Uid) { + if store.Marker().IsMarked(msg.Uid) { msg_styles = append(msg_styles, config.STYLE_MSGLIST_MARKED) } diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 70ff5d8f..cd0c9371 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -302,8 +302,7 @@ func (mv *MessageViewer) SelectedMessage() (*models.MessageInfo, error) { } func (mv *MessageViewer) MarkedMessages() ([]uint32, error) { - store := mv.Store() - return store.Marked(), nil + return mv.acct.MarkedMessages() } func (mv *MessageViewer) ToggleHeaders() { |