Extract mention from post & comment and notify [WIP]

This commit is contained in:
Suraj Shetty 2019-02-12 12:40:41 +05:30
parent 5b3300e2ca
commit 52bd7514ae
2 changed files with 8 additions and 0 deletions

View file

@ -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()

View file

@ -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)