mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 19:06:09 +00:00
management: Move inactive_since to digest.
This commit is contained in:
committed by
Tim Abbott
parent
f1648af607
commit
25a40806df
@@ -13,7 +13,7 @@ from django.conf import settings
|
|||||||
from zerver.lib.notifications import build_message_list, hash_util_encode, \
|
from zerver.lib.notifications import build_message_list, hash_util_encode, \
|
||||||
one_click_unsubscribe_link
|
one_click_unsubscribe_link
|
||||||
from zerver.lib.send_email import send_future_email, FromAddress
|
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
|
Subscription, get_active_streams, get_user_profile_by_id
|
||||||
from zerver.context_processors import common_context
|
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
|
# 4. Interesting stream traffic, as determined by the longest and most
|
||||||
# diversely comment upon topics.
|
# 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):
|
def gather_hot_conversations(user_profile, stream_messages):
|
||||||
# type: (UserProfile, QuerySet) -> List[Dict[str, Any]]
|
# type: (UserProfile, QuerySet) -> List[Dict[str, Any]]
|
||||||
# Gather stream conversations of 2 types:
|
# Gather stream conversations of 2 types:
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ from django.core.management.base import BaseCommand
|
|||||||
from django.utils.timezone import now as timezone_now
|
from django.utils.timezone import now as timezone_now
|
||||||
|
|
||||||
from zerver.lib.queue import queue_json_publish
|
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 ##
|
## Logging setup ##
|
||||||
|
|
||||||
@@ -27,20 +28,6 @@ logger.addHandler(file_handler)
|
|||||||
VALID_DIGEST_DAY = 1 # Tuesdays
|
VALID_DIGEST_DAY = 1 # Tuesdays
|
||||||
DIGEST_CUTOFF = 5
|
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
|
# Changes to this should also be reflected in
|
||||||
# zerver/worker/queue_processors.py:DigestWorker.consume()
|
# zerver/worker/queue_processors.py:DigestWorker.consume()
|
||||||
def queue_digest_recipient(user_profile, cutoff):
|
def queue_digest_recipient(user_profile, cutoff):
|
||||||
|
|||||||
Reference in New Issue
Block a user