diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index d0509e3..477c07f 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -21,7 +21,7 @@ class ArticlesController < ApplicationController def show raise AccessError unless @article.can_show? cuser - @article.read_by! cuser if cuser + cuser.mark_as_read(@article) if cuser # @article.record_view_count(request.remote_ip, cuser.nil?) end diff --git a/app/models/article.rb b/app/models/article.rb index 314793f..52ab126 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -69,7 +69,7 @@ class Article < ActiveRecord::Base after_destroy :remove_readings has_view_count - acts_as_reader + acts_as_readable acts_as_versioned non_versioned_columns << 'category_id' diff --git a/app/models/category.rb b/app/models/category.rb index 2bc42d3..ab8fbb1 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -48,7 +48,7 @@ class Category < ActiveRecord::Base has_many :gathers has_many :servers - acts_as_reader + acts_as_readable def to_s name diff --git a/app/models/forum.rb b/app/models/forum.rb index 72fd341..dc34308 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -34,7 +34,7 @@ class Forum < ActiveRecord::Base after_create :update_position - acts_as_reader + acts_as_readable def to_s self.title diff --git a/app/models/issue.rb b/app/models/issue.rb index a279781..887e3d7 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -35,10 +35,10 @@ class Issue < ActiveRecord::Base belongs_to :author, :class_name => "User" belongs_to :assigned, :class_name => "User" - scope :unread_by, - lambda { |user| { - :joins => "LEFT JOIN readings ON readable_type = 'Issue' AND readable_id = issues.id AND readings.user_id = #{user.id}", - :conditions => "readings.user_id IS NULL"} } + #scope :unread_by, + # lambda { |user| { + # :joins => "LEFT JOIN readings ON readable_type = 'Issue' AND readable_id = issues.id AND readings.user_id = #{user.id}", + # :conditions => "readings.user_id IS NULL"} } scope :with_status, -> (s) { where(status: s) } validates_length_of :title, :in => 1..50 @@ -49,7 +49,7 @@ class Issue < ActiveRecord::Base before_save :parse_text after_save :remove_readings - acts_as_reader + acts_as_readable def to_s title diff --git a/app/models/message.rb b/app/models/message.rb index c288b10..c91aeb2 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -24,12 +24,12 @@ class Message < ActiveRecord::Base validates_length_of :text, :in => 1..65000 scope :ordered, :order => "created_at DESC" - scope :read_by, - lambda { |user| {:include => :readings, :conditions => ["readings.user_id = ?", user.id]} } - scope :unread_by, - lambda { |user| { - :joins => "LEFT JOIN readings ON readable_type = 'Message' AND readable_id = messages.id AND readings.user_id = #{user.id}", - :conditions => "readings.user_id IS NULL"} } + #scope :read_by, + # lambda { |user| {:include => :readings, :conditions => ["readings.user_id = ?", user.id]} } + #scope :unread_by, + # lambda { |user| { + # :joins => "LEFT JOIN readings ON readable_type = 'Message' AND readable_id = messages.id AND readings.user_id = #{user.id}", + # :conditions => "readings.user_id IS NULL"} } belongs_to :sender, :polymorphic => true belongs_to :recipient, :polymorphic => true @@ -37,7 +37,7 @@ class Message < ActiveRecord::Base before_save :parse_text after_create :send_notifications - acts_as_reader + acts_as_readable def to_s title diff --git a/app/models/movie.rb b/app/models/movie.rb index bce92e4..d834d0e 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -62,7 +62,7 @@ class Movie < ActiveRecord::Base mount_uploader :picture, MovieUploader has_view_count - acts_as_reader + acts_as_readable def to_s file.to_s diff --git a/app/models/topic.rb b/app/models/topic.rb index ac2e1df..84dc60a 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -39,7 +39,7 @@ class Topic < ActiveRecord::Base after_create :make_post - acts_as_reader + acts_as_readable def self.recent_topics find_by_sql %q{ diff --git a/app/models/user.rb b/app/models/user.rb index 4ecc4aa..b530d7f 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -119,6 +119,8 @@ class User < ActiveRecord::Base accepts_nested_attributes_for :profile + acts_as_reader + acts_as_versioned non_versioned_columns << 'firstname' non_versioned_columns << 'lastname' diff --git a/app/views/articles/index.html.erb b/app/views/articles/index.html.erb index b2c2ae7..06a2f8f 100644 --- a/app/views/articles/index.html.erb +++ b/app/views/articles/index.html.erb @@ -8,7 +8,7 @@ <% category.articles.nodrafts.ordered.each do |article| %>
- <% if cuser and !article.read_by? cuser %> + <% if cuser and !cuser.have_read?(article) %> NEW <% end %> diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index eaedf73..da77de2 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -19,7 +19,7 @@ <% forums.each do |forum| %> - +
<%= namelink(forum) %>
<%= forum.description %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index 4b3da2b..b8e813e 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -65,7 +65,7 @@ <%= form_for @lock do |f| %> <%= f.hidden_field :lockable_type %> <%= f.hidden_field :lockable_id %> - <%= link_to_function "Lock", "this.parentNode.submit()", class: 'button' %> + <%= link_to "Lock", "#", class: 'button submitButton' %> <% end %> <% elsif @lock.can_destroy? cuser %> <%= link_to 'Unlock', @lock, class: 'button', confirm: 'Are you sure?', method: :delete %> diff --git a/db/migrate/20200315183444_unread_migration.rb b/db/migrate/20200315183444_unread_migration.rb new file mode 100644 index 0000000..098a51c --- /dev/null +++ b/db/migrate/20200315183444_unread_migration.rb @@ -0,0 +1,24 @@ +class UnreadMigration < Unread::MIGRATION_BASE_CLASS + def self.up + create_table ReadMark, force: true, options: create_options do |t| + t.references :readable, polymorphic: { null: false } + t.references :reader, polymorphic: { null: false } + t.datetime :timestamp + end + + add_index ReadMark, [:reader_id, :reader_type, :readable_type, :readable_id], name: 'read_marks_reader_readable_index', unique: true + end + + def self.down + drop_table ReadMark + end + + def self.create_options + options = '' + if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) \ + && ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) + options = 'DEFAULT CHARSET=latin1' + end + options + end +end diff --git a/db/schema.rb b/db/schema.rb index 99ed8a2..b7a8362 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20200315144657) do +ActiveRecord::Schema.define(version: 20200315183444) do create_table "article_versions", force: true do |t| t.integer "article_id" @@ -633,6 +633,16 @@ ActiveRecord::Schema.define(version: 20200315144657) do add_index "ratings", ["rate_id"], name: "index_ratings_on_rate_id", using: :btree add_index "ratings", ["rateable_id", "rateable_type"], name: "index_ratings_on_rateable_id_and_rateable_type", using: :btree + create_table "read_marks", force: true do |t| + t.integer "readable_id" + t.string "readable_type", null: false + t.integer "reader_id" + t.string "reader_type", null: false + t.datetime "timestamp" + end + + add_index "read_marks", ["reader_id", "reader_type", "readable_type", "readable_id"], name: "read_marks_reader_readable_index", unique: true, using: :btree + create_table "readings", force: true do |t| t.string "readable_type" t.integer "readable_id"