app/application/ports/repositories/post_repo.rb
# Returns an array of tuples unique to each chat with arrays
# of ids of posts that the user should be notified about.
Returns an array of tuples unique to each chat with arrays
of ids of posts that the user should be notified about.
Returns an array of tuples unique to each chat with arrays of ids of posts that the user should be notified about .
def aggregate_relevant_by_chat_ids
          posts.read(<<~QUERY.chomp).to_a
            select result.chat_id, array_agg(result.post_id) as post_ids
            from (
              select posts.id as post_id, chats.id as chat_id
              from posts
              left join blogs on posts.blog_id = blogs.id
              left join chats_blogs on chats_blogs.blog_id = blogs.id
              left join chats on chats.id = chats_blogs.chat_id
              where posts.created_at > chats_blogs.created_at
              except select post_id, chat_id from chat_notifications
            ) as result
            group by chat_id;
          QUERY
        end
def aggregate_relevant_by_chat_ids posts . read ( <<~QUERY . chomp ) . to_a 
            select result.chat_id, array_agg(result.post_id) as post_ids
            from (
              select posts.id as post_id, chats.id as chat_id
              from posts
              left join blogs on posts.blog_id = blogs.id
              left join chats_blogs on chats_blogs.blog_id = blogs.id
              left join chats on chats.id = chats_blogs.chat_id
              where posts.created_at > chats_blogs.created_at
              except select post_id, chat_id from chat_notifications
            ) as result
            group by chat_id;
           QUERY end
Returns an array of tuples unique to each chat with arrays
of ids of posts that the user should be notified about.
Returns an array of tuples unique to each chat with arrays of ids of posts that the user should be notified about .