mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 15:09:34 +00:00
home: Extract code to get the furthest read time.
This commit is contained in:
committed by
Tim Abbott
parent
a937ea531e
commit
1adb88cf62
@@ -112,6 +112,19 @@ def sent_time_in_epoch_seconds(user_message: Optional[UserMessage]) -> Optional[
|
|||||||
# Return the epoch seconds in UTC.
|
# Return the epoch seconds in UTC.
|
||||||
return calendar.timegm(user_message.message.date_sent.utctimetuple())
|
return calendar.timegm(user_message.message.date_sent.utctimetuple())
|
||||||
|
|
||||||
|
def get_furthest_read_time(user_profile: Optional[UserProfile]) -> Optional[float]:
|
||||||
|
if user_profile is None: # nocoverage
|
||||||
|
furthest_read_time: Optional[float] = time.time()
|
||||||
|
elif user_profile.pointer == -1:
|
||||||
|
furthest_read_time = None
|
||||||
|
else:
|
||||||
|
latest_read = get_usermessage_by_message_id(user_profile, user_profile.pointer)
|
||||||
|
if latest_read is None:
|
||||||
|
# Don't completely fail if your saved pointer ID is invalid
|
||||||
|
logging.warning("User %s has invalid pointer %s", user_profile.id, user_profile.pointer)
|
||||||
|
furthest_read_time = sent_time_in_epoch_seconds(latest_read)
|
||||||
|
return furthest_read_time
|
||||||
|
|
||||||
def get_bot_types(user_profile: Optional[UserProfile]) -> List[Dict[str, object]]:
|
def get_bot_types(user_profile: Optional[UserProfile]) -> List[Dict[str, object]]:
|
||||||
bot_types: List[Dict[str, object]] = []
|
bot_types: List[Dict[str, object]] = []
|
||||||
if user_profile is None: # nocoverage
|
if user_profile is None: # nocoverage
|
||||||
@@ -209,10 +222,7 @@ def home_real(request: HttpRequest) -> HttpResponse:
|
|||||||
# The current tutorial doesn't super make sense for logged-out users.
|
# The current tutorial doesn't super make sense for logged-out users.
|
||||||
needs_tutorial = False
|
needs_tutorial = False
|
||||||
|
|
||||||
if user_profile is None: # nocoverage
|
if user_has_messages and user_profile.pointer == -1:
|
||||||
furthest_read_time: Optional[float] = time.time()
|
|
||||||
elif user_profile.pointer == -1:
|
|
||||||
if user_has_messages:
|
|
||||||
# Put the new user's pointer at the bottom
|
# Put the new user's pointer at the bottom
|
||||||
#
|
#
|
||||||
# This improves performance, because we limit backfilling of messages
|
# This improves performance, because we limit backfilling of messages
|
||||||
@@ -221,13 +231,8 @@ def home_real(request: HttpRequest) -> HttpResponse:
|
|||||||
# first messages on the system.
|
# first messages on the system.
|
||||||
|
|
||||||
register_ret['pointer'] = register_ret['max_message_id']
|
register_ret['pointer'] = register_ret['max_message_id']
|
||||||
furthest_read_time = None
|
|
||||||
else:
|
furthest_read_time = get_furthest_read_time(user_profile)
|
||||||
latest_read = get_usermessage_by_message_id(user_profile, user_profile.pointer)
|
|
||||||
if latest_read is None:
|
|
||||||
# Don't completely fail if your saved pointer ID is invalid
|
|
||||||
logging.warning("User %s has invalid pointer %s", user_profile.id, user_profile.pointer)
|
|
||||||
furthest_read_time = sent_time_in_epoch_seconds(latest_read)
|
|
||||||
|
|
||||||
# We pick a language for the user as follows:
|
# We pick a language for the user as follows:
|
||||||
# * First priority is the language in the URL, for debugging.
|
# * First priority is the language in the URL, for debugging.
|
||||||
|
|||||||
Reference in New Issue
Block a user