thredded 0.16.3 → 0.16.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/commands/thredded/at_notification_extractor.rb +2 -1
- data/app/helpers/thredded/application_helper.rb +2 -1
- data/app/models/concerns/thredded/post_common.rb +4 -10
- data/lib/thredded.rb +1 -0
- data/lib/thredded/html_pipeline/at_mention_filter.rb +4 -3
- data/lib/thredded/users_provider.rb +43 -0
- data/lib/thredded/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c673448c2a6d28fb179142b35315e75444fce8dd02e7023ed2bacc044fb25fc6
|
4
|
+
data.tar.gz: 1a2c5185e9f7329ef66eba90964ee16a0acc5612721e028b37a065290a2b51f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b63618a95b16216b1527b9317f6d016540692b6de92e2f915b7fb9806979ca480c4c2db6af0bbd7a4889b3b01152844d334a9999b77dd64f193f53c3b163406
|
7
|
+
data.tar.gz: 79fdbe8f94dce3f8519c3635016866ca294ecd11ea5fdceb93edc2df2df29f85c10663aee38c56c2153cf0c84220cb94306e5a9f49e7b32f5cecd9ad11e4c380
|
data/README.md
CHANGED
@@ -95,7 +95,7 @@ Then, see the rest of this Readme for more information about using and customizi
|
|
95
95
|
Add the gem to your Gemfile:
|
96
96
|
|
97
97
|
```ruby
|
98
|
-
gem 'thredded', '~> 0.16.
|
98
|
+
gem 'thredded', '~> 0.16.4'
|
99
99
|
```
|
100
100
|
|
101
101
|
Add the Thredded [initializer] to your parent app by running the install generator.
|
@@ -16,7 +16,8 @@ module Thredded
|
|
16
16
|
Thredded::HtmlPipeline::AtMentionFilter.new(
|
17
17
|
html,
|
18
18
|
view_context: view_context,
|
19
|
-
users_provider:
|
19
|
+
users_provider: ::Thredded::UsersProvider,
|
20
|
+
users_provider_scope: @post.readers
|
20
21
|
).mentioned_users
|
21
22
|
end
|
22
23
|
end
|
@@ -85,7 +85,8 @@ module Thredded
|
|
85
85
|
# @param content_partial [String]
|
86
86
|
def render_posts(posts, partial: 'thredded/posts/post', content_partial: 'thredded/posts/content', locals: {})
|
87
87
|
posts_with_contents = render_collection_to_strings_with_cache(
|
88
|
-
partial: content_partial, collection: posts, as: :post, expires_in: 1.week
|
88
|
+
partial: content_partial, collection: posts, as: :post, expires_in: 1.week,
|
89
|
+
locals: { options: { users_provider: ::Thredded::UsersProviderWithCache.new } }
|
89
90
|
)
|
90
91
|
render partial: partial, collection: posts_with_contents, as: :post_and_content, locals: locals
|
91
92
|
end
|
@@ -33,22 +33,16 @@ module Thredded
|
|
33
33
|
|
34
34
|
# @param view_context [Object] the context of the rendering view.
|
35
35
|
# @return [String] formatted and sanitized html-safe post content.
|
36
|
-
def filtered_content(view_context, users_provider:
|
37
|
-
Thredded::ContentFormatter.new(
|
36
|
+
def filtered_content(view_context, users_provider: ::Thredded::UsersProvider, **options)
|
37
|
+
Thredded::ContentFormatter.new(
|
38
|
+
view_context, users_provider: users_provider, users_provider_scope: readers, **options
|
39
|
+
).format_content(content)
|
38
40
|
end
|
39
41
|
|
40
42
|
def first_post_in_topic?
|
41
43
|
postable.first_post == self
|
42
44
|
end
|
43
45
|
|
44
|
-
# @return [ActiveRecord::Relation<Thredded.user_class>] users from the list of user names that can read this post.
|
45
|
-
# @api private
|
46
|
-
def readers_from_user_names(user_names)
|
47
|
-
DbTextSearch::CaseInsensitive
|
48
|
-
.new(readers, Thredded.user_name_column)
|
49
|
-
.in(user_names)
|
50
|
-
end
|
51
|
-
|
52
46
|
# Marks all the posts from the given one as unread for the given user
|
53
47
|
# @param [Thredded.user_class] user
|
54
48
|
def mark_as_unread(user)
|
data/lib/thredded.rb
CHANGED
@@ -23,6 +23,7 @@ require 'thredded/html_pipeline/kramdown_filter'
|
|
23
23
|
require 'thredded/html_pipeline/onebox_filter'
|
24
24
|
require 'thredded/html_pipeline/wrap_iframes_filter'
|
25
25
|
require 'thredded/html_pipeline/spoiler_tag_filter'
|
26
|
+
require 'thredded/users_provider'
|
26
27
|
|
27
28
|
# Asset compilation
|
28
29
|
require 'autoprefixer-rails'
|
@@ -10,6 +10,7 @@ module Thredded
|
|
10
10
|
def initialize(doc, context = nil, result = nil)
|
11
11
|
super doc, context, result
|
12
12
|
@users_provider = context[:users_provider]
|
13
|
+
@users_provider_scope = context[:users_provider_scope]
|
13
14
|
@view_context = context[:view_context]
|
14
15
|
end
|
15
16
|
|
@@ -30,7 +31,7 @@ module Thredded
|
|
30
31
|
names = []
|
31
32
|
process_text_nodes! { |node| names.concat mentioned_names(node.to_html) }
|
32
33
|
names.uniq!
|
33
|
-
@users_provider.call(names)
|
34
|
+
@users_provider.call(names, @users_provider_scope)
|
34
35
|
end
|
35
36
|
|
36
37
|
private
|
@@ -43,8 +44,8 @@ module Thredded
|
|
43
44
|
|
44
45
|
def highlight!(text_node_html)
|
45
46
|
names = mentioned_names(text_node_html)
|
46
|
-
return if names.blank?
|
47
|
-
@users_provider.call(names).each do |user|
|
47
|
+
return if names.blank? || @users_provider.nil?
|
48
|
+
@users_provider.call(names, @users_provider_scope).each do |user|
|
48
49
|
name = user.thredded_display_name
|
49
50
|
maybe_quoted_name = name =~ /[., ()]/ ? %("#{name}") : name
|
50
51
|
url = Thredded.user_path(@view_context, user)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thredded
|
4
|
+
module UsersProvider
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def call(user_names, scope)
|
8
|
+
DbTextSearch::CaseInsensitive
|
9
|
+
.new(scope, Thredded.user_name_column)
|
10
|
+
.in(user_names)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class UsersProviderWithCache
|
15
|
+
def initialize
|
16
|
+
@mutex = Mutex.new
|
17
|
+
@cache = {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(names, scope)
|
21
|
+
# This is not the same as the database lowercasing but it's OK.
|
22
|
+
# The worst that can happen is some cache misses.
|
23
|
+
names_with_lowercase = names.zip(names.map(&:downcase))
|
24
|
+
cached = uncached = nil
|
25
|
+
result = @mutex.synchronize do
|
26
|
+
scope_cache = (@cache[scope.to_sql] ||= {})
|
27
|
+
cached, uncached = names_with_lowercase.partition { |(_, lowercase)| scope_cache.key?(lowercase) }
|
28
|
+
fetched = UsersProvider.call(uncached.map(&:first), scope)
|
29
|
+
fetched.each do |user|
|
30
|
+
scope_cache[user.send(Thredded.user_name_column).downcase] = user
|
31
|
+
end
|
32
|
+
cached.map { |(_, lowercase)| scope_cache[lowercase] }.concat(fetched)
|
33
|
+
end
|
34
|
+
result.uniq!
|
35
|
+
result.compact!
|
36
|
+
Rails.logger.info(
|
37
|
+
" [Thredded::UsersProviderWithCache] #{names.size} user names => #{result.size} users "\
|
38
|
+
"(#{cached.size} cached, #{uncached.size} uncached)"
|
39
|
+
)
|
40
|
+
result
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/thredded/version.rb
CHANGED
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.16.
|
4
|
+
version: 0.16.4
|
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:
|
12
|
+
date: 2019-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_record_union
|
@@ -1043,6 +1043,7 @@ files:
|
|
1043
1043
|
- lib/thredded/html_pipeline/utils.rb
|
1044
1044
|
- lib/thredded/html_pipeline/wrap_iframes_filter.rb
|
1045
1045
|
- lib/thredded/rails_lt_5_2_arel_case_node.rb
|
1046
|
+
- lib/thredded/users_provider.rb
|
1046
1047
|
- lib/thredded/version.rb
|
1047
1048
|
- lib/thredded/view_hooks/config.rb
|
1048
1049
|
- lib/thredded/view_hooks/renderer.rb
|