You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: topic_common.rb
    path of file: ./repos/thredded/app/models/concerns/thredded
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

module Thredded
  module TopicCommon
    extend ActiveSupport::Concern
    included do
      paginates_per Thredded.topics_per_page if respond_to?(:paginates_per)

      belongs_to :last_
    
      def unread(user)
        topics = arel_table
        reads_class = reflect_on_association(:user_read_states).klass
        reads = reads_class.arel_table

        joins_reads =
          topics.outer_join(reads)
            .on(topics[:id].eq(reads[:postable_id]).and(reads[:user_id].eq(user.id))).join_sources

        unread_scope = reads_class.where(reads[:id].eq(nil).or(reads[:unread_posts_count].not_eq(0)))

        joins(joins_reads).merge(unread_scope)
      end