Interface ConversationParticipantRepository

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

@Repository public interface ConversationParticipantRepository extends org.springframework.data.jpa.repository.JpaRepository<ConversationParticipant,UUID>
  • Method Details

    • findByConversationIdAndUserId

      Optional<ConversationParticipant> findByConversationIdAndUserId(UUID conversationId, UUID userId)
      Find a participant by conversation ID and user ID
    • findByConversationIdAndActiveIsTrue

      List<ConversationParticipant> findByConversationIdAndActiveIsTrue(UUID conversationId)
      Find all active participants in a conversation
    • findByUserIdAndActiveIsTrue

      List<ConversationParticipant> findByUserIdAndActiveIsTrue(UUID userId)
      Find all conversations for a user (active participation)
    • existsByConversationIdAndUserIdAndActiveIsTrue

      boolean existsByConversationIdAndUserIdAndActiveIsTrue(UUID conversationId, UUID userId)
      Check if a user is a participant in a conversation
    • hasAdminPrivileges

      @Query("SELECT CASE WHEN COUNT(cp) > 0 THEN true ELSE false END FROM ConversationParticipant cp WHERE cp.conversationId = :conversationId AND cp.userId = :userId AND cp.active = true AND (cp.role = \'OWNER\' OR cp.role = \'ADMIN\')") boolean hasAdminPrivileges(@Param("conversationId") UUID conversationId, @Param("userId") UUID userId)
      Check if a user has admin privileges in a conversation
    • countByConversationIdAndActiveIsTrue

      long countByConversationIdAndActiveIsTrue(UUID conversationId)
      Count active participants in a conversation
    • updateParticipantRole

      @Modifying @Query("UPDATE ConversationParticipant cp SET cp.role = :role WHERE cp.conversationId = :conversationId AND cp.userId = :userId") void updateParticipantRole(@Param("conversationId") UUID conversationId, @Param("userId") UUID userId, @Param("role") ParticipantRole role)
      Update participant role
    • updateParticipantActiveStatus

      @Modifying @Query("UPDATE ConversationParticipant cp SET cp.active = :isActive WHERE cp.conversationId = :conversationId AND cp.userId = :userId") void updateParticipantActiveStatus(@Param("conversationId") UUID conversationId, @Param("userId") UUID userId, @Param("isActive") boolean isActive)
      Update participant active status
    • updateParticipantMuteStatus

      @Modifying @Query("UPDATE ConversationParticipant cp SET cp.muted = :isMuted WHERE cp.conversationId = :conversationId AND cp.userId = :userId") void updateParticipantMuteStatus(@Param("conversationId") UUID conversationId, @Param("userId") UUID userId, @Param("isMuted") boolean isMuted)
      Update participant mute status
    • updateNotificationSettings

      @Modifying @Query("UPDATE ConversationParticipant cp SET cp.notificationEnabled = :enabled WHERE cp.conversationId = :conversationId AND cp.userId = :userId") void updateNotificationSettings(@Param("conversationId") UUID conversationId, @Param("userId") UUID userId, @Param("enabled") boolean enabled)
      Update participant notification settings
    • updateLastReadAt

      @Modifying @Query("UPDATE ConversationParticipant cp SET cp.lastReadAt = :timestamp WHERE cp.conversationId = :conversationId AND cp.userId = :userId") void updateLastReadAt(@Param("conversationId") UUID conversationId, @Param("userId") UUID userId, @Param("timestamp") Instant timestamp)
      Update last read timestamp for a participant
    • removeParticipant

      @Modifying @Query("UPDATE ConversationParticipant cp SET cp.active = false WHERE cp.conversationId = :conversationId AND cp.userId = :userId") void removeParticipant(@Param("conversationId") UUID conversationId, @Param("userId") UUID userId)
      Remove participant from conversation (set inactive)
    • findConversationsWithUnreadMessages

      @Query("SELECT cp FROM ConversationParticipant cp WHERE cp.userId = :userId AND cp.active = true AND (cp.lastReadAt IS NULL OR cp.lastReadAt < (SELECT MAX(cm.createdAt) FROM ChatMessage cm WHERE cm.conversationId = cp.conversationId))") List<ConversationParticipant> findConversationsWithUnreadMessages(@Param("userId") UUID userId)
      Find conversations where user has unread messages