Commit 3b0c1020 authored by Benjamin Neff's avatar Benjamin Neff
Browse files

Merge pull request #6818 from cmrd-senya/1851-mentions-in-comments.new

Mentions in comments backend changes
parents 4fb9d6ed 33ad411b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
## Bug fixes

## Features
* Add support for mentions in comments to the backend [#6818](https://github.com/diaspora/diaspora/pull/6818)

# 0.6.2.0

+17 −4
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@ class NotificationsController < ApplicationController

  def index
    conditions = {:recipient_id => current_user.id}
    if params[:type] && Notification.types.has_key?(params[:type])
      conditions[:type] = Notification.types[params[:type]]
    if params[:type] && types.has_key?(params[:type])
      conditions[:type] = types[params[:type]]
    end
    if params[:show] == "unread" then conditions[:unread] = true end
    page = params[:page] || 1
@@ -44,7 +44,7 @@ class NotificationsController < ApplicationController

    @grouped_unread_notification_counts = {}

    Notification.types.each_with_object(current_user.unread_notifications.group_by(&:type)) {|(name, type), notifications|
    types.each_with_object(current_user.unread_notifications.group_by(&:type)) {|(name, type), notifications|
      @grouped_unread_notification_counts[name] = notifications.has_key?(type) ? notifications[type].count : 0
    }

@@ -65,7 +65,7 @@ class NotificationsController < ApplicationController
  end

  def read_all
    current_type = Notification.types[params[:type]]
    current_type = types[params[:type]]
    notifications = Notification.where(recipient_id: current_user.id, unread: true)
    notifications = notifications.where(type: current_type) if params[:type]
    notifications.update_all(unread: false)
@@ -93,4 +93,17 @@ class NotificationsController < ApplicationController
      }
    }.as_json
  end

  def types
    {
      "also_commented"       => "Notifications::AlsoCommented",
      "comment_on_post"      => "Notifications::CommentOnPost",
      "liked"                => "Notifications::Liked",
      "mentioned"            => "Notifications::MentionedInPost",
      "mentioned_in_comment" => "Notifications::MentionedInComment",
      "reshared"             => "Notifications::Reshared",
      "started_sharing"      => "Notifications::StartedSharing"
    }
  end
  helper_method :types
end
+4 −1
Original line number Diff line number Diff line
@@ -80,7 +80,10 @@ class StatusMessagesController < ApplicationController

  def handle_mention_feedback(status_message)
    return unless comes_from_others_profile_page?
    flash[:notice] = t("status_messages.create.success", names: status_message.mentioned_people_names)
    flash[:notice] = t(
      "status_messages.create.success",
      names: PersonPresenter.people_names(status_message.mentioned_people)
    )
  end

  def comes_from_others_profile_page?
+1 −10
Original line number Diff line number Diff line
@@ -150,16 +150,7 @@ class UsersController < ApplicationController
      :auto_follow_back_aspect_id,
      :getting_started,
      :post_default_public,
      email_preferences: %i(
        someone_reported
        also_commented
        mentioned
        comment_on_post
        private_message
        started_sharing
        liked
        reshared
      )
      email_preferences: UserPreference::VALID_EMAIL_TYPES.map(&:to_sym)
    )
  end
  # rubocop:enable Metrics/MethodLength
+30 −26
Original line number Diff line number Diff line
@@ -2,42 +2,46 @@ module NotificationsHelper
  include PeopleHelper
  include PostsHelper

  def object_link(note, actors)
  def object_link(note, actors_html)
    target_type = note.popup_translation_key
    actors_count = note.actors.size
    opts = {actors: actors_html, count: note.actors.size}

    if note.instance_of?(Notifications::Mentioned)
      if post = note.linked_object
        translation(target_type,
                    actors:    actors,
                    count:     actors_count,
                    post_link: link_to(post_page_title(post), post_path(post)).html_safe)
      else
        t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe
      end
    elsif note.instance_of?(Notifications::CommentOnPost) || note.instance_of?(Notifications::AlsoCommented) || note.instance_of?(Notifications::Reshared) || note.instance_of?(Notifications::Liked)
      if post = note.linked_object
        translation(target_type,
                    actors:      actors,
                    count:       actors_count,
                    post_author: h(post.author_name),
                    post_link:   link_to(post_page_title(post),
                                         post_path(post),
                                         data:  {ref: post.id},
                                         class: "hard_object_link").html_safe)
      else
        t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe
    if note.respond_to?(:linked_object)
      if note.linked_object.nil? && note.respond_to?(:deleted_translation_key)
        target_type = note.deleted_translation_key
      elsif note.is_a?(Notifications::Mentioned)
        opts.merge!(opts_for_mentioned(note.linked_object))
      elsif %w(Notifications::CommentOnPost Notifications::AlsoCommented Notifications::Reshared Notifications::Liked)
            .include?(note.type)
        opts.merge!(opts_for_post(note.linked_object))
      end
    else #Notifications:StartedSharing, etc.
      translation(target_type, :actors => actors, :count => actors_count)
    end
    translation(target_type, opts)
  end

  def translation(target_type, opts = {})
    {:post_author => nil}.merge!(opts)
    t("#{target_type}", opts).html_safe
  end

  def opts_for_post(post)
    {
      post_author: html_escape(post.author_name),
      post_link:   link_to(post_page_title(post),
                           post_path(post),
                           data:  {ref: post.id},
                           class: "hard_object_link").html_safe
    }
  end

  def opts_for_mentioned(mentioned)
    post = mentioned.instance_of?(Comment) ? mentioned.parent : mentioned
    {
      post_link: link_to(post_page_title(post), post_path(post)).html_safe
    }.tap {|opts|
      opts[:comment_path] = post_path(post, anchor: mentioned.guid).html_safe if mentioned.instance_of?(Comment)
    }
  end

  def notification_people_link(note, people=nil)
    actors =people || note.actors
    number_of_actors = actors.size
Loading