From 52bd7514ae59ea828b30fc4ae9b366bec88dd72e Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 12 Feb 2019 12:40:41 +0530 Subject: [PATCH] Extract mention from post & comment and notify [WIP] --- frappe/social/doctype/post/post.py | 4 ++++ frappe/social/doctype/post_comment/post_comment.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/frappe/social/doctype/post/post.py b/frappe/social/doctype/post/post.py index 24f407ddf6..c5ee3bf854 100644 --- a/frappe/social/doctype/post/post.py +++ b/frappe/social/doctype/post/post.py @@ -7,6 +7,7 @@ import frappe import requests from bs4 import BeautifulSoup from frappe.model.document import Document +from frappe.core.doctype.user.user import extract_mentions class Post(Document): def on_update(self): @@ -14,6 +15,9 @@ class Post(Document): frappe.publish_realtime('global_pin', after_commit=True) def after_insert(self): + mentions = extract_mentions(self.content) + for mention in mentions: + frappe.publish_realtime('mention', "Someone mentioned you", user=mention, after_commit=True) frappe.publish_realtime('new_post', self.owner, after_commit=True) @frappe.whitelist() diff --git a/frappe/social/doctype/post_comment/post_comment.py b/frappe/social/doctype/post_comment/post_comment.py index d29ed160c1..cda9f12f31 100644 --- a/frappe/social/doctype/post_comment/post_comment.py +++ b/frappe/social/doctype/post_comment/post_comment.py @@ -5,7 +5,11 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document +from frappe.core.doctype.user.user import extract_mentions class PostComment(Document): def after_insert(self): + mentions = extract_mentions(self.content) + for mention in mentions: + frappe.publish_realtime('mention', "Someone mentioned you", user=mention, after_commit=True) frappe.publish_realtime('new_post_comment' + self.parent, self, after_commit=True)