def create_mention(self, username, topic, content): user = self.cache.get('member:%s' % str(username)) if user is None: user = Member.query.filter_by(username=username).first() self.cache.set('member:%s' % str(username), user, 600) if not user: return if user.id == self.current_user.id: return if user.id == topic.user_id: #avoid double notify return link = '/topic/%s#reply-%s' % (topic.id, topic.reply_count) content = content[:200] notify = Notify( sender=self.current_user.id, receiver=user.id, label=topic.title, link=link, content=content) notify.type = 'mention' self.db.add(notify) if not hasattr(self, 'cache'): self.cache = self.handler.cache self.cache.delete('notify:%s' % user.id) return notify
def create_notify(self, receiver, topic, content, type='reply'): if receiver == self.current_user.id: return link = '/topic/%s#reply-%s' % (topic.id, topic.reply_count) content = content[:200] notify = Notify(sender=self.current_user.id, receiver=receiver, label=topic.title, link=link, content=content) notify.type = type self.db.add(notify) if not hasattr(self, 'cache'): self.cache = self.handler.cache self.cache.delete('notify:%s' % receiver) return notify