management: Move inactive_since to digest.

This commit is contained in:
Preston Hansen
2017-08-25 14:44:28 -05:00
committed by Tim Abbott
parent f1648af607
commit 25a40806df
2 changed files with 17 additions and 16 deletions

View File

@@ -13,7 +13,7 @@ from django.conf import settings
from zerver.lib.notifications import build_message_list, hash_util_encode, \
one_click_unsubscribe_link
from zerver.lib.send_email import send_future_email, FromAddress
from zerver.models import UserProfile, UserMessage, Recipient, Stream, \
from zerver.models import UserProfile, UserActivity, UserMessage, Recipient, Stream, \
Subscription, get_active_streams, get_user_profile_by_id
from zerver.context_processors import common_context
@@ -37,6 +37,20 @@ logger.addHandler(file_handler)
# 4. Interesting stream traffic, as determined by the longest and most
# diversely comment upon topics.
def inactive_since(user_profile, cutoff):
# type: (UserProfile, datetime.datetime) -> bool
# Hasn't used the app in the last DIGEST_CUTOFF (5) days.
most_recent_visit = [row.last_visit for row in
UserActivity.objects.filter(
user_profile=user_profile)]
if not most_recent_visit:
# This person has never used the app.
return True
last_visit = max(most_recent_visit)
return last_visit < cutoff
def gather_hot_conversations(user_profile, stream_messages):
# type: (UserProfile, QuerySet) -> List[Dict[str, Any]]
# Gather stream conversations of 2 types:

View File

@@ -9,7 +9,8 @@ from django.core.management.base import BaseCommand
from django.utils.timezone import now as timezone_now
from zerver.lib.queue import queue_json_publish
from zerver.models import UserActivity, UserProfile, Realm
from zerver.models import UserProfile, Realm
from zerver.lib.digest import inactive_since
## Logging setup ##
@@ -27,20 +28,6 @@ logger.addHandler(file_handler)
VALID_DIGEST_DAY = 1 # Tuesdays
DIGEST_CUTOFF = 5
def inactive_since(user_profile, cutoff):
# type: (UserProfile, datetime.datetime) -> bool
# Hasn't used the app in the last DIGEST_CUTOFF (5) days.
most_recent_visit = [row.last_visit for row in
UserActivity.objects.filter(
user_profile=user_profile)]
if not most_recent_visit:
# This person has never used the app.
return True
last_visit = max(most_recent_visit)
return last_visit < cutoff
# Changes to this should also be reflected in
# zerver/worker/queue_processors.py:DigestWorker.consume()
def queue_digest_recipient(user_profile, cutoff):