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

@@ -25,11 +25,18 @@
<%= link_to dmail.title, dmail_path(dmail) %>
<% end %>
<% t.column do |dmail| %>
<% if dmail.is_read? %>
<%= link_to "Unread", dmail_path(dmail, format: :js), remote: true, method: :put, "data-params": "dmail[is_read]=false" %>
<% else %>
<%= link_to "Read", dmail_path(dmail, format: :js), remote: true, method: :put, "data-params": "dmail[is_read]=true" %>
<% end %>
|
<% if dmail.is_deleted? %>
<%= link_to "Undelete", dmail_path(dmail, format: :js), remote: true, method: :put, "data-params": "dmail[is_deleted]=false" %>
<% else %>
<%= link_to "Delete", dmail_path(dmail, format: :js), remote: true, method: :put, "data-params": "dmail[is_deleted]=true", "data-confirm": "Are you sure you want to delete this dmail?" %>
<% end %>
<% if dmail.reportable_by?(CurrentUser.user) %>
| <%= link_to "Report", new_moderation_report_path(moderation_report: { model_type: "Dmail", model_id: dmail.id }), remote: true, title: "Report this dmail to the moderators" %>
<% end %>

View File

@@ -2,7 +2,7 @@
<% if CurrentUser.is_anonymous? %>
<%= nav_link_to("Login", login_path) %>
<% else %>
<%= nav_link_to("My Account #{CurrentUser.dmail_count}", profile_path) %>
<%= nav_link_to("My Account #{unread_dmail_indicator(CurrentUser.user)}", profile_path) %>
<% end %>
<%= nav_link_to("Posts", posts_path) %>
<%= nav_link_to("Comments", comments_path(:group_by => "post")) %>

View File

@@ -118,7 +118,7 @@
<%= render "users/ban_notice" %>
<% end %>
<% if CurrentUser.has_mail? && CurrentUser.dmails.unread.first.present? && (cookies[:hide_dmail_notice].blank? || cookies[:hide_dmail_notice].to_i < CurrentUser.dmails.unread.first.id) %>
<% if params[:controller] != "dmails" && has_unread_dmails?(CurrentUser.user) %>
<%= render "users/dmail_notice" %>
<% end %>

View File

@@ -127,7 +127,7 @@
<li><%= link_to "Change name", new_user_name_change_request_path %></li>
<% end %>
<li><%= link_to "Delete account", maintenance_user_deletion_path %></li>
<li><%= link_to "Dmails", dmails_path %></li>
<li><%= link_to "Dmails", dmails_path(search: { folder: "received" }) %></li>
<li><%= link_to "Favorites", favorites_path %></li>
<li><%= link_to "Favorite groups", favorite_groups_path %></li>
<li><%= link_to "Saved searches", saved_searches_path %></li>

View File

@@ -1,4 +1,4 @@
<div class="notice notice-info notice-large" id="dmail-notice" data-id="<%= CurrentUser.dmails.unread.first.id %>">
<h2>You have <%= link_to "unread mail", dmails_path(search: {owner_id: CurrentUser.id, to_id: CurrentUser.id}, folder: "received") %>.</h2>
<div class="notice notice-info notice-large" id="dmail-notice" data-id="<%= latest_unread_dmail(CurrentUser.user) %>">
<h2>You have <%= link_to "unread mail", dmails_path(search: { folder: "received" }) %>.</h2>
<div><%= link_to "Close this", "#", id: "hide-dmail-notice" %></div>
</div>

View File

@@ -12,7 +12,7 @@
<% if @user.id == CurrentUser.user.id %>
<%= subnav_link_to "Profile", profile_path %>
<%= subnav_link_to "Settings", settings_path %>
<%= subnav_link_to "Messages #{CurrentUser.user.dmail_count}", dmails_path %>
<%= subnav_link_to "Messages #{unread_dmail_indicator(CurrentUser.user)}", dmails_path(search: { folder: "received" }) %>
<% if !@user.is_platinum? %>
<%= subnav_link_to "Upgrade", new_user_upgrade_path %>