def send_message_to_all_team_members(team_id: int, team_name: str, message_dto: MessageDTO): """Sends supplied message to all contributors in a team. Message all team members can take over a minute to run, so this method is expected to be called on its own thread""" app = ( create_app() ) # Because message-all run on background thread it needs it's own app context with app.app_context(): team_members = TeamService._get_active_team_members(team_id) sender = UserService.get_user_by_id( message_dto.from_user_id).username message_dto.message = ( "A message from {}, manager of {} team:<br/><br/>{}".format( MessageService.get_user_profile_link(sender), MessageService.get_team_link(team_name, team_id, False), markdown(message_dto.message, output_format="html"), )) messages = [] for team_member in team_members: if team_member.user_id != message_dto.from_user_id: message = Message.from_dto(team_member.user_id, message_dto) message.message_type = MessageType.TEAM_BROADCAST.value message.save() user = UserService.get_user_by_id(team_member.user_id) messages.append(dict(message=message, user=user)) MessageService._push_messages(messages)
def send_message_to_all_contributors(project_id: int, message_dto: MessageDTO): """Sends supplied message to all contributors on specified project. Message all contributors can take over a minute to run, so this method is expected to be called on its own thread""" app = ( create_app() ) # Because message-all run on background thread it needs it's own app context with app.app_context(): contributors = Message.get_all_contributors(project_id) message_dto.message = "A message from {} managers:<br/><br/>{}".format( MessageService.get_project_link(project_id), markdown(message_dto.message, output_format="html"), ) messages = [] for contributor in contributors: message = Message.from_dto(contributor[0], message_dto) message.message_type = MessageType.BROADCAST.value message.project_id = project_id user = UserService.get_user_by_id(contributor[0]) messages.append(dict(message=message, user=user)) MessageService._push_messages(messages)
def send_message_to_all_contributors(project_id: int, message_dto: MessageDTO): """ Sends supplied message to all contributors on specified project. Message all contributors can take over a minute to run, so this method is expected to be called on its own thread """ app = ( create_app() ) # Because message-all run on background thread it needs it's own app context with app.app_context(): contributors = Message.get_all_contributors(project_id) project_link = MessageService.get_project_link(project_id) message_dto.message = ( f"{project_link}<br/><br/>" + message_dto.message ) # Append project link to end of message messages = [] for contributor in contributors: message = Message.from_dto(contributor[0], message_dto) message.message_type = MessageType.BROADCAST.value message.project_id = project_id message.save() user = UserService.get_user_by_id(contributor[0]) messages.append(dict(message=message, user=user)) MessageService._push_messages(messages)
def as_dto(self) -> MessageDTO: """ Casts message object to DTO """ dto = MessageDTO() dto.message_id = self.id dto.message = self.message dto.sent_date = self.date dto.read = self.read dto.subject = self.subject dto.project_id = self.project_id dto.task_id = self.task_id if self.message_type is not None: dto.message_type = MessageType(self.message_type).name if self.from_user_id: dto.from_username = self.from_user.username return dto