thredded 0.15.5 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -7
  3. data/app/assets/stylesheets/thredded/_thredded.scss +1 -0
  4. data/app/assets/stylesheets/thredded/components/_messageboard.scss +16 -3
  5. data/app/assets/stylesheets/thredded/utilities/_flex.scss +3 -0
  6. data/app/commands/thredded/mark_all_read.rb +3 -7
  7. data/app/controllers/thredded/messageboards_controller.rb +4 -1
  8. data/app/controllers/thredded/moderation_controller.rb +7 -2
  9. data/app/controllers/thredded/private_topics_controller.rb +1 -5
  10. data/app/controllers/thredded/theme_previews_controller.rb +5 -1
  11. data/app/controllers/thredded/topics_controller.rb +1 -1
  12. data/app/forms/thredded/post_form.rb +1 -1
  13. data/app/forms/thredded/private_post_form.rb +1 -1
  14. data/app/forms/thredded/private_topic_form.rb +2 -0
  15. data/app/forms/thredded/topic_form.rb +2 -1
  16. data/app/forms/thredded/user_preferences_form.rb +5 -1
  17. data/app/models/concerns/thredded/post_common.rb +10 -6
  18. data/app/models/concerns/thredded/topic_common.rb +4 -8
  19. data/app/models/concerns/thredded/user_topic_read_state_common.rb +56 -62
  20. data/app/models/thredded/messageboard.rb +27 -1
  21. data/app/models/thredded/post.rb +6 -0
  22. data/app/models/thredded/private_topic.rb +12 -2
  23. data/app/models/thredded/topic.rb +8 -3
  24. data/app/models/thredded/user_extender.rb +0 -7
  25. data/app/models/thredded/user_private_topic_read_state.rb +35 -0
  26. data/app/models/thredded/user_topic_read_state.rb +41 -0
  27. data/app/view_models/thredded/messageboard_group_view.rb +24 -7
  28. data/app/view_models/thredded/messageboard_view.rb +50 -0
  29. data/app/views/thredded/messageboards/_messageboard.html.erb +8 -18
  30. data/app/views/thredded/messageboards/index.html.erb +6 -1
  31. data/app/views/thredded/messageboards/messageboard/_description.html.erb +1 -0
  32. data/app/views/thredded/messageboards/messageboard/_header.html.erb +6 -0
  33. data/app/views/thredded/messageboards/messageboard/_last_updated.html.erb +7 -0
  34. data/app/views/thredded/messageboards/messageboard/_meta.html.erb +19 -0
  35. data/app/views/thredded/messageboards/messageboard/_unread_followed_topics_badge.html.erb +6 -0
  36. data/app/views/thredded/preferences/_messageboards_nav_item.html.erb +1 -1
  37. data/app/views/thredded/private_posts/_private_post.html.erb +1 -1
  38. data/app/views/thredded/theme_previews/show.html.erb +10 -4
  39. data/app/views/thredded/topics/_topic.html.erb +1 -1
  40. data/app/views/thredded/topics/unread.html.erb +1 -1
  41. data/config/locales/de.yml +1 -0
  42. data/config/locales/en.yml +2 -1
  43. data/config/locales/es.yml +1 -0
  44. data/config/locales/fr.yml +1 -0
  45. data/config/locales/it.yml +1 -0
  46. data/config/locales/pl.yml +1 -0
  47. data/config/locales/pt-BR.yml +1 -0
  48. data/config/locales/ru.yml +1 -0
  49. data/config/locales/zh-CN.yml +1 -0
  50. data/db/migrate/20160329231848_create_thredded.rb +5 -0
  51. data/db/upgrade_migrations/20180930063614_upgrade_thredded_v0_15_to_v0_16.rb +40 -0
  52. data/lib/generators/thredded/install/templates/initializer.rb +4 -4
  53. data/lib/thredded/arel_compat.rb +18 -24
  54. data/lib/thredded/content_formatter.rb +1 -1
  55. data/lib/thredded/database_seeder.rb +7 -6
  56. data/lib/thredded/version.rb +1 -1
  57. metadata +24 -18
  58. data/app/views/thredded/messageboards/_messageboard_meta.html.erb +0 -13
  59. data/lib/tasks/thredded_tasks.rake +0 -14
@@ -69,6 +69,7 @@ de:
69
69
  page_title: Forum
70
70
  last_updated_by_html: Letzter Beitrag %{time_ago} <cite>von %{user}</cite>
71
71
  topics_and_posts_counts: "%{topics_count} Diskussionen / %{posts_count} Beiträge"
72
+ topics_and_unread_topics_counts: "%{unread_topics_count} ungelesen von %{topics_count} Themen"
72
73
  update: :thredded.form.update
73
74
  updated_notice: Das Forum wurde aktualisiert
74
75
  messageboard_first_topic:
@@ -67,7 +67,8 @@ en:
67
67
  index:
68
68
  page_title: Messageboards
69
69
  last_updated_by_html: Updated %{time_ago} <cite>by %{user}</cite>
70
- topics_and_posts_counts: "%{topics_count} topics / %{posts_count} posts"
70
+ topics_and_posts_counts: "%{posts_count} posts in %{topics_count} topics"
71
+ topics_and_unread_topics_counts: "%{unread_topics_count} unread of %{topics_count} topics"
71
72
  update: :thredded.form.update
72
73
  updated_notice: Messageboard has been updated
73
74
  messageboard_first_topic:
@@ -70,6 +70,7 @@ es:
70
70
  page_title: Foros
71
71
  last_updated_by_html: Actualizado %{time_ago} <cite>por %{user}</cite>
72
72
  topics_and_posts_counts: "%{topics_count} temas / %{posts_count} mensajes"
73
+ topics_and_unread_topics_counts: "%{unread_topics_count} no leídos de los temas de %{topics_count}"
73
74
  update: :thredded.form.update
74
75
  updated_notice: Foro actualizado
75
76
  messageboard_first_topic:
@@ -68,6 +68,7 @@ fr:
68
68
  page_title: Catégories
69
69
  last_updated_by_html: Mise à jour %{time_ago} <cite>par %{user}</cite>
70
70
  topics_and_posts_counts: "%{topics_count} sujets / %{posts_count} commentaires"
71
+ topics_and_unread_topics_counts: "%{unread_topics_count} non lu des sujets de %{topics_count}"
71
72
  update: :thredded.form.update
72
73
  updated_notice: La catégorie a été mise à jour
73
74
  messageboard_first_topic:
@@ -68,6 +68,7 @@ it:
68
68
  page_title: Bacheche
69
69
  last_updated_by_html: Aggiornato %{time_ago} <cite>da %{user}</cite>
70
70
  topics_and_posts_counts: "%{topics_count} discussioni / %{posts_count} messaggi"
71
+ topics_and_unread_topics_counts: "%{unread_topics_count} non letto di argomenti %{topics_count}"
71
72
  update: :thredded.form.update
72
73
  updated_notice: La bacheca è stata aggiornata
73
74
  messageboard_first_topic:
@@ -68,6 +68,7 @@ pl:
68
68
  page_title: Tablice
69
69
  last_updated_by_html: Zaktualizowano %{time_ago} <cite>przez %{user}</cite>
70
70
  topics_and_posts_counts: "%{topics_count} tematów / %{posts_count} postów"
71
+ topics_and_unread_topics_counts: "%{unread_topics_count} nieprzeczytane tematy %{topics_count}"
71
72
  update: :thredded.form.update
72
73
  updated_notice: Tablica została zaktualizowana
73
74
  messageboard_first_topic:
@@ -70,6 +70,7 @@ pt-BR:
70
70
  page_title: Fóruns de Mensagens
71
71
  last_updated_by_html: Atualizado %{time_ago} <cite>por %{user}</cite>
72
72
  topics_and_posts_counts: "%{topics_count} tópicos / %{posts_count} posts"
73
+ topics_and_unread_topics_counts: "%{unread_topics_count} não lida de %{topics_count} topics"
73
74
  update: :thredded.form.update
74
75
  updated_notice: Fórum de mensagem foi atualizado
75
76
  messageboard_first_topic:
@@ -67,6 +67,7 @@ ru:
67
67
  page_title: Форумы
68
68
  last_updated_by_html: Обновлено %{time_ago} <cite>пользователем %{user}</cite>
69
69
  topics_and_posts_counts: "%{topics_count} тем / %{posts_count} постов"
70
+ topics_and_unread_topics_counts: "%{unread_topics_count} непрочитанных из %{topics_count} тем"
70
71
  update: :thredded.form.update
71
72
  updated_notice: Форум обновлен
72
73
  messageboard_first_topic:
@@ -65,6 +65,7 @@ zh-CN:
65
65
  page_title: 板块
66
66
  last_updated_by_html: 最近由 <span>%{user}</span> 在%{time_ago}更新
67
67
  topics_and_posts_counts: "%{topics_count} 帖子 / %{posts_count} 回复"
68
+ topics_and_unread_topics_counts: "%{unread_topics_count} 未读取 %{topics_count} 主题"
68
69
  update: :thredded.form.update
69
70
  updated_notice: 板块已更新
70
71
  messageboard_first_topic:
@@ -195,12 +195,17 @@ class CreateThredded < Thredded::BaseMigration
195
195
  %i[topic private_topic].each do |topics_table|
196
196
  table_name = :"thredded_user_#{topics_table}_read_states"
197
197
  create_table table_name do |t|
198
+ t.references :messageboard, null: false, index: true if table_name == :thredded_user_topic_read_states
198
199
  t.references :user, type: user_id_type, null: false, index: false
199
200
  t.references :postable, null: false, index: false
201
+ t.integer :unread_posts_count, default: 0, null: false
202
+ t.integer :read_posts_count, :integer, default: 0, null: false
200
203
  t.timestamp :read_at, null: false
201
204
  t.index %i[user_id postable_id], name: :"#{table_name}_user_postable", unique: true
202
205
  end
203
206
  end
207
+ add_index :thredded_user_topic_read_states, %i[user_id messageboard_id],
208
+ name: :thredded_user_topic_read_states_user_messageboard
204
209
 
205
210
  create_table :thredded_messageboard_groups do |t|
206
211
  t.string :name
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thredded/base_migration'
4
+
5
+ class UpgradeThreddedV015ToV016 < Thredded::BaseMigration
6
+ def up
7
+ %i[thredded_user_topic_read_states thredded_user_private_topic_read_states].each do |table_name|
8
+ add_column table_name, :unread_posts_count, :integer, default: 0, null: false
9
+ add_column table_name, :read_posts_count, :integer, default: 0, null: false
10
+ end
11
+ add_column :thredded_user_topic_read_states, :messageboard_id, column_type(:thredded_messageboards, :id)
12
+ set_messageboard_ids
13
+ change_column_null :thredded_user_topic_read_states, :messageboard_id, false
14
+ add_index :thredded_user_topic_read_states, :messageboard_id
15
+ add_index :thredded_user_topic_read_states, %i[user_id messageboard_id],
16
+ name: :thredded_user_topic_read_states_user_messageboard
17
+ [Thredded::UserTopicReadState, Thredded::UserPrivateTopicReadState].each do |klass|
18
+ klass.reset_column_information
19
+ klass.update_post_counts!
20
+ end
21
+ end
22
+
23
+ def down
24
+ remove_column :thredded_user_topic_read_states, :messageboard_id
25
+ %i[thredded_user_topic_read_states thredded_user_private_topic_read_states].each do |table|
26
+ remove_column table, :unread_posts_count
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def set_messageboard_ids
33
+ messageboard_topics = Thredded::Topic.pluck(:messageboard_id, :id).group_by(&:first)
34
+ messageboard_topics.transform_values! { |v| v.map(&:second) }
35
+ messageboard_topics.each do |messageboard_id, topic_ids|
36
+ say "Setting messageboard_id #{messageboard_id} for postable_id IN (#{topic_ids.join(',')})"
37
+ Thredded::UserTopicReadState.where(postable_id: topic_ids).update_all(messageboard_id: messageboard_id)
38
+ end
39
+ end
40
+ end
@@ -109,10 +109,10 @@ Thredded.layout = 'thredded/application'
109
109
  # ==> Post Content Formatting
110
110
  # Customize the way Thredded handles post formatting.
111
111
 
112
- # Change the default html-pipeline filters used by thredded.
113
- # E.g. to replace default emoji filter with your own:
114
- # Thredded::ContentFormatter.after_markup_filters[
115
- # Thredded::ContentFormatter.after_markup_filters.index(HTML::Pipeline::EmojiFilter)] = MyEmojiFilter
112
+ # ===> Emoji using the 'gemoji' gem
113
+ # 1. Install `gemoji` following instruction at https://github.com/github/gemoji.
114
+ # 2. Uncomment the following line:
115
+ # Thredded::ContentFormatter.after_markup_filters.insert(1, HTML::Pipeline::EmojiFilter)
116
116
 
117
117
  # Change the HTML sanitization settings used by Thredded.
118
118
  # See the Sanitize docs for more information on the underlying library: https://github.com/rgrove/sanitize/#readme
@@ -4,6 +4,24 @@ unless Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2 || Rails::VERSIO
4
4
  require 'thredded/rails_lt_5_2_arel_case_node.rb'
5
5
  end
6
6
 
7
+ if Rails::VERSION::MAJOR == 4
8
+ # Make `pluck` compatible with Arel.
9
+ require 'active_record/relation'
10
+ ActiveRecord::Relation.prepend(Module.new do
11
+ def pluck(*column_names)
12
+ super(*column_names.map do |n|
13
+ if n.is_a?(Arel::Node)
14
+ Arel.sql(n.to_sql)
15
+ elsif n.is_a?(Arel::Attributes::Attribute)
16
+ n.name
17
+ else
18
+ n
19
+ end
20
+ end)
21
+ end
22
+ end)
23
+ end
24
+
7
25
  module Thredded
8
26
  module ArelCompat
9
27
  module_function
@@ -20,30 +38,6 @@ module Thredded
20
38
  end
21
39
  end
22
40
 
23
- if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2 || Rails::VERSION::MAJOR > 5
24
- # @param [ActiveRecord::Relation] relation
25
- # @return [Arel::Nodes::Node]
26
- def relation_to_arel(relation)
27
- relation.arel
28
- end
29
- else
30
- def relation_to_arel(relation)
31
- Arel.sql("(#{relation.to_sql})")
32
- end
33
- end
34
-
35
- if Rails::VERSION::MAJOR >= 5
36
- # @param [Arel::Nodes::Node] table
37
- # @return [Arel::SelectManager]
38
- def new_arel_select_manager(table)
39
- Arel::SelectManager.new(table)
40
- end
41
- else
42
- def new_arel_select_manager(table)
43
- Arel::SelectManager.new(ActiveRecord::Base, table)
44
- end
45
- end
46
-
47
41
  if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2 || Rails::VERSION::MAJOR > 5
48
42
  def true_value(_engine)
49
43
  true
@@ -46,6 +46,7 @@ module Thredded
46
46
  'abbr' => %w[title],
47
47
  'span' => %w[class],
48
48
  'div' => %w[class],
49
+ 'img' => %w[src longdesc class],
49
50
  :all => HTML::Pipeline::SanitizationFilter::WHITELIST[:attributes][:all] +
50
51
  %w[aria-expanded aria-label aria-labelledby aria-live aria-hidden aria-pressed role],
51
52
  }
@@ -63,7 +64,6 @@ module Thredded
63
64
  # AutolinkFilter is required because Kramdown does not autolink by default.
64
65
  # https://github.com/gettalong/kramdown/issues/306
65
66
  Thredded::HtmlPipeline::AutolinkFilter,
66
- HTML::Pipeline::EmojiFilter,
67
67
  Thredded::HtmlPipeline::AtMentionFilter,
68
68
  Thredded::HtmlPipeline::SpoilerTagFilter::AfterMarkup,
69
69
  ]
@@ -229,12 +229,13 @@ module Thredded
229
229
  end
230
230
 
231
231
  def read_topic(topic, user_id)
232
- read_state = Thredded::UserTopicReadState.find_or_initialize_by(user_id: user_id, postable_id: topic.id)
233
- if rand(2).zero?
234
- read_state.update!(read_at: topic.updated_at)
235
- else
236
- read_state.update!(read_at: topic.posts.order_newest_first.first(2).last.created_at)
237
- end
232
+ last_read_post =
233
+ if rand(2).zero?
234
+ topic.posts.order_newest_first.first(2).last
235
+ else
236
+ topic.posts.order_newest_first.first
237
+ end
238
+ Thredded::UserTopicReadState.touch!(user_id, last_read_post)
238
239
  end
239
240
 
240
241
  class BaseSeedData
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Thredded
4
- VERSION = '0.15.5'
4
+ VERSION = '0.16.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thredded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.5
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Oliveira
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-01 00:00:00.000000000 Z
12
+ date: 2018-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active_record_union
@@ -213,20 +213,6 @@ dependencies:
213
213
  - - ">="
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
- - !ruby/object:Gem::Dependency
217
- name: gemoji
218
- requirement: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: 2.1.0
223
- type: :runtime
224
- prerelease: false
225
- version_requirements: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - "~>"
228
- - !ruby/object:Gem::Version
229
- version: 2.1.0
230
216
  - !ruby/object:Gem::Dependency
231
217
  name: sanitize
232
218
  requirement: !ruby/object:Gem::Requirement
@@ -591,6 +577,20 @@ dependencies:
591
577
  - - ">="
592
578
  - !ruby/object:Gem::Version
593
579
  version: '0'
580
+ - !ruby/object:Gem::Dependency
581
+ name: twemoji
582
+ requirement: !ruby/object:Gem::Requirement
583
+ requirements:
584
+ - - ">="
585
+ - !ruby/object:Gem::Version
586
+ version: '0'
587
+ type: :development
588
+ prerelease: false
589
+ version_requirements: !ruby/object:Gem::Requirement
590
+ requirements:
591
+ - - ">="
592
+ - !ruby/object:Gem::Version
593
+ version: '0'
594
594
  - !ruby/object:Gem::Dependency
595
595
  name: web-console
596
596
  requirement: !ruby/object:Gem::Requirement
@@ -752,6 +752,7 @@ files:
752
752
  - app/assets/stylesheets/thredded/layout/_search-navigation.scss
753
753
  - app/assets/stylesheets/thredded/layout/_user-navigation.scss
754
754
  - app/assets/stylesheets/thredded/layout/_user.scss
755
+ - app/assets/stylesheets/thredded/utilities/_flex.scss
755
756
  - app/assets/stylesheets/thredded/utilities/_is-compact.scss
756
757
  - app/assets/stylesheets/thredded/utilities/_is-expanded.scss
757
758
  - app/commands/thredded/at_notification_extractor.rb
@@ -855,6 +856,7 @@ files:
855
856
  - app/view_hooks/thredded/all_view_hooks.rb
856
857
  - app/view_models/thredded/base_topic_view.rb
857
858
  - app/view_models/thredded/messageboard_group_view.rb
859
+ - app/view_models/thredded/messageboard_view.rb
858
860
  - app/view_models/thredded/post_view.rb
859
861
  - app/view_models/thredded/posts_page_view.rb
860
862
  - app/view_models/thredded/private_topic_view.rb
@@ -878,9 +880,13 @@ files:
878
880
  - app/views/thredded/messageboards/_form.html.erb
879
881
  - app/views/thredded/messageboards/_messageboard.html.erb
880
882
  - app/views/thredded/messageboards/_messageboard_actions.html.erb
881
- - app/views/thredded/messageboards/_messageboard_meta.html.erb
882
883
  - app/views/thredded/messageboards/edit.html.erb
883
884
  - app/views/thredded/messageboards/index.html.erb
885
+ - app/views/thredded/messageboards/messageboard/_description.html.erb
886
+ - app/views/thredded/messageboards/messageboard/_header.html.erb
887
+ - app/views/thredded/messageboards/messageboard/_last_updated.html.erb
888
+ - app/views/thredded/messageboards/messageboard/_meta.html.erb
889
+ - app/views/thredded/messageboards/messageboard/_unread_followed_topics_badge.html.erb
884
890
  - app/views/thredded/messageboards/new.html.erb
885
891
  - app/views/thredded/moderation/_nav.html.erb
886
892
  - app/views/thredded/moderation/_post.html.erb
@@ -1006,10 +1012,10 @@ files:
1006
1012
  - db/upgrade_migrations/20170420163138_upgrade_thredded_v0_11_to_v0_12.rb
1007
1013
  - db/upgrade_migrations/20170811090735_upgrade_thredded_v0_13_to_v0_14.rb
1008
1014
  - db/upgrade_migrations/20180110200009_upgrade_thredded_v0_14_to_v0_15.rb
1015
+ - db/upgrade_migrations/20180930063614_upgrade_thredded_v0_15_to_v0_16.rb
1009
1016
  - lib/generators/thredded/install/USAGE
1010
1017
  - lib/generators/thredded/install/install_generator.rb
1011
1018
  - lib/generators/thredded/install/templates/initializer.rb
1012
- - lib/tasks/thredded_tasks.rake
1013
1019
  - lib/thredded.rb
1014
1020
  - lib/thredded/arel_compat.rb
1015
1021
  - lib/thredded/base_migration.rb
@@ -1,13 +0,0 @@
1
- <div class="thredded--messageboard--meta">
2
- <% if messageboard.locked? %>
3
- <span class="thredded--messageboard--meta--locked"
4
- title="<%= t('thredded.messageboard.form.locked_notice') %>">
5
- <%= inline_svg('thredded/lock.svg', class: 'thredded--messageboard--meta--icon') %>
6
- </span>
7
- <% end %>
8
- <h3 class="thredded--messageboard--meta--counts">
9
- <%= t 'thredded.messageboard.topics_and_posts_counts',
10
- topics_count: number_with_delimiter(messageboard.topics_count),
11
- posts_count: number_with_delimiter(messageboard.posts_count) %>
12
- </h3>
13
- </div>
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- namespace :thredded do
4
- namespace :install do
5
- desc 'Copy emoji to the Rails `public/emoji` directory'
6
- task :emoji do
7
- require 'emoji'
8
-
9
- target = Rails.application.root.join('public')
10
- STDERR.puts "Copying emoji to #{target}"
11
- `mkdir -p '#{target}' && cp -Rp '#{Emoji.images_path}/emoji' '#{target}'`
12
- end
13
- end
14
- end