-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic mark mail as read #56
Conversation
src/Storage/Notmuch.hs
Outdated
Nothing -> pure $ Left ("Tags are corrupt") | ||
Just nmtags -> | ||
bracket | ||
(databaseOpen dbpath >>= either (error . show) pure) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fiddled with the error
here. This would obviously crash, but the Type expected in IO is always (Database RW), but I'm puzzled, since I thought the first function handles the Left value, which is String
. What I want is to give an error back, rather than... well just crashing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're going to need to start using MonadError monad transformer to be able to better manage IO-with-error scenarios. For now leave it as-is and I'll address in a later commit (just add a FIXME comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved it in a backlog item... when we have the time.
Travis died as well with the change. Will have to investigate. Wouldn't be surprised if it has something to do with the old, but stable version of Ubuntu sigh. I'm also thinking of adding one additional acceptance test to check if toggling works. Not sure if it will run in Travis tho, since I've noticed that I dealt with different escape sequences to assert e.g. text is bold or not. |
0eb3ce7
to
8cb6254
Compare
Hm.. I've got trouble building |
@romanofski there are breaking API changes in notmuch v0.25 :( Might take a little while to sort out. edit: can probably fix it tomorrow. An old-ish version of libnotmuch (0.17) is used in Ubuntu trusty though. Fortunately there's only one incompatibility there though. I'll have to change the type of |
@frasertweedale I'd be happy to add in a .travis and stack.yml file. stack just because most of the infrastructure is now build around it, including ready-made files for testing against several platforms/GHC. |
@romanofski IMO the "correct" approach for hs-notmuch is to determine which versions of notmuch we want to support, and have CI that checks out every single release, builds libnotmuch, then builds hs-notmuch against it. But that's a task for another day. edit: created purebred-mua/hs-notmuch#13 |
@romanofski well I didn't quite get it done today. But the changes are well on the way. Hopefully Wednseday. |
@romanofski new hs-notmuch commit which should hopefully fix CI issues, add support for notmuch-0.25, and introduces the monad transformer for dealing with errors. Lots of API changes, you will have fun chasing this. purebred-mua/hs-notmuch@5bc75a6 The most important function you'll need to perform the refactor/rebase is https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Except.html#v:runExceptT. |
8cb6254
to
f5639d7
Compare
Does it build? |
Meh now I realize that I've squashed my changes against latest hs-notmuch just with the parent. Should have perhaps fiddled it into the separate patches :/ Could probably do that with a few items I still want to "clean up" |
Alright doesn't build... perhaps we should yank hs-notmuch into travis first ... |
This is needed to later lookup the message again.
This is needed to later lookup the message again.
Instead of keeping a persistent attribute, make the decision to draw a mail as "unread" during rendering.
f5639d7
to
399c02b
Compare
I think I'm getting there to where I want to have this and you can start having a look. I think the intermittend test failures are caused by unstable search results, since the maildir I'm using exposes two mails with different content. That's why I created purebred-mua/hs-notmuch#15 Anyway, have a look and tell me what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits. One kinda important thing. Haven't tested yet.
src/Storage/Notmuch.hs
Outdated
>>= messages | ||
mails <- liftIO $ mapM messageToMail msgs | ||
return $ Vec.fromList mails | ||
) >>= pure . either (Left . show) pure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of
runExceptT (k) >>= pure . either (Left . show) pure
Why not:
first show <$> runExceptT (k)
(Data.Bifunctor.first
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, does getMessages
run multiple times? Either we should open the database somewhere else and pass it around, or you should use databaseDestroy
to close the database after each use (otherwise we leak memory
and probably other resources).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for the review. Yes getMessages
is used a few times, certainly every time when you changes the search. Would it make sense to open the database with the config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One other thing which comes to my mind is using (resourceT)[https://hackage.haskell.org/package/resourcet] on the client side, to always close the database ... Currently I'd be leaning towards the resourcet approach and always closing the database after reading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResourceT, maybe. Let's not do it in this rebase. Something to look at after perhaps.
Just nmtags -> | ||
bracket (runExceptT (databaseOpen dbpath) >>= either (error . show) pure) | ||
(void . runExceptT . databaseDestroy) | ||
(\db -> tagsToMessage nmtags m db) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, bracket
is a bit awkward because it forces IO
; the transformer is unhelpful here :/
Not much we can do about it right now.
src/Storage/Notmuch.hs
Outdated
addTag :: NotmuchMail -> T.Text -> NotmuchMail | ||
addTag m t = | ||
let xs = view mailTags m | ||
in set mailTags (xs `union` [t]) m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nicer to use over
here (also in removeTag
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes.. much, much better!! Cheers for that.
src/Storage/Notmuch.hs
Outdated
:: HasTags (Message n RO) | ||
=> Message n RO | ||
:: HasTags (Message n a) | ||
=> Message n a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/UI/Index/Keybindings.hs
Outdated
in do setNotmuchMailTags dbpath (op m newTag) | ||
>>= either | ||
(\err -> pure $ s & asError ?~ err) | ||
(pure . updateMailInList s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps the following instead of (>>=)
either (\err -> set asError (Just err) s) (updateMailInList s)
<$> setNotmuchMailTags dbpath (op m newTag)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Cheers.
This adds functionality to automatically set e-mail as `read` as well as allowing to toggle the mail back into the 'unread' state. Currently the Keybinding to toggle unread is set to `t` (for toggle). Issue: #53
8538e4e
to
774a519
Compare
This includes a small re-factoring of moving all defined style attributes into the config, which will make it easier to define themes in the future.
Allow easier debugging by running the tests with a "DEBUG=1" environment variable, which prints all captured output to STDERR.
Using the new debug mode, capture all STDERR output into a log file and print it after all tests are run. This will hopefully make it easier to debug failures.
This fixes an intermittently breaking test, which has a timing problem. The test driver waits for a string which is already present on the screen capture which results not in waiting for a re-draw. Since the body is not shown when all headers are visible, we use the string in the mail body to wait for to circumvent the timing problem.
774a519
to
76039d3
Compare
getMessages s settings = | ||
first show <$> | ||
bracket (runExceptT (databaseOpenReadOnly (view nmDatabase settings)) | ||
>>= either (error . show) pure) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still not right IMHO... it would currently crash the application if I wouldn't be able the open the database properly. Arguably that's pretty bad in itself, but perhaps the application shouldn't crash. Same for the function which opens the database RW for tagging. Any suggestions or leave it for now and keep a backlog item.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave for now.
Alright this should be it. I've added a bunch of fix up patches as well and an acceptance test. |
No description provided.