<commit_before>module SocialNetworking
  # Provide Participant home page tools.
  class HomesController < ApplicationController
    def show
      @action_items = ActionItem.for(current_participant)
      current_profile = Profile.find_by_participant_id(current_participant.id)
      if !current_profile || !current_profile.icon_name
        @action_items.unshift(
          link: social_networking_profile_path,
          label: "Create a Profile"
        )
      end

      @feed_items = (
      Serializers::OnTheMindStatementSerializer
        .from_collection(
          OnTheMindStatement.joins(participant: [{ memberships: :group }])
            .where(groups: { id: current_participant.active_group.id })
            .includes(:comments, :likes)) +
        Serializers::NudgeSerializer
          .from_collection(
            Nudge.joins(initiator: [{ memberships: :group }])
              .where(groups: { id: current_participant.active_group.id })
              .includes(:comments)) +
        Serializers::SharedItemSerializer
          .from_collection(group_shared_items(current_participant)))
      set_member_profiles
    end

    private

    def group_shared_items(current_participant)
      all_shared_items = SharedItem.includes(:item, :comments, :likes)
      participant_group_shared_items = []
      all_shared_items.each do |shared_item|
        if shared_item.item.participant.active_group.id ==
           current_participant.active_group.id
          participant_group_shared_items.push(shared_item)
        end
      end
      participant_group_shared_items
    end

    def set_member_profiles
      return if current_participant.active_group.nil?<commit_msg>[#84782718] Updated feed logic to ensure properly formatted shared items.<commit_after>module SocialNetworking
  # Provide Participant home page tools.
  class HomesController < ApplicationController
    def show
      @action_items = ActionItem.for(current_participant)
      current_profile = Profile.find_by_participant_id(current_participant.id)
      if !current_profile || !current_profile.icon_name
        @action_items.unshift(
          link: social_networking_profile_path,
          label: "Create a Profile"
        )
      end

      @feed_items = (
      Serializers::OnTheMindStatementSerializer
        .from_collection(
          OnTheMindStatement.joins(participant: [{ memberships: :group }])
            .where(groups: { id: current_participant.active_group.id })
            .includes(:comments, :likes)) +
        Serializers::NudgeSerializer
          .from_collection(
            Nudge.joins(initiator: [{ memberships: :group }])
              .where(groups: { id: current_participant.active_group.id })
              .includes(:comments)) +
        Serializers::SharedItemSerializer
          .from_collection(group_shared_items(current_participant)))
      set_member_profiles
    end

    private

    def group_shared_items(current_participant)
      all_shared_items = SharedItem.includes(:item, :comments, :likes)
      participant_group_shared_items = []
      all_shared_items.each do |shared_item|
        if shared_item.item &&
           shared_item.item.participant.active_group.id ==
           current_participant.active_group.id
          participant_group_shared_items.push(shared_item)
        end
      end
      participant_group_shared_items
    end

    def set_member_profiles
      return if current_participant.active_group.nil?
{'fraction_non_alphanumeric': 0.07821067821067822, 'fraction_numerical': 0.002308802308802309, 'mean_word_length': 2.9431171786120593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2008911', 'n_tokens_mistral': 993, 'n_tokens_neox': 952, 'n_words': 159}