Interface MessageReadReceiptRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<MessageReadReceipt,UUID>, org.springframework.data.jpa.repository.JpaRepository<MessageReadReceipt,UUID>, org.springframework.data.repository.ListCrudRepository<MessageReadReceipt,UUID>, org.springframework.data.repository.ListPagingAndSortingRepository<MessageReadReceipt,UUID>, org.springframework.data.repository.PagingAndSortingRepository<MessageReadReceipt,UUID>, org.springframework.data.repository.query.QueryByExampleExecutor<MessageReadReceipt>, org.springframework.data.repository.Repository<MessageReadReceipt,UUID>

@Repository public interface MessageReadReceiptRepository extends org.springframework.data.jpa.repository.JpaRepository<MessageReadReceipt,UUID>
  • Method Summary

    Modifier and Type
    Method
    Description
    countUnreadByConversationIdIn(UUID userId, Set<UUID> conversationIds)
    Count the unread messages for a specific conversation, ordered by creation timestamp
    findByMessageIdIn(Set<UUID> messageIds)
    Find all read receipts for provided message ids
    Find the earliest unread message for a specific conversation, ordered by creation timestamp
    getAllMessagesToMarkAsReadByUser(UUID userId, UUID conversationId)
    Get all messages in a conversation to mark as read by a user (bulk operation)
    getMessagesByIdInToMarkAsReadByUser(UUID userId, UUID conversationId, Set<UUID> ids)
    Gets all messages in a conversation to mark as read by a user (bulk operation) for the provided ids.
    getMessagesUptoCreatedAtToMarkAsReadByUser(UUID userId, UUID conversationId, Instant uptoCreatedAt)
    Get all messages in a conversation to mark as read by a user (bulk operation) upto the created at value provided.
    int
    markAllMessagesAsReadByUser(UUID userId, UUID conversationId, Instant readAt)
    Mark all messages in a conversation as read by a user (bulk operation) This creates read receipts for all unread messages
    int
    markMessagesByIdInAsReadByUser(UUID userId, UUID conversationId, Set<UUID> ids, Instant readAt)
    Mark all messages in a conversation as read by a user (bulk operation) for the provided ids.
    int
    markMessagesUptoCreatedAtAsReadByUser(UUID userId, UUID conversationId, Instant uptoCreatedAt, Instant readAt)
    Mark all messages in a conversation as read by a user (bulk operation) upto the created at value provided.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findByMessageIdIn

      List<MessageReadReceipt> findByMessageIdIn(Set<UUID> messageIds)
      Find all read receipts for provided message ids
    • getAllMessagesToMarkAsReadByUser

      @Modifying @Query(value="SELECT cm.id\nFROM chat_messages cm\nWHERE cm.conversation_id = :conversationId\nAND cm.sender_id != :userId\nAND NOT EXISTS (SELECT 1 FROM message_read_receipts mrr WHERE mrr.message_id = cm.id AND mrr.user_id = :userId)\n", nativeQuery=true) List<UUID> getAllMessagesToMarkAsReadByUser(@Param("userId") UUID userId, @Param("conversationId") UUID conversationId)
      Get all messages in a conversation to mark as read by a user (bulk operation)
    • markAllMessagesAsReadByUser

      @Modifying @Query(value="INSERT INTO message_read_receipts (message_id, user_id, conversation_id, read_at, created_at)\nSELECT cm.id, :userId, :conversationId, :readAt, :readAt\nFROM chat_messages cm\nWHERE cm.conversation_id = :conversationId\nAND cm.sender_id != :userId\nAND NOT EXISTS (SELECT 1 FROM message_read_receipts mrr WHERE mrr.message_id = cm.id AND mrr.user_id = :userId)\n", nativeQuery=true) int markAllMessagesAsReadByUser(@Param("userId") UUID userId, @Param("conversationId") UUID conversationId, @Param("readAt") Instant readAt)
      Mark all messages in a conversation as read by a user (bulk operation) This creates read receipts for all unread messages
    • getMessagesUptoCreatedAtToMarkAsReadByUser

      @Modifying @Query(value="SELECT cm.id\nFROM chat_messages cm\nWHERE cm.conversation_id = :conversationId\nAND cm.sender_id != :userId\nAND cm.created_at <= :uptoCreatedAt\nAND NOT EXISTS (SELECT 1 FROM message_read_receipts mrr WHERE mrr.message_id = cm.id AND mrr.user_id = :userId)\n", nativeQuery=true) List<UUID> getMessagesUptoCreatedAtToMarkAsReadByUser(@Param("userId") UUID userId, @Param("conversationId") UUID conversationId, @Param("uptoCreatedAt") Instant uptoCreatedAt)
      Get all messages in a conversation to mark as read by a user (bulk operation) upto the created at value provided.
    • markMessagesUptoCreatedAtAsReadByUser

      @Modifying @Query(value="INSERT INTO message_read_receipts (message_id, user_id, conversation_id, read_at, created_at)\nSELECT cm.id, :userId, :conversationId, :readAt, :readAt\nFROM chat_messages cm\nWHERE cm.conversation_id = :conversationId\nAND cm.sender_id != :userId\nAND cm.created_at <= :uptoCreatedAt\nAND NOT EXISTS (SELECT 1 FROM message_read_receipts mrr WHERE mrr.message_id = cm.id AND mrr.user_id = :userId)\n", nativeQuery=true) int markMessagesUptoCreatedAtAsReadByUser(@Param("userId") UUID userId, @Param("conversationId") UUID conversationId, @Param("uptoCreatedAt") Instant uptoCreatedAt, @Param("readAt") Instant readAt)
      Mark all messages in a conversation as read by a user (bulk operation) upto the created at value provided. This creates read receipts for all relevant unread messages
    • getMessagesByIdInToMarkAsReadByUser

      @Query(value="SELECT cm.id\nFROM chat_messages cm\nWHERE cm.conversation_id = :conversationId\nAND cm.sender_id != :userId\nAND cm.id IN (:ids)\nAND NOT EXISTS (SELECT 1 FROM message_read_receipts mrr WHERE mrr.message_id = cm.id AND mrr.user_id = :userId)\n", nativeQuery=true) List<UUID> getMessagesByIdInToMarkAsReadByUser(@Param("userId") UUID userId, @Param("conversationId") UUID conversationId, @Param("ids") Set<UUID> ids)
      Gets all messages in a conversation to mark as read by a user (bulk operation) for the provided ids.
    • markMessagesByIdInAsReadByUser

      @Modifying @Query(value="INSERT INTO message_read_receipts (message_id, user_id, conversation_id, read_at, created_at)\nSELECT cm.id, :userId, :conversationId, :readAt, :readAt\nFROM chat_messages cm\nWHERE cm.conversation_id = :conversationId\nAND cm.sender_id != :userId\nAND cm.id IN (:ids)\nAND NOT EXISTS (SELECT 1 FROM message_read_receipts mrr WHERE mrr.message_id = cm.id AND mrr.user_id = :userId)\n", nativeQuery=true) int markMessagesByIdInAsReadByUser(@Param("userId") UUID userId, @Param("conversationId") UUID conversationId, @Param("ids") Set<UUID> ids, @Param("readAt") Instant readAt)
      Mark all messages in a conversation as read by a user (bulk operation) for the provided ids. This creates read receipts for all relevant unread messages
    • countUnreadByConversationIdIn

      @Query(" SELECT new com.finconsgroup.itserr.marketplace.usercommunication.dm.dto.OutputConversationMessageSummaryDto(cm.conversationId, count(cm))\n FROM ChatMessage cm\n LEFT JOIN MessageReadReceipt mrr ON mrr.messageId = cm.id AND mrr.userId = :userId\n WHERE cm.conversationId IN (:conversationIds)\n AND cm.senderId <> :userId\n AND mrr.id IS NULL\n") List<OutputConversationMessageSummaryDto> countUnreadByConversationIdIn(@Param("userId") UUID userId, @Param("conversationIds") Set<UUID> conversationIds)
      Count the unread messages for a specific conversation, ordered by creation timestamp
    • findEarliestUnreadByConversationIdIn

      @Query(value=" WITH messages AS (SELECT cm.*,\n rank() OVER (PARTITION BY cm.conversation_id ORDER by cm.created_at) message_rank\n FROM chat_messages cm\n left join message_read_receipts mrr on mrr.message_id = cm.id and mrr.user_id = :userId\n WHERE cm.conversation_id IN (:conversationIds)\n AND cm.sender_id <> :userId\n AND mrr.id IS NULL)\n SELECT messages.* FROM messages WHERE message_rank = 1\n", nativeQuery=true) List<ChatMessage> findEarliestUnreadByConversationIdIn(@Param("userId") UUID userId, @Param("conversationIds") Set<UUID> conversationIds)
      Find the earliest unread message for a specific conversation, ordered by creation timestamp