Module: Thredded

Defined in:
lib/thredded.rb,
lib/thredded/engine.rb,
lib/thredded/errors.rb,
lib/thredded/version.rb,
lib/thredded/db_tools.rb,
app/models/thredded/post.rb,
lib/thredded/arel_compat.rb,
app/models/thredded/stats.rb,
app/models/thredded/topic.rb,
lib/thredded/base_notifier.rb,
lib/thredded/base_migration.rb,
lib/thredded/users_provider.rb,
lib/thredded/webpack_assets.rb,
app/forms/thredded/post_form.rb,
app/models/thredded/category.rb,
lib/thredded/database_seeder.rb,
app/forms/thredded/topic_form.rb,
app/models/thredded/null_user.rb,
lib/thredded/content_formatter.rb,
lib/thredded/email_transformer.rb,
lib/thredded/view_hooks/config.rb,
app/helpers/thredded/nav_helper.rb,
app/models/thredded/user_detail.rb,
app/helpers/thredded/icon_helper.rb,
app/helpers/thredded/urls_helper.rb,
app/mailers/thredded/base_mailer.rb,
app/mailers/thredded/post_mailer.rb,
app/models/thredded/messageboard.rb,
app/models/thredded/private_post.rb,
app/models/thredded/private_user.rb,
lib/thredded/html_pipeline/utils.rb,
lib/thredded/view_hooks/renderer.rb,
app/models/thredded/private_topic.rb,
app/models/thredded/user_extender.rb,
app/policies/thredded/post_policy.rb,
app/forms/thredded/edit_topic_form.rb,
app/helpers/thredded/render_helper.rb,
app/models/thredded/topic_category.rb,
app/policies/thredded/topic_policy.rb,
app/view_models/thredded/post_view.rb,
app/commands/thredded/mark_all_read.rb,
app/commands/thredded/moderate_post.rb,
app/models/thredded/user_preference.rb,
app/view_models/thredded/topic_view.rb,
lib/thredded/email_transformer/base.rb,
app/forms/thredded/private_post_form.rb,
lib/thredded/formatting_demo_content.rb,
app/forms/thredded/private_topic_form.rb,
app/models/thredded/messageboard_user.rb,
app/models/thredded/user_topic_follow.rb,
app/notifiers/thredded/email_notifier.rb,
lib/thredded/email_transformer/onebox.rb,
app/commands/thredded/autofollow_users.rb,
app/helpers/thredded/moderation_helper.rb,
app/jobs/thredded/activity_updater_job.rb,
app/models/thredded/messageboard_group.rb,
app/view_hooks/thredded/all_view_hooks.rb,
lib/thredded/email_transformer/spoiler.rb,
app/helpers/thredded/application_helper.rb,
app/forms/thredded/user_preferences_form.rb,
app/models/concerns/thredded/post_common.rb,
app/view_models/thredded/base_topic_view.rb,
app/view_models/thredded/posts_page_view.rb,
lib/thredded/html_pipeline/onebox_filter.rb,
app/commands/thredded/create_messageboard.rb,
app/controllers/thredded/posts_controller.rb,
app/mailers/thredded/private_topic_mailer.rb,
app/models/concerns/thredded/topic_common.rb,
app/models/thredded/user_topic_read_state.rb,
app/policies/thredded/messageboard_policy.rb,
app/policies/thredded/private_post_policy.rb,
app/view_models/thredded/topic_email_view.rb,
app/view_models/thredded/topics_page_view.rb,
app/controllers/thredded/topics_controller.rb,
app/models/concerns/thredded/search_parser.rb,
app/models/concerns/thredded/topics_search.rb,
app/models/thredded/post_moderation_record.rb,
app/models/thredded/user_post_notification.rb,
app/policies/thredded/private_topic_policy.rb,
app/view_models/thredded/messageboard_view.rb,
lib/thredded/html_pipeline/autolink_filter.rb,
lib/thredded/html_pipeline/kramdown_filter.rb,
app/view_models/thredded/private_topic_view.rb,
app/commands/thredded/notify_following_users.rb,
app/jobs/thredded/auto_follow_and_notify_job.rb,
lib/thredded/html_pipeline/at_mention_filter.rb,
app/models/concerns/thredded/moderation_state.rb,
app/models/thredded/user_permissions/read/all.rb,
lib/thredded/html_pipeline/spoiler_tag_filter.rb,
app/controllers/thredded/moderation_controller.rb,
app/models/thredded/null_user_topic_read_state.rb,
app/models/thredded/user_permissions/write/all.rb,
app/view_models/thredded/topic_posts_page_view.rb,
lib/thredded/html_pipeline/wrap_iframes_filter.rb,
app/commands/thredded/at_notification_extractor.rb,
app/controllers/thredded/application_controller.rb,
app/controllers/thredded/preferences_controller.rb,
app/controllers/thredded/read_states_controller.rb,
app/models/thredded/user_permissions/admin/none.rb,
app/models/thredded/user_permissions/write/none.rb,
app/policies/thredded/messageboard_group_policy.rb,
app/commands/thredded/notify_private_topic_users.rb,
app/controllers/concerns/thredded/render_preview.rb,
app/jobs/thredded/notify_private_topic_users_job.rb,
app/mailer_previews/thredded/base_mailer_preview.rb,
app/mailer_previews/thredded/post_mailer_preview.rb,
app/models/concerns/thredded/notifier_preference.rb,
app/models/thredded/user_messageboard_preference.rb,
app/view_models/thredded/messageboard_group_view.rb,
app/controllers/concerns/thredded/new_post_params.rb,
app/controllers/thredded/messageboards_controller.rb,
app/controllers/thredded/post_previews_controller.rb,
app/controllers/thredded/private_posts_controller.rb,
app/models/thredded/user_private_topic_read_state.rb,
app/view_models/thredded/private_topics_page_view.rb,
lib/generators/thredded/install/install_generator.rb,
app/controllers/concerns/thredded/new_topic_params.rb,
app/controllers/thredded/private_topics_controller.rb,
app/controllers/thredded/theme_previews_controller.rb,
app/controllers/thredded/topic_previews_controller.rb,
app/models/thredded/user_permissions/moderate/none.rb,
app/controllers/thredded/post_permalinks_controller.rb,
app/models/thredded/notifications_for_private_topics.rb,
app/models/concerns/thredded/content_moderation_state.rb,
app/models/thredded/notifications_for_followed_topics.rb,
app/controllers/thredded/autocomplete_users_controller.rb,
lib/thredded/collection_to_strings_with_cache_renderer.rb,
app/controllers/thredded/messageboard_groups_controller.rb,
app/controllers/concerns/thredded/new_private_post_params.rb,
app/controllers/thredded/private_post_previews_controller.rb,
app/mailer_previews/thredded/private_topic_mailer_preview.rb,
app/models/concerns/thredded/user_topic_read_state_common.rb,
app/controllers/concerns/thredded/new_private_topic_params.rb,
app/controllers/thredded/private_topic_previews_controller.rb,
app/controllers/thredded/private_post_permalinks_controller.rb,
app/models/thredded/user_permissions/admin/if_admin_column_true.rb,
app/models/thredded/messageboard_notifications_for_followed_topics.rb,
app/models/concerns/thredded/friendly_id_reserved_words_and_pagination.rb,
app/models/thredded/user_permissions/moderate/if_moderator_column_true.rb,
app/models/thredded/user_permissions/message/readers_of_writeable_boards.rb

Overview

rubocop:enable HandleExceptions

Defined Under Namespace

Modules: ApplicationHelper, ArelCompat, ContentModerationState, DbTools, EmailTransformer, Errors, FormattingDemoContent, Generators, HtmlPipeline, IconHelper, ModeratePost, ModerationHelper, ModerationState, NavHelper, NewPostParams, NewPrivatePostParams, NewPrivateTopicParams, NewTopicParams, NotifierPreference, PostCommon, RenderHelper, RenderPreview, TopicCommon, UrlsHelper, UserExtender, UserPermissions, UserTopicReadStateCommon, UsersProvider, ViewHooks, WebpackAssets Classes: ActivityUpdaterJob, AllViewHooks, ApplicationController, AtNotificationExtractor, AutoFollowAndNotifyJob, AutocompleteUsersController, AutofollowUsers, BaseMailer, BaseMailerPreview, BaseMigration, BaseNotifier, BaseTopicView, Category, CollectionToStringsWithCacheRenderer, ContentFormatter, CreateMessageboard, DatabaseSeeder, EditTopicForm, EmailNotifier, Engine, Error, FriendlyIdReservedWordsAndPagination, MarkAllRead, Messageboard, MessageboardGroup, MessageboardGroupPolicy, MessageboardGroupView, MessageboardGroupsController, MessageboardNotificationsForFollowedTopics, MessageboardPolicy, MessageboardUser, MessageboardView, MessageboardsController, ModerationController, NotificationsForFollowedTopics, NotificationsForPrivateTopics, NotifyFollowingUsers, NotifyPrivateTopicUsers, NotifyPrivateTopicUsersJob, NullUser, NullUserTopicReadState, Post, PostForm, PostMailer, PostMailerPreview, PostModerationRecord, PostPermalinksController, PostPolicy, PostPreviewsController, PostView, PostsController, PostsPageView, PreferencesController, PrivatePost, PrivatePostForm, PrivatePostPermalinksController, PrivatePostPolicy, PrivatePostPreviewsController, PrivatePostsController, PrivateTopic, PrivateTopicForm, PrivateTopicMailer, PrivateTopicMailerPreview, PrivateTopicPolicy, PrivateTopicPreviewsController, PrivateTopicView, PrivateTopicsController, PrivateTopicsPageView, PrivateUser, ReadStatesController, SearchParser, Stats, ThemePreviewsController, Topic, TopicCategory, TopicEmailView, TopicForm, TopicPolicy, TopicPostsPageView, TopicPreviewsController, TopicView, TopicsController, TopicsPageView, TopicsSearch, UserDetail, UserMessageboardPreference, UserPostNotification, UserPreference, UserPreferencesForm, UserPrivateTopicReadState, UserTopicFollow, UserTopicReadState, UsersProviderWithCache

Constant Summary collapse

VERSION =
'0.16.16'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.active_user_thresholdActiveSupport::Duration



120
121
122
# File 'lib/thredded.rb', line 120

def active_user_threshold
  @active_user_threshold
end

.admin_columnSymbol



83
84
85
# File 'lib/thredded.rb', line 83

def admin_column
  @admin_column
end

.auto_follow_when_creating_topicBoolean



149
150
151
# File 'lib/thredded.rb', line 149

def auto_follow_when_creating_topic
  @auto_follow_when_creating_topic
end

.auto_follow_when_posting_in_topicBoolean



152
153
154
# File 'lib/thredded.rb', line 152

def auto_follow_when_posting_in_topic
  @auto_follow_when_posting_in_topic
end

.autocomplete_min_lengthNumber



135
136
137
# File 'lib/thredded.rb', line 135

def autocomplete_min_length
  @autocomplete_min_length
end

.avatar_urlProc



77
78
79
# File 'lib/thredded.rb', line 77

def avatar_url
  @avatar_url
end

.content_visible_while_pending_moderationBoolean



88
89
90
# File 'lib/thredded.rb', line 88

def content_visible_while_pending_moderation
  @content_visible_while_pending_moderation
end

.current_user_methodSymbol



68
69
70
# File 'lib/thredded.rb', line 68

def current_user_method
  @current_user_method
end

.currently_online_enabledBoolean



117
118
119
# File 'lib/thredded.rb', line 117

def currently_online_enabled
  @currently_online_enabled
end

.email_fromString



160
161
162
# File 'lib/thredded.rb', line 160

def email_from
  @email_from
end

.email_outgoing_prefixString



163
164
165
# File 'lib/thredded.rb', line 163

def email_outgoing_prefix
  @email_outgoing_prefix
end

.layoutString



99
100
101
# File 'lib/thredded.rb', line 99

def layout
  @layout
end

.messageboard_name_length_rangeRange<Integer>



180
181
182
# File 'lib/thredded.rb', line 180

def messageboard_name_length_range
  @messageboard_name_length_range
end

.messageboards_order:position, ...

How to calculate the position of messageboards in a list: :position set the position manually (new messageboards go to the bottom, by creation timestamp) :last_post_at_desc most recent post first :topics_count_desc most topics first



129
130
131
# File 'lib/thredded.rb', line 129

def messageboards_order
  @messageboards_order
end

.moderator_columnSymbol



91
92
93
# File 'lib/thredded.rb', line 91

def moderator_column
  @moderator_column
end

.parent_mailerString



157
158
159
# File 'lib/thredded.rb', line 157

def parent_mailer
  @parent_mailer
end

.posts_per_pageNumber



104
105
106
# File 'lib/thredded.rb', line 104

def posts_per_page
  @posts_per_page
end

.private_messaging_enabledBoolean



112
113
114
# File 'lib/thredded.rb', line 112

def private_messaging_enabled
  @private_messaging_enabled
end

.routes_id_constraintObject

By default, thredded uses integers for record ID route constraints. For integer based IDs (default):

Thredded.routes_id_constraint = /[1-9]\d*/

For UUID based IDs (example):

Thredded.routes_id_constraint = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/


175
176
177
# File 'lib/thredded.rb', line 175

def routes_id_constraint
  @routes_id_constraint
end

.show_messageboard_delete_buttonBoolean



94
95
96
# File 'lib/thredded.rb', line 94

def show_messageboard_delete_button
  @show_messageboard_delete_button
end

.show_messageboard_group_pageBoolean



138
139
140
# File 'lib/thredded.rb', line 138

def show_messageboard_group_page
  @show_messageboard_group_page
end

.show_topic_followersBoolean



107
108
109
# File 'lib/thredded.rb', line 107

def show_topic_followers
  @show_topic_followers
end

.slugifierProc



168
169
170
# File 'lib/thredded.rb', line 168

def slugifier
  @slugifier
end

.topic_title_length_rangeRange<Integer>



183
184
185
# File 'lib/thredded.rb', line 183

def topic_title_length_range
  @topic_title_length_range
end

.topics_per_pageNumber



132
133
134
# File 'lib/thredded.rb', line 132

def topics_per_page
  @topics_per_page
end

.user_class_nameString (readonly)



65
66
67
# File 'lib/thredded.rb', line 65

def user_class_name
  @user_class_name
end

.user_display_name_methodSymbol



197
198
199
# File 'lib/thredded.rb', line 197

def user_display_name_method
  @user_display_name_method || user_name_column
end

.user_name_columnSymbol



71
72
73
# File 'lib/thredded.rb', line 71

def user_name_column
  @user_name_column
end

.user_path(view_context, user) ⇒ String



229
230
231
# File 'lib/thredded.rb', line 229

def user_path(view_context, user)
  view_context.instance_exec(user, &@user_path)
end

Class Method Details

.notifiersArray



186
187
188
# File 'lib/thredded.rb', line 186

def notifiers
  @notifiers ||= [Thredded::EmailNotifier.new]
end

.notifiers=(notifiers) ⇒ Object



191
192
193
194
# File 'lib/thredded.rb', line 191

def notifiers=(notifiers)
  notifiers.each { |notifier| Thredded::BaseNotifier.validate_notifier(notifier) }
  @notifiers = notifiers
end

.posts_page_view(scope:, current_user:) ⇒ PostsPageView

Returns a view for the given posts’ scope, applying read permission filters to the scope. Can be used in main_app, e.g. for showing the recent user posts on the profile page.



246
247
248
249
250
251
252
253
254
# File 'lib/thredded.rb', line 246

def posts_page_view(scope:, current_user:)
  current_user ||= Thredded::NullUser.new
  Thredded::PostsPageView.new(
    current_user,
    Pundit.policy_scope!(current_user, scope)
      .where(messageboard_id: Pundit.policy_scope!(current_user, Thredded::Messageboard.all).pluck(:id))
      .includes(:postable)
  )
end

.rails_gte_51?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



257
258
259
260
# File 'lib/thredded.rb', line 257

def rails_gte_51?
  @rails_gte_51 = (Rails.gem_version >= Gem::Version.new('5.1.0')) if @rails_gte_51.nil?
  @rails_gte_51
end

.rails_supports_csp_nonce?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



263
264
265
266
# File 'lib/thredded.rb', line 263

def rails_supports_csp_nonce?
  @rails_supports_csp_nonce = (Rails.gem_version >= Gem::Version.new('5.2.0')) if @rails_supports_csp_nonce.nil?
  @rails_supports_csp_nonce
end

.standalone_layout?Boolean

Whether the layout is a thredded layout as opposed to the application layout.



234
235
236
# File 'lib/thredded.rb', line 234

def standalone_layout?
  layout.is_a?(String) && layout.start_with?('thredded/')
end

.user_classClass<Thredded::UserExtender>



220
221
222
223
224
# File 'lib/thredded.rb', line 220

def user_class
  # This is nil before the initializer is installed.
  return nil if @user_class_name.nil?
  @user_class_name.constantize
end

.user_class=(user_class_name) ⇒ Object



212
213
214
215
216
217
# File 'lib/thredded.rb', line 212

def user_class=(user_class_name)
  unless user_class_name.is_a?(String)
    fail "Thredded.user_class must be set to a String, got #{user_class_name.inspect}"
  end
  @user_class_name = user_class_name
end

.view_hooksThredded::AllViewHooks



141
142
143
144
# File 'lib/thredded.rb', line 141

def view_hooks
  Thredded::AllViewHooks.instance ||
    fail('`Thredded.view_hooks` must be configured in a `Rails.application.config.to_prepare` block!')
end