diff options
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/account.go | 8 | ||||
-rw-r--r-- | widgets/msgviewer.go | 8 | ||||
-rw-r--r-- | widgets/providesmessage.go | 2 |
3 files changed, 13 insertions, 5 deletions
diff --git a/widgets/account.go b/widgets/account.go index e08a2537..981a143a 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -1,6 +1,7 @@ package widgets import ( + "errors" "fmt" "log" @@ -170,8 +171,11 @@ func (acct *AccountView) SelectedAccount() *AccountView { return acct } -func (acct *AccountView) SelectedMessage() *models.MessageInfo { - return acct.msglist.Selected() +func (acct *AccountView) SelectedMessage() (*models.MessageInfo, error) { + if len(acct.msglist.Store().Uids) == 0 { + return nil, errors.New("no message selected") + } + return acct.msglist.Selected(), nil } func (acct *AccountView) SelectedMessagePart() *PartInfo { diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index f6bef2d8..f15fbae4 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -2,6 +2,7 @@ package widgets import ( "bufio" + "errors" "fmt" "io" "os/exec" @@ -211,8 +212,11 @@ func (mv *MessageViewer) SelectedAccount() *AccountView { return mv.acct } -func (mv *MessageViewer) SelectedMessage() *models.MessageInfo { - return mv.msg +func (mv *MessageViewer) SelectedMessage() (*models.MessageInfo, error) { + if mv.msg == nil { + return nil, errors.New("no message selected") + } + return mv.msg, nil } func (mv *MessageViewer) ToggleHeaders() { diff --git a/widgets/providesmessage.go b/widgets/providesmessage.go index a1cfaa8f..34b90112 100644 --- a/widgets/providesmessage.go +++ b/widgets/providesmessage.go @@ -17,6 +17,6 @@ type ProvidesMessage interface { ui.Drawable Store() *lib.MessageStore SelectedAccount() *AccountView - SelectedMessage() *models.MessageInfo + SelectedMessage() (*models.MessageInfo, error) SelectedMessagePart() *PartInfo } |