aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authordima2011-12-11 11:14:09 +0100
committerdima2011-12-11 11:14:09 +0100
commitc94547a6bab514e6df816e105f17311ba2ce73c9 (patch)
treec765206549958d0642698c891ed6c840805277bc /app
parent932790890a583cf877ef06a218316b82a7014b60 (diff)
downloadinboxes-c94547a6bab514e6df816e105f17311ba2ce73c9.tar.bz2
выводим количество непрочитанных сообщений в дискуссии
Diffstat (limited to 'app')
-rw-r--r--app/models/discussion.rb8
-rw-r--r--app/views/inboxes/discussions/index.html.haml4
2 files changed, 9 insertions, 3 deletions
diff --git a/app/models/discussion.rb b/app/models/discussion.rb
index 9e9a92c..7230538 100644
--- a/app/models/discussion.rb
+++ b/app/models/discussion.rb
@@ -84,6 +84,12 @@ class Discussion < ActiveRecord::Base
end
end
+ # return amount of unreaded messages for current discussion
+ def count_unread_mess(user)
+ speaker = find_speaker_by_user(user)
+ messages.where("updated_at > ?", speaker.updated_at ).where("user_id != ?", speaker.id ).count
+ end
+
def mark_as_read_for(user)
speaker = Speaker.find_or_create_by_user_id_and_discussion_id(user.id, self.id)
# flag.update_attributes(:updat => Time.zone.now)
@@ -100,4 +106,4 @@ class Discussion < ActiveRecord::Base
errors.add :recipient_tokens, t("inboxes.discussions.choose_at_least_one_recipient") if !self.recipient_ids || self.recipient_ids.size < 2
end
-end \ No newline at end of file
+end
diff --git a/app/views/inboxes/discussions/index.html.haml b/app/views/inboxes/discussions/index.html.haml
index 7e300d4..3d47a59 100644
--- a/app/views/inboxes/discussions/index.html.haml
+++ b/app/views/inboxes/discussions/index.html.haml
@@ -11,7 +11,7 @@
%td
= link_to discussion.users.collect{|u| u[Inboxes::config.user_name]}.join(', '), discussion
%td
- = discussion.unread_for?(current_user) ? "Yes" : "No"
+ = discussion.unread_for?(current_user) ? (discussion.count_unread_mess(current_user).to_s + ' сообщение') : "No"
%p
- = link_to "Create new", new_discussion_path \ No newline at end of file
+ = link_to "Create new", new_discussion_path