def _on_published(self): # Mark as not a draft. self.draft = False # Reset the creation date to the moment it's published. self.created = timezone.now() # Save. self.save() # Kick the attached object. if hasattr(self.discussion.attached_to_obj, 'on_discussion_comment'): self.discussion.attached_to_obj.on_discussion_comment(self) # Issue a notification to anyone watching the discussion # via discussion.get_notification_watchers() except to # anyone @-mentioned because they'll get a different # notification. if self.draft: raise Exception("I'm still a draft.") from siteapp.views import issue_notification _, mentioned_users = match_autocompletes(self.text, self.discussion.get_autocompletes(self.user)) issue_notification( self.user, "commented on", self.discussion, recipients=self.discussion.get_notification_watchers() - mentioned_users, description=self.text, comment_id=self.id) # Issue a notification to anyone @-mentioned in the comment # that is already a discussion participant. discussion_participants = set(self.discussion.get_all_participants()) issue_notification( self.user, "mentioned you in a comment on", self.discussion, recipients=mentioned_users & discussion_participants, description=self.text, comment_id=self.id) # Send invitations to anyone @-mentioned who is not yet a participant # in the discussion. from siteapp.models import Invitation for user in mentioned_users - discussion_participants: inv = Invitation.objects.create( organization=self.discussion.organization, from_user=self.user, from_project=self.discussion.attached_to_obj.task.project, # TODO: Breaks abstraction, assumes attached_to => TaskAnswer. target=self.discussion, target_info={ "what": "invite-guest" }, to_user=user, text="{} mentioned you in a discussion:\n\n{}".format(self.user, self.text), ) inv.send() # Let the owner object of the discussion know that a comment was left. if hasattr(self.discussion.attached_to_obj, 'on_discussion_comment'): self.discussion.attached_to_obj.on_discussion_comment(self)
def save_reaction(request): # get comment that is being reacted *to* comment = get_object_or_404(Comment, id=request.POST['id'], **makekwargs(request, 'discussion__')) # can see it? if not comment.can_see(request.user): return HttpResponseForbidden() # get the Comment that holds the reaction to it comment, is_new = Comment.objects.get_or_create( discussion=comment.discussion, replies_to=comment, user=request.user, ) # get previous value old_value = comment.get_emoji_list() # record edit history comment.push_history('emojis') # edit comment.emojis = request.POST['emojis'] # if there are changes... new_value = comment.get_emoji_list() if old_value != new_value: # save comment.save() # issue notification to the parent comment's author, unless it's # the user making the reaction if new_value - old_value: # There are new reactions. msg = "reacted " + ", ".join(sorted(new_value - old_value)) + " to" # There were also emojis un-reacted. if old_value - new_value: msg += " and removed their reaction " + ", ".join( sorted(old_value - new_value)) elif old_value - new_value: # Emojis were removed (and nothing else). msg = "removed their reaction " + ", ".join( sorted(old_value - new_value)) + " to" from siteapp.views import issue_notification issue_notification(comment.user, msg, comment.discussion, recipients=[comment.replies_to.user], comment_id=comment.id) # return new comment info return JsonResponse(comment.render_context_dict(request.user))
def _on_published(self): # Mark as not a draft. self.draft = False # Reset the creation date to the moment it's published. self.created = timezone.now() # Save. self.save() # Kick the attached object. if hasattr(self.discussion.attached_to, 'on_discussion_comment'): self.discussion.attached_to.on_discussion_comment(self) # Issue a notification to anyone watching the discussion # via discussion.get_notification_watchers() except to # anyone @-mentioned because they'll get a different # notification. if self.draft: raise Exception("I'm still a draft.") from siteapp.views import issue_notification _, mentioned_users = match_autocompletes( self.text, self.discussion.get_autocompletes(self.user)) issue_notification( self.user, "commented on", self.discussion, recipients=self.discussion.get_notification_watchers() - mentioned_users, description=self.text, comment_id=self.id) # Issue a notification to anyone @-mentioned in the comment. issue_notification(self.user, "mentioned you in a comment on", self.discussion, recipients=mentioned_users, description=self.text, comment_id=self.id) # Let the owner object of the discussion know that a comment was left. if hasattr(self.discussion.attached_to, 'on_discussion_comment'): self.discussion.attached_to.on_discussion_comment(self)