mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Max os 3 stories sent per notification group. Also limiting notifications to staff for live test.
This commit is contained in:
parent
8f6bfa1c55
commit
9ffa63ec2b
4 changed files with 36 additions and 15 deletions
|
@ -56,6 +56,10 @@ class MUserFeedNotification(mongo.Document):
|
|||
self.last_notification_date,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def feed_has_users(cls, feed_id):
|
||||
return cls.users_for_feed(feed_id).count()
|
||||
|
||||
@classmethod
|
||||
def users_for_feed(cls, feed_id):
|
||||
notifications = cls.objects.filter(feed_id=feed_id)
|
||||
|
@ -83,7 +87,7 @@ class MUserFeedNotification(mongo.Document):
|
|||
def push_feed_notifications(cls, feed_id, new_stories, force=False):
|
||||
feed = Feed.get_by_id(feed_id)
|
||||
notifications = MUserFeedNotification.users_for_feed(feed.pk)
|
||||
logging.debug(" ---> [%-30s] ~FCPushing out ~SB%s notifications~SN for ~FB~SB%s stories" % (
|
||||
logging.debug(" ---> [%-30s] ~FCPushing out notifications to ~SB%s users~SN for ~FB~SB%s stories" % (
|
||||
feed, len(notifications), new_stories))
|
||||
r = redis.Redis(connection_pool=settings.REDIS_STORY_HASH_POOL)
|
||||
|
||||
|
@ -92,17 +96,28 @@ class MUserFeedNotification(mongo.Document):
|
|||
stories = Feed.format_stories(mstories)
|
||||
|
||||
for feed_notification in notifications:
|
||||
sent_count = 0
|
||||
last_notification_date = feed_notification.last_notification_date
|
||||
classifiers = feed_notification.classifiers()
|
||||
if not classifiers:
|
||||
|
||||
if classifiers == None:
|
||||
logging.debug("Has no usersubs")
|
||||
continue
|
||||
|
||||
for story in stories:
|
||||
if sent_count >= 3:
|
||||
logging.debug("Sent too many, ignoring...")
|
||||
continue
|
||||
if story['story_date'] < last_notification_date and not force:
|
||||
logging.debug("Story date older than last notification date: %s < %s" % (story['story_date'], last_notification_date))
|
||||
continue
|
||||
|
||||
if story['story_date'] > feed_notification.last_notification_date:
|
||||
feed_notification.last_notification_date = story['story_date']
|
||||
feed_notification.save()
|
||||
feed_notification.push_notifications(story, classifiers)
|
||||
|
||||
sent = feed_notification.push_notifications(story, classifiers)
|
||||
if sent: sent_count += 1
|
||||
|
||||
def classifiers(self):
|
||||
try:
|
||||
|
@ -124,9 +139,11 @@ class MUserFeedNotification(mongo.Document):
|
|||
def push_notifications(self, story, classifiers):
|
||||
story_score = self.story_score(story, classifiers)
|
||||
if self.is_focus and story_score <= 0:
|
||||
return
|
||||
logging.debug("Is focus, but story is hidden")
|
||||
return False
|
||||
elif story_score < 0:
|
||||
return
|
||||
logging.debug("Is unread, but story is hidden")
|
||||
return False
|
||||
|
||||
user = User.objects.get(pk=self.user_id)
|
||||
logging.user(user, "~FCSending push notification: %s/%s (score: %s)" % (story['story_title'][:40], story['story_hash'], story_score))
|
||||
|
@ -135,6 +152,8 @@ class MUserFeedNotification(mongo.Document):
|
|||
self.send_ios(story)
|
||||
self.send_android(story)
|
||||
self.send_email(story)
|
||||
|
||||
return True
|
||||
|
||||
def send_web(self, story):
|
||||
if not self.is_web: return
|
||||
|
@ -155,10 +174,10 @@ class MUserFeedNotification(mongo.Document):
|
|||
if not self.is_email: return
|
||||
|
||||
def story_score(self, story, classifiers):
|
||||
score = compute_story_score(story, classifier_titles=classifiers['titles'],
|
||||
classifier_authors=classifiers['authors'],
|
||||
classifier_tags=classifiers['tags'],
|
||||
classifier_feeds=classifiers['feeds'])
|
||||
score = compute_story_score(story, classifier_titles=classifiers.get('titles', []),
|
||||
classifier_authors=classifiers.get('authors', []),
|
||||
classifier_tags=classifiers.get('tags', []),
|
||||
classifier_feeds=classifiers.get('feeds', []))
|
||||
|
||||
return score
|
||||
|
||||
|
|
|
@ -3173,10 +3173,10 @@
|
|||
$.make('div', { className: 'NB-menu-manage-image' }),
|
||||
$.make('div', { className: 'NB-menu-manage-title' }, 'Goodies & Mobile Apps')
|
||||
]),
|
||||
$.make('li', { className: 'NB-menu-item NB-menu-manage-notifications' }, [
|
||||
(NEWSBLUR.Globals.is_admin && $.make('li', { className: 'NB-menu-item NB-menu-manage-notifications' }, [
|
||||
$.make('div', { className: 'NB-menu-manage-image' }),
|
||||
$.make('div', { className: 'NB-menu-manage-title' }, 'Notifications')
|
||||
]),
|
||||
])),
|
||||
$.make('li', { className: 'NB-menu-item NB-menu-manage-newsletters' }, [
|
||||
$.make('div', { className: 'NB-menu-manage-image' }),
|
||||
$.make('div', { className: 'NB-menu-manage-title' }, 'Email Newsletters')
|
||||
|
@ -3235,10 +3235,10 @@
|
|||
$.make('div', { className: 'NB-menu-manage-image' }),
|
||||
$.make('div', { className: 'NB-menu-manage-title' }, 'Site settings')
|
||||
]),
|
||||
$.make('li', { className: 'NB-menu-item NB-menu-manage-feed-notifications' }, [
|
||||
(NEWSBLUR.Globals.is_admin && $.make('li', { className: 'NB-menu-item NB-menu-manage-feed-notifications' }, [
|
||||
$.make('div', { className: 'NB-menu-manage-image' }),
|
||||
$.make('div', { className: 'NB-menu-manage-title' }, 'Notifications')
|
||||
]),
|
||||
])),
|
||||
$.make('li', { className: 'NB-menu-item NB-menu-manage-feed-train' }, [
|
||||
$.make('div', { className: 'NB-menu-manage-image' }),
|
||||
$.make('div', { className: 'NB-menu-manage-title' }, 'Intelligence trainer'),
|
||||
|
|
|
@ -48,12 +48,14 @@
|
|||
Goodies & Apps
|
||||
</div>
|
||||
</li>
|
||||
{% if user.is_staff %}
|
||||
<li class="NB-menu-item NB-menu-manage-notifications">
|
||||
<div class="NB-menu-manage-image"></div>
|
||||
<div class="NB-menu-manage-title">
|
||||
Notifications
|
||||
</div>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="NB-menu-item NB-menu-manage-newsletters">
|
||||
<div class="NB-menu-manage-image"></div>
|
||||
<div class="NB-menu-manage-title">
|
||||
|
|
|
@ -20,7 +20,7 @@ from apps.reader.models import UserSubscription
|
|||
from apps.rss_feeds.models import Feed, MStory
|
||||
from apps.rss_feeds.page_importer import PageImporter
|
||||
from apps.rss_feeds.icon_importer import IconImporter
|
||||
from apps.notifications.tasks import QueueNotifications
|
||||
from apps.notifications.tasks import QueueNotifications, MUserFeedNotification
|
||||
from apps.push.models import PushSubscription
|
||||
from apps.social.models import MSocialServices
|
||||
from apps.statistics.models import MAnalyticsFetcher
|
||||
|
@ -687,7 +687,7 @@ class ProcessFeed:
|
|||
self.feed = self.feed.save()
|
||||
|
||||
# Push notifications
|
||||
if ret_values['new'] > 0:
|
||||
if ret_values['new'] > 0 and MUserFeedNotification.feed_has_users(self.feed.pk) > 0:
|
||||
QueueNotifications.delay(self.feed.pk, ret_values['new'])
|
||||
|
||||
# All Done
|
||||
|
|
Loading…
Add table
Reference in a new issue