dmails: allow marking dmails as unread.

* Add ability to mark dmails as unread.
* Fix users.unread_dmail_count to not count deleted dmails.
* Fix show action so that API calls don't mark dmails as read.
* Don't show the unread dmail notice on the /dmails page itself.
* Stop using users.has_mail flag.
This commit is contained in:
evazion
2020-01-31 15:47:58 -06:00
parent 067c6a10e7
commit 6468df6d44
12 changed files with 107 additions and 50 deletions

View File

@@ -1,4 +1,16 @@
module UsersHelper
def unread_dmail_indicator(user)
"(#{user.unread_dmail_count})" if user.unread_dmail_count > 0
end
def has_unread_dmails?(user)
user.unread_dmail_count > 0 && (cookies[:hide_dmail_notice].to_i < latest_unread_dmail(user).id)
end
def latest_unread_dmail(user)
user.dmails.active.unread.first
end
def email_sig(user)
verifier = ActiveSupport::MessageVerifier.new(Danbooru.config.email_key, serializer: JSON, digest: "SHA256")
verifier.generate(user.id.to_s)