def prepare_group_conversation_message_notification(user, message): conversation = message.conversation group = conversation.target from_text = message.author.display_name reply_to_name = group.name conversation_name = group.name local_part = make_local_part(conversation, user, message) reply_to = formataddr( (reply_to_name, '{}@{}'.format(local_part, settings.SPARKPOST_RELAY_DOMAIN))) from_email = formataddr((from_text, settings.DEFAULT_FROM_EMAIL)) unsubscribe_url = conversation_unsubscribe_url(user, group=group, conversation=conversation) return prepare_email( template='conversation_message_notification', from_email=from_email, user=user, tz=group.timezone, reply_to=[reply_to], unsubscribe_url=unsubscribe_url, context={ 'messages': [message], 'conversation_name': conversation_name, 'conversation_url': group_wall_url(group), 'mute_url': unsubscribe_url, }, stats_category='group_conversation_message', )
def prepare_private_user_conversation_message_notification(user, messages): first_message = messages[0] conversation = first_message.conversation author = first_message.author reply_to_name = author.display_name local_part = make_local_part(conversation, user) reply_to = formataddr( (reply_to_name, '{}@{}'.format(local_part, settings.SPARKPOST_RELAY_DOMAIN))) from_email = formataddr((author.display_name, settings.DEFAULT_FROM_EMAIL)) unsubscribe_url = conversation_unsubscribe_url(author, conversation=conversation) return prepare_email( template='conversation_message_notification', from_email=from_email, user=user, # TODO: which timezone? maybe the user needs a timezone? reply_to=[reply_to], unsubscribe_url=unsubscribe_url, context={ 'messages': messages, 'conversation_name': author.display_name, 'conversation_url': user_detail_url(author), 'mute_url': unsubscribe_url, }, stats_category='private_conversation_message', )
def prepare_message_notification( user, messages, *, conversation_name, conversation_url, stats_category, group=None, reply_to_name=None, ): first_message = messages[0] conversation = first_message.conversation author = first_message.author if group: tz = group.timezone elif user.current_group: tz = user.current_group.timezone else: # default, I guess most groups are not so far from this timezone... tz = pytz.timezone('Europe/Berlin') if reply_to_name is None: reply_to_name = author.display_name with translation.override(language_for_user(user)): from_text = author_names(messages) # If the conversation supports threads, replies should go into a thread, not the main conversation thread = first_message if conversation.target and conversation.target.conversation_supports_threads else None local_part = make_local_part(conversation, user, thread) reply_to = formataddr( (reply_to_name, '{}@{}'.format(local_part, settings.EMAIL_REPLY_DOMAIN))) from_email = formataddr((from_text, settings.DEFAULT_FROM_EMAIL)) unsubscribe_url = conversation_unsubscribe_url( user, group=group, conversation=conversation) return prepare_email( template='conversation_message_notification', from_email=from_email, user=user, tz=tz, reply_to=[reply_to], unsubscribe_url=unsubscribe_url, context={ 'messages': messages, 'conversation_name': conversation_name, 'conversation_url': conversation_url, 'mute_url': unsubscribe_url, }, stats_category=stats_category, )
def prepare_application_message_notification(user, messages): first_message = messages[0] conversation = first_message.conversation application = conversation.target language = user.language if not translation.check_for_language(language): language = 'en' with translation.override(language): reply_to_name = application.user.display_name conversation_name = _( 'New message in application of %(user_name)s to %(group_name)s' ) % { 'user_name': application.user.display_name, 'group_name': application.group.name, } if application.user == user: conversation_name = _( 'New message in your application to %(group_name)s') % { 'group_name': application.group.name } from_text = author_names(messages) local_part = make_local_part(conversation, user) reply_to = formataddr( (reply_to_name, '{}@{}'.format(local_part, settings.SPARKPOST_RELAY_DOMAIN))) from_email = formataddr((from_text, settings.DEFAULT_FROM_EMAIL)) unsubscribe_url = conversation_unsubscribe_url( user, group=application.group, conversation=conversation) return prepare_email( template='conversation_message_notification', from_email=from_email, user=user, tz=application.group.timezone, reply_to=[reply_to], unsubscribe_url=unsubscribe_url, context={ 'messages': messages, 'conversation_name': conversation_name, 'conversation_url': application_url(application), 'mute_url': unsubscribe_url, }, stats_category='application_message', )
def prepare_issue_message_notification(user, messages): first_message = messages[0] conversation = first_message.conversation author = first_message.author reply_to_name = author.display_name issue = conversation.target language = user.language if not translation.check_for_language(language): language = 'en' with translation.override(language): conversation_name = _( 'New message in conflict resolution in %(group_name)s') % { 'group_name': issue.group.name, } from_text = author_names(messages) local_part = make_local_part(conversation, user) reply_to = formataddr( (reply_to_name, '{}@{}'.format(local_part, settings.SPARKPOST_RELAY_DOMAIN))) from_email = formataddr((from_text, settings.DEFAULT_FROM_EMAIL)) unsubscribe_url = conversation_unsubscribe_url( user, group=issue.group, conversation=conversation) return prepare_email(template='conversation_message_notification', from_email=from_email, user=user, tz=issue.group.timezone, reply_to=[reply_to], unsubscribe_url=unsubscribe_url, context={ 'messages': messages, 'conversation_name': conversation_name, 'conversation_url': issue_url(issue), 'mute_url': unsubscribe_url, })
def prepare_pickup_conversation_message_notification(user, messages): first_message = messages[0] conversation = first_message.conversation pickup = conversation.target group_tz = pickup.place.group.timezone language = user.language if not translation.check_for_language(language): language = 'en' with translation.override(language): with timezone.override(group_tz): weekday = format_date( pickup.date.start.astimezone(timezone.get_current_timezone()), 'EEEE', locale=translation.to_locale(language), ) time = format_time( pickup.date.start, format='short', locale=translation.to_locale(language), tzinfo=timezone.get_current_timezone(), ) date = format_date( pickup.date.start.astimezone(timezone.get_current_timezone()), format='long', locale=translation.to_locale(language), ) long_date = '{} {}, {}'.format(weekday, time, date) short_date = '{} {}'.format(weekday, time) reply_to_name = _('Pickup %(date)s') % { 'date': short_date, } conversation_name = _('Pickup %(date)s') % { 'date': long_date, } from_text = author_names(messages) local_part = make_local_part(conversation, user) reply_to = formataddr( (reply_to_name, '{}@{}'.format(local_part, settings.SPARKPOST_RELAY_DOMAIN))) from_email = formataddr((from_text, settings.DEFAULT_FROM_EMAIL)) unsubscribe_url = conversation_unsubscribe_url( user, group=pickup.place.group, conversation=conversation) return prepare_email( template='conversation_message_notification', from_email=from_email, user=user, tz=group_tz, reply_to=[reply_to], unsubscribe_url=unsubscribe_url, context={ 'messages': messages, 'conversation_name': conversation_name, 'conversation_url': pickup_detail_url(pickup), 'mute_url': unsubscribe_url, }, stats_category='pickup_conversation_message', )