Skip to content
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

Merged
merged 10 commits into from
Sep 11, 2017
Merged

Conversation

romanofski
Copy link
Member

No description provided.

Nothing -> pure $ Left ("Tags are corrupt")
Just nmtags ->
bracket
(databaseOpen dbpath >>= either (error . show) pure)
Copy link
Member Author

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.

Copy link
Member

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)

Copy link
Member Author

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.

@romanofski
Copy link
Member Author

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.

@romanofski
Copy link
Member Author

Hm.. I've got trouble building hs-notmuch now (see travis error). I actually ran into the same error locally as well, but I was unable to reproduce it 100%. In case you know what's going on on top of year head please share :))

@frasertweedale
Copy link
Member

frasertweedale commented Sep 4, 2017

@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 databaseDestroy though.

@romanofski
Copy link
Member Author

@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.

@frasertweedale
Copy link
Member

frasertweedale commented Sep 5, 2017

@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

@frasertweedale
Copy link
Member

@romanofski well I didn't quite get it done today. But the changes are well on the way. Hopefully Wednseday.

@frasertweedale
Copy link
Member

@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.

@romanofski
Copy link
Member Author

Does it build?

@romanofski
Copy link
Member Author

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"

@romanofski
Copy link
Member Author

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.
@romanofski
Copy link
Member Author

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.

Copy link
Member

@frasertweedale frasertweedale left a 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.

>>= messages
mails <- liftIO $ mapM messageToMail msgs
return $ Vec.fromList mails
) >>= pure . either (Left . show) pure
Copy link
Member

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)

Copy link
Member

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).

Copy link
Member Author

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?

Copy link
Member Author

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.

Copy link
Member

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)
Copy link
Member

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.

addTag :: NotmuchMail -> T.Text -> NotmuchMail
addTag m t =
let xs = view mailTags m
in set mailTags (xs `union` [t]) m
Copy link
Member

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)

Copy link
Member Author

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.

:: HasTags (Message n RO)
=> Message n RO
:: HasTags (Message n a)
=> Message n a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

in do setNotmuchMailTags dbpath (op m newTag)
>>= either
(\err -> pure $ s & asError ?~ err)
(pure . updateMailInList s)
Copy link
Member

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)

Copy link
Member Author

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
@romanofski romanofski force-pushed the automatic_mark_mail_as_read branch 2 times, most recently from 8538e4e to 774a519 Compare September 10, 2017 10:41
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.
getMessages s settings =
first show <$>
bracket (runExceptT (databaseOpenReadOnly (view nmDatabase settings))
>>= either (error . show) pure)
Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave for now.

@romanofski
Copy link
Member Author

Alright this should be it. I've added a bunch of fix up patches as well and an acceptance test.

@frasertweedale frasertweedale merged commit 76039d3 into master Sep 11, 2017
@frasertweedale frasertweedale deleted the automatic_mark_mail_as_read branch September 28, 2017 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants