<commit_before>package backend.model.messaging

import backend.model.misc.Email
import backend.model.misc.EmailAddress
import backend.model.user.UserAccount
import backend.model.user.UserRepository
import backend.services.NotificationService
import backend.services.mail.MailService
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class GroupMessageServiceImpl(val repository: GroupMessageRepository,
                              val userRepository: UserRepository,
                              val mailService: MailService,
                              val notificationServer: NotificationService) : GroupMessageService {

    @Transactional
    override fun createGroupMessage(creator: UserAccount): GroupMessage {
        val groupMessage = GroupMessage(creator)
        return repository.save(groupMessage)
    }

    override fun getByID(id: Long): GroupMessage? = repository.findById(id)

    override fun save(groupMessage: GroupMessage): GroupMessage = repository.save(groupMessage)

    @Transactional
    override fun addUser(user: UserAccount, groupMessage: GroupMessage): GroupMessage {
        groupMessage.addUser(user)

        val email = Email(
                to = listOf(EmailAddress(user.email)),
                subject = "BreakOut 2016 - Du wurdest einer Gruppennachricht hinzugefügt!",
                body = "Hallo ${user.firstname ?: ""},<br><br>" +
                        "Du wurdest einer neuen Gruppennachricht hinzugefügt. Sieh nach was man Dir mitteilen mag!<br><br>" +
                        "Liebe Grüße<br>" +
                        "Euer BreakOut-Team",
                buttonText = "NACHRICHT ÖFFNEN",
                buttonUrl = "https://anmeldung.break-out.org/messages/${groupMessage.id}?utm_source=backend&utm_medium=email&utm_content=intial&utm_campaign=add_groupmessage",
                campaignCode = "add_groupmessage"
        )

        mailService.send(email)

        return repository.save(groupMessage)
    }

    @Transactional
    override fun addMessage(message: Message, groupMessage: GroupMessage): GroupMessage {
        userRepository.save(message.creator)
        groupMessage.addMessage(message)
        val notifiedUsers = groupMessage.users.filter { it.id != message.creator.id && groupMessage.isBlockedBy(it.id) }
        notificationServer.notifyNewMessage(message, groupMessage.id, notifiedUsers)
        return repository.save(groupMessage)
    }
}<commit_msg>Fixing message notifications doing blocking wrong<commit_after>package backend.model.messaging

import backend.model.misc.Email
import backend.model.misc.EmailAddress
import backend.model.user.UserAccount
import backend.model.user.UserRepository
import backend.services.NotificationService
import backend.services.mail.MailService
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class GroupMessageServiceImpl(val repository: GroupMessageRepository,
                              val userRepository: UserRepository,
                              val mailService: MailService,
                              val notificationServer: NotificationService) : GroupMessageService {

    @Transactional
    override fun createGroupMessage(creator: UserAccount): GroupMessage {
        val groupMessage = GroupMessage(creator)
        return repository.save(groupMessage)
    }

    override fun getByID(id: Long): GroupMessage? = repository.findById(id)

    override fun save(groupMessage: GroupMessage): GroupMessage = repository.save(groupMessage)

    @Transactional
    override fun addUser(user: UserAccount, groupMessage: GroupMessage): GroupMessage {
        groupMessage.addUser(user)

        val email = Email(
                to = listOf(EmailAddress(user.email)),
                subject = "BreakOut 2016 - Du wurdest einer Gruppennachricht hinzugefügt!",
                body = "Hallo ${user.firstname ?: ""},<br><br>" +
                        "Du wurdest einer neuen Gruppennachricht hinzugefügt. Sieh nach was man Dir mitteilen mag!<br><br>" +
                        "Liebe Grüße<br>" +
                        "Euer BreakOut-Team",
                buttonText = "NACHRICHT ÖFFNEN",
                buttonUrl = "https://anmeldung.break-out.org/messages/${groupMessage.id}?utm_source=backend&utm_medium=email&utm_content=intial&utm_campaign=add_groupmessage",
                campaignCode = "add_groupmessage"
        )

        mailService.send(email)

        return repository.save(groupMessage)
    }

    @Transactional
    override fun addMessage(message: Message, groupMessage: GroupMessage): GroupMessage {
        userRepository.save(message.creator)
        groupMessage.addMessage(message)
        val notifiedUsers = groupMessage.users.filter { it.id != message.creator.id && !groupMessage.isBlockedBy(it.id) }
        notificationServer.notifyNewMessage(message, groupMessage.id, notifiedUsers)
        return repository.save(groupMessage)
    }
}
{'fraction_non_alphanumeric': 0.08470541559214441, 'fraction_numerical': 0.0015869867089863122, 'mean_word_length': 3.0143312101910826, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2275961', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1276, 'n_words': 265}