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,
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/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, ModerationState, NavHelper, NewPostParams, NewPrivatePostParams, NewPrivateTopicParams, NewTopicParams, NotifierPreference, PostCommon, RenderHelper, RenderPreview, TopicCommon, UrlsHelper, UserExtender, UserPermissions, UserTopicReadStateCommon, ViewHooks 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

Constant Summary collapse

VERSION =
'0.16.3'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.active_user_thresholdActiveSupport::Duration

Returns How long the users are considered online after their last action.

Returns:

  • (ActiveSupport::Duration)

    How long the users are considered online after their last action.



114
115
116
# File 'lib/thredded.rb', line 114

def active_user_threshold
  @active_user_threshold
end

.admin_columnSymbol

Returns The name of the admin flag column on the users table for the default permissions model

Returns:

  • (Symbol)

    The name of the admin flag column on the users table for the default permissions model



80
81
82
# File 'lib/thredded.rb', line 80

def admin_column
  @admin_column
end

.auto_follow_when_creating_topicBoolean

Returns Whether the user should get subscribed to a new topic they've created.

Returns:

  • (Boolean)

    Whether the user should get subscribed to a new topic they've created.



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

def auto_follow_when_creating_topic
  @auto_follow_when_creating_topic
end

.auto_follow_when_posting_in_topicBoolean

Returns Whether the user should get subscribed to a topic after posting in it.

Returns:

  • (Boolean)

    Whether the user should get subscribed to a topic after posting in it.



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

def auto_follow_when_posting_in_topic
  @auto_follow_when_posting_in_topic
end

.autocomplete_min_lengthNumber

Returns Minimum length to trigger username auto-completion for @-mentions and private message recipients.

Returns:

  • (Number)

    Minimum length to trigger username auto-completion for @-mentions and private message recipients.



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

def autocomplete_min_length
  @autocomplete_min_length
end

.avatar_urlProc

Returns A lambda that returns the avatar URL for the given user.

Returns:

  • (Proc)

    A lambda that returns the avatar URL for the given user.



74
75
76
# File 'lib/thredded.rb', line 74

def avatar_url
  @avatar_url
end

.content_visible_while_pending_moderationBoolean

Returns Whether posts that are pending moderation are visible to regular users.

Returns:

  • (Boolean)

    Whether posts that are pending moderation are visible to regular users.



85
86
87
# File 'lib/thredded.rb', line 85

def content_visible_while_pending_moderation
  @content_visible_while_pending_moderation
end

.current_user_methodSymbol

Returns The name of the method used by Thredded controllers and views to get the currently signed-in user

Returns:

  • (Symbol)

    The name of the method used by Thredded controllers and views to get the currently signed-in user



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

def current_user_method
  @current_user_method
end

.currently_online_enabledBoolean

Returns Whether the list of users who are currently online is displayed.

Returns:

  • (Boolean)

    Whether the list of users who are currently online is displayed.



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

def currently_online_enabled
  @currently_online_enabled
end

.email_fromString

Returns Sender email for Thredded notification emails.

Returns:

  • (String)

    Sender email for Thredded notification emails.



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

def email_from
  @email_from
end

.email_outgoing_prefixString

Returns Email subject prefix.

Returns:

  • (String)

    Email subject prefix.



154
155
156
# File 'lib/thredded.rb', line 154

def email_outgoing_prefix
  @email_outgoing_prefix
end

.layoutString

Returns The layout to use for rendering Thredded views.

Returns:

  • (String)

    The layout to use for rendering Thredded views.



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

def layout
  @layout
end

.messageboard_name_length_rangeRange<Integer>

Returns The range of valid messageboard name lengths.

Returns:

  • (Range<Integer>)

    The range of valid messageboard name lengths.



171
172
173
# File 'lib/thredded.rb', line 171

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

Returns:

  • (:position, :last_post_at_desc, :topics_count_desc)


123
124
125
# File 'lib/thredded.rb', line 123

def messageboards_order
  @messageboards_order
end

.moderator_columnSymbol

Returns The name of the moderator flag column on the users table for the default permissions model

Returns:

  • (Symbol)

    The name of the moderator flag column on the users table for the default permissions model



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

def moderator_column
  @moderator_column
end

.parent_mailerString

Returns The name of the parent mailer class for Thredded mailers.

Returns:

  • (String)

    The name of the parent mailer class for Thredded mailers.



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

def parent_mailer
  @parent_mailer
end

.posts_per_pageNumber

Returns The number of posts to display per page in a topic.

Returns:

  • (Number)

    The number of posts to display per page in a topic.



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

def posts_per_page
  @posts_per_page
end

.private_messaging_enabledBoolean

Returns Whether the private messaging functionality is enabled.

Returns:

  • (Boolean)

    Whether the private messaging functionality is enabled.



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

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}/


166
167
168
# File 'lib/thredded.rb', line 166

def routes_id_constraint
  @routes_id_constraint
end

.show_topic_followersBoolean

Returns Whether users that are following a topic are listed on the topic page.

Returns:

  • (Boolean)

    Whether users that are following a topic are listed on the topic page.



101
102
103
# File 'lib/thredded.rb', line 101

def show_topic_followers
  @show_topic_followers
end

.slugifierProc

Returns The proc that Thredded uses to generate URL slugs from text.

Returns:

  • (Proc)

    The proc that Thredded uses to generate URL slugs from text.



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

def slugifier
  @slugifier
end

.topic_title_length_rangeRange<Integer>

Returns The range of valid topic title lengths.

Returns:

  • (Range<Integer>)

    The range of valid topic title lengths.



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

def topic_title_length_range
  @topic_title_length_range
end

.topics_per_pageNumber

Returns The number of topics to display per page.

Returns:

  • (Number)

    The number of topics to display per page.



126
127
128
# File 'lib/thredded.rb', line 126

def topics_per_page
  @topics_per_page
end

.user_class_nameString (readonly)

Returns The name of the user class

Returns:

  • (String)

    The name of the user class



62
63
64
# File 'lib/thredded.rb', line 62

def user_class_name
  @user_class_name
end

.user_display_name_methodSymbol

Returns The name of the method used by Thredded to display users

Returns:

  • (Symbol)

    The name of the method used by Thredded to display users



188
189
190
# File 'lib/thredded.rb', line 188

def user_display_name_method
  @user_display_name_method || user_name_column
end

.user_name_columnSymbol

Returns The user table column that contains the username. Must be unique.

Returns:

  • (Symbol)

    The user table column that contains the username. Must be unique.



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

def user_name_column
  @user_name_column
end

.user_path(view_context, user) ⇒ String

Returns path to the user evaluated in the specified context.

Parameters:

Returns:

  • (String)

    path to the user evaluated in the specified context.



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

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

Class Method Details

.notifiersArray

Returns The notifiers, by default just the EmailNotifier

Returns:

  • (Array)

    The notifiers, by default just the EmailNotifier



177
178
179
# File 'lib/thredded.rb', line 177

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

.notifiers=(notifiers) ⇒ Object

Parameters:

  • notifiers (Array)


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

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.

Parameters:

  • scope (ActiveRecord::Relation<Thredded::Post>)

    the posts scope for which to return the view.

  • current_user (Thredded.user_class, nil)

    the user viewing the posts.

Returns:



237
238
239
240
241
242
243
244
245
# File 'lib/thredded.rb', line 237

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.

Returns:

  • (Boolean)


248
249
250
251
# File 'lib/thredded.rb', line 248

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

.standalone_layout?Boolean

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

Returns:

  • (Boolean)


225
226
227
# File 'lib/thredded.rb', line 225

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

.user_classClass<Thredded::UserExtender>

Returns the user class from the host application.

Returns:



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

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

Parameters:

  • user_class_name (String)


203
204
205
206
207
208
# File 'lib/thredded.rb', line 203

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

Returns View hooks configuration.

Returns:



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

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