def send_message_after_chat(chat_from: int, chat: str, project_id: int):
        """ Send alert to user if they were @'d in a chat message """
        current_app.logger.debug('Sending Message After Chat')
        usernames = MessageService._parse_message_for_username(chat)

        if len(usernames) == 0:
            return  # Nobody @'d so return

        link = MessageService.get_project_link(project_id)

        for username in usernames:
            current_app.logger.debug(f'Searching for {username}')
            try:
                user = UserService.get_user_by_username(username)
            except NotFound:
                current_app.logger.error(f'Username {username} not found')
                continue  # If we can't find the user, keep going no need to fail

            message = Message()
            message.message_type = MessageType.MENTION_NOTIFICATION.value
            message.project_id = project_id
            message.from_user_id = chat_from
            message.to_user_id = user.id
            message.subject = f'You were mentioned in Project Chat on {link}'
            message.message = chat
            message.add_message()
            SMTPService.send_email_alert(user.email_address, user.username)
    def send_message_after_comment(comment_from: int, comment: str,
                                   task_id: int, project_id: int):
        """ Will send a canned message to anyone @'d in a comment """
        usernames = MessageService._parse_message_for_username(comment)

        if len(usernames) == 0:
            return  # Nobody @'d so return

        task_link = MessageService.get_task_link(project_id, task_id)
        project_title = ProjectService.get_project_title(project_id)
        for username in usernames:

            try:
                user = UserService.get_user_by_username(username)
            except NotFound:
                continue  # If we can't find the user, keep going no need to fail

            message = Message()
            message.message_type = MessageType.MENTION_NOTIFICATION.value
            message.project_id = project_id
            message.task_id = task_id
            message.from_user_id = comment_from
            message.to_user_id = user.id
            message.subject = f'You were mentioned in a comment in Project {project_id} on {task_link}'
            message.message = comment
            message.add_message()
            SMTPService.send_email_alert(user.email_address, user.username)
    def send_welcome_message(user: User):
        """ Sends welcome message to all new users at Sign up"""
        text_template = get_template('welcome_message_en.txt')

        text_template = text_template.replace('[USERNAME]', user.username)
        text_template = text_template.replace('[PROFILE_LINK]',
                                              get_profile_url(user.username))

        welcome_message = Message()
        welcome_message.message_type = MessageType.SYSTEM.value
        welcome_message.to_user_id = user.id
        welcome_message.subject = 'Welcome to the HOT Tasking Manager'
        welcome_message.message = text_template
        welcome_message.save()

        return welcome_message.id