def trigger_notification(comment, media_entry, request): ''' Send out notifications about a new comment. ''' # Verify we have the Comment object and not any other type e.g. TextComment if not isinstance(comment, Comment): raise ValueError("Must provide Comment to trigger_notification") # Get the associated object associated to the Comment wrapper. comment_object = comment.comment() subscriptions = CommentSubscription.query.filter_by( media_entry_id=media_entry.id).all() for subscription in subscriptions: # Check the user wants to be notified, if not, skip. if not subscription.notify: continue # If the subscriber is the current actor, don't bother. if comment_object.get_actor == subscription.user: continue cn = Notification(user_id=subscription.user_id, ) cn.obj = comment cn.save() if subscription.send_email: message = generate_comment_message(subscription.user, comment, media_entry, request) from mediagoblin.notifications.task import email_notification_task email_notification_task.apply_async([cn.id, message])
def fixture_add_comment_notification(entry, subject, user, seen=False): cn = Notification( user_id=user, seen=seen, ) cn.obj = subject cn.save() cn = Notification.query.filter_by(id=cn.id).first() Session.expunge(cn) return cn
def trigger_notification(comment, media_entry, request): ''' Send out notifications about a new comment. ''' subscriptions = CommentSubscription.query.filter_by( media_entry_id=media_entry.id).all() for subscription in subscriptions: if not subscription.notify: continue if comment.get_actor == subscription.user: continue cn = Notification(user_id=subscription.user_id, ) cn.obj = comment cn.save() if subscription.send_email: message = generate_comment_message(subscription.user, comment, media_entry, request) from mediagoblin.notifications.task import email_notification_task email_notification_task.apply_async([cn.id, message])