Skip to content

Add new message emails #1321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2017
Merged

Add new message emails #1321

merged 1 commit into from
Dec 20, 2017

Conversation

joshsmith
Copy link
Contributor

@joshsmith joshsmith commented Dec 20, 2017

What's in this PR?

Adds emails for messages.

References

Fixes #1311

conversation_url: project |> conversation_url(conversation),
name: user.first_name,
project_title: project.title,
subject: "#{user.first_name} has posted a reply on #{project.title}"
Copy link
Contributor

@begedin begedin Dec 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different from the user email primarily because this could be a reply by any participant, including another admin/owner.

Feel free to word it differently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might change some language here but need to think on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:

"#{user.first_name} replied to a message in #{project.title}"

"""
@spec notify_of_new_message(Message.t) :: :ok
def notify_of_new_message(%Message{initiated_by: "admin"} = message) do
message = message |> Repo.preload(@message_preloads)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These explicit preloads are ugly, but it's an "internal" module, so it would be a matter of doing them here, or up higher, within the main messages context.

[message: [:author, [project: :organization]]],
:user
]
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, ugly, same as above.

In this case, I might actually prefer doing an explicit sql query instead.

# we match against admin initiated only, because it's unclear who
# message.author is for user-initiated messages, or who the email recipient
# would be, assuming the message.author is the user who initiated the message
@spec send_message_for_project_emails(ConversationPart.t) :: :ok
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the comment says

  • who gets notified of an email sent by a user to a project? I know we don't have it yet, but still
  • who gets assigned as the message.author. Having it be identical to conversation.user seems redundant/confusing. Should we allow it blank in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our conversation earlier got it right. Can you comment here what we said?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, the idea was

When a user messages a project, all project admins and owners receive an email.

When a project admin/owner replies to the conversation, from that point on, only participating users receive emails. That means whoever send it initially, whoever replied, and whoever decided to join in at a later time.

@begedin
Copy link
Contributor

begedin commented Dec 20, 2017

@joshsmith The logic is in, but I'm hoping it could be done a bit better. Does post mark allow specifying a separate template "submodel" for each recipient? That would allow us to just fetch a list of recipients and send the project email to all of them in one request.

Sparkpost allows something like that, so I was hoping Postmark would to.

@begedin
Copy link
Contributor

begedin commented Dec 20, 2017

@joshsmith Also, I'm not sure if only participants of the conversation should be notified of new replies, or if all project members of admin or higher should be. If we want to change that, Messages.Emails.get_project_participants/1 is the place to do it.

Copy link
Contributor Author

@joshsmith joshsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs the template ids to be added to the config.

This is also generally confusing to me. It looks like we're missing an email for a message from a user to a project (which admittedly we don't have in the front-end yet, so perhaps can come later). But I think the naming conventions here no longer match up with the original intention or the current usage.

It seems like we need three email types:

  • conversation replies, which go to all participants in a conversation
  • new message to a project (i.e. initiated_by user), which goes to all a project's admins
  • new message to some unknown number of n users (i.e. initiated_by admin), which goes to all the conversation's n users

Given that, we should maybe have emails that are:

  • ReplyToConversationEmail - currently MessageForProjectEmail
  • MessageInitiatedByProjectEmail - currently MessageForUserEmail
  • MessageInitiatedByUserEmail - currently not implemented

conversation_url: project |> conversation_url(conversation),
name: user.first_name,
project_title: project.title,
subject: "#{user.first_name} has posted a reply on #{project.title}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:

"#{user.first_name} replied to a message in #{project.title}"

@begedin
Copy link
Contributor

begedin commented Dec 20, 2017

I think the 3 new types would make sense. In this case, that would mean

MessageToUserEmail -> MessageInitiatedByProjectEmail
MessageToProjectEmail -> ReplyToConversationEmail

Then we add MessageInitiatedByUserEmail at a later time

The logic would have to change a bit to. The Messages.add_part/1 would only send ReplyToConversationEmail emails, to all participants, except the author of the conversation.

Also note that with conversation part types, we might have to name it differently and word it a bit differently to.

@joshsmith joshsmith assigned joshsmith and unassigned begedin Dec 20, 2017
@joshsmith
Copy link
Contributor Author

I’ll get to work making the modifications then and create an issue to do the MessageInitiatedByUserEmail.

@joshsmith
Copy link
Contributor Author

I think the maybe_send_message_for_user_email was overthinking what's needed to send a message to all relevant users in a conversation.

For sending a notification for the conversation part, we need to:

  • get all the authors for all the conversation parts
  • get the author of the message
  • get the user for the conversation

That should be everyone who's participating.

@joshsmith joshsmith force-pushed the 1311-emails-for-messages branch from 59a8674 to 33fc482 Compare December 20, 2017 20:59
@joshsmith joshsmith force-pushed the 1311-emails-for-messages branch from 33fc482 to 98e1ea0 Compare December 20, 2017 21:18
@joshsmith joshsmith merged commit a95566e into develop Dec 20, 2017
@joshsmith joshsmith deleted the 1311-emails-for-messages branch December 20, 2017 22:13
@begedin
Copy link
Contributor

begedin commented Dec 20, 2017

@joshsmith I figured it would be simpler with the new email types. Agree with the logic 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants