mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
unreads: Add support for web public guests.
This handles the case of web public guests by returning RawUnreadMessagesResult with empty initalized values.
This commit is contained in:
@@ -27,6 +27,7 @@ from zerver.lib.integrations import EMBEDDED_BOTS, WEBHOOK_INTEGRATIONS
|
|||||||
from zerver.lib.message import (
|
from zerver.lib.message import (
|
||||||
aggregate_unread_data,
|
aggregate_unread_data,
|
||||||
apply_unread_message_event,
|
apply_unread_message_event,
|
||||||
|
extract_unread_data_from_um_rows,
|
||||||
get_raw_unread_data,
|
get_raw_unread_data,
|
||||||
get_recent_conversations_recipient_id,
|
get_recent_conversations_recipient_id,
|
||||||
get_recent_private_conversations,
|
get_recent_private_conversations,
|
||||||
@@ -337,20 +338,14 @@ def fetch_initial_state_data(user_profile: Optional[UserProfile],
|
|||||||
# message updates. This is due to the fact that new messages will not
|
# message updates. This is due to the fact that new messages will not
|
||||||
# generate a flag update so we need to use the flags field in the
|
# generate a flag update so we need to use the flags field in the
|
||||||
# message event.
|
# message event.
|
||||||
if user_profile is None:
|
|
||||||
# TODO: We should deduplicate this logic by extracting the
|
if user_profile is not None:
|
||||||
# row-processing part of get_raw_unread_data as a helper
|
|
||||||
# function, and calling that with an empty list.
|
|
||||||
state['raw_unread_msgs'] = {
|
|
||||||
'pm_dict': {},
|
|
||||||
'stream_dict': {},
|
|
||||||
'muted_stream_ids': [],
|
|
||||||
'unmuted_stream_msgs': set(),
|
|
||||||
'huddle_dict': {},
|
|
||||||
'mentions': set()
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
state['raw_unread_msgs'] = get_raw_unread_data(user_profile)
|
state['raw_unread_msgs'] = get_raw_unread_data(user_profile)
|
||||||
|
else:
|
||||||
|
# For logged-out visitors, we treat all messages as read;
|
||||||
|
# calling this helper lets us return empty objects in the
|
||||||
|
# appropriate format.
|
||||||
|
state['raw_unread_msgs'] = extract_unread_data_from_um_rows([], user_profile)
|
||||||
|
|
||||||
if want('starred_messages'):
|
if want('starred_messages'):
|
||||||
state['starred_messages'] = [] if user_profile is None else get_starred_message_ids(user_profile)
|
state['starred_messages'] = [] if user_profile is None else get_starred_message_ids(user_profile)
|
||||||
|
|||||||
@@ -840,7 +840,6 @@ def get_starred_message_ids(user_profile: UserProfile) -> List[int]:
|
|||||||
).values_list('message_id', flat=True)[0:10000])
|
).values_list('message_id', flat=True)[0:10000])
|
||||||
|
|
||||||
def get_raw_unread_data(user_profile: UserProfile) -> RawUnreadMessagesResult:
|
def get_raw_unread_data(user_profile: UserProfile) -> RawUnreadMessagesResult:
|
||||||
|
|
||||||
excluded_recipient_ids = get_inactive_recipient_ids(user_profile)
|
excluded_recipient_ids = get_inactive_recipient_ids(user_profile)
|
||||||
|
|
||||||
user_msgs = UserMessage.objects.filter(
|
user_msgs = UserMessage.objects.filter(
|
||||||
@@ -867,10 +866,29 @@ def get_raw_unread_data(user_profile: UserProfile) -> RawUnreadMessagesResult:
|
|||||||
|
|
||||||
def extract_unread_data_from_um_rows(
|
def extract_unread_data_from_um_rows(
|
||||||
rows: List[Dict[str, Any]],
|
rows: List[Dict[str, Any]],
|
||||||
user_profile: UserProfile
|
user_profile: Optional[UserProfile]
|
||||||
) -> RawUnreadMessagesResult:
|
) -> RawUnreadMessagesResult:
|
||||||
|
|
||||||
|
pm_dict: Dict[int, Any] = {}
|
||||||
|
stream_dict: Dict[int, Any] = {}
|
||||||
|
unmuted_stream_msgs: Set[int] = set()
|
||||||
|
huddle_dict: Dict[int, Any] = {}
|
||||||
|
mentions: Set[int] = set()
|
||||||
|
|
||||||
|
raw_unread_messages: RawUnreadMessagesResult = dict(
|
||||||
|
pm_dict=pm_dict,
|
||||||
|
stream_dict=stream_dict,
|
||||||
|
muted_stream_ids=[],
|
||||||
|
unmuted_stream_msgs=unmuted_stream_msgs,
|
||||||
|
huddle_dict=huddle_dict,
|
||||||
|
mentions=mentions,
|
||||||
|
)
|
||||||
|
|
||||||
|
if user_profile is None:
|
||||||
|
return raw_unread_messages # nocoverage
|
||||||
|
|
||||||
muted_stream_ids = get_muted_stream_ids(user_profile)
|
muted_stream_ids = get_muted_stream_ids(user_profile)
|
||||||
|
raw_unread_messages['muted_stream_ids'] = muted_stream_ids
|
||||||
|
|
||||||
topic_mute_checker = build_topic_mute_checker(user_profile)
|
topic_mute_checker = build_topic_mute_checker(user_profile)
|
||||||
|
|
||||||
@@ -893,12 +911,6 @@ def extract_unread_data_from_um_rows(
|
|||||||
huddle_cache[recipient_id] = user_ids_string
|
huddle_cache[recipient_id] = user_ids_string
|
||||||
return user_ids_string
|
return user_ids_string
|
||||||
|
|
||||||
pm_dict = {}
|
|
||||||
stream_dict = {}
|
|
||||||
unmuted_stream_msgs = set()
|
|
||||||
huddle_dict = {}
|
|
||||||
mentions = set()
|
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
message_id = row['message_id']
|
message_id = row['message_id']
|
||||||
msg_type = row['message__recipient__type']
|
msg_type = row['message__recipient__type']
|
||||||
@@ -952,14 +964,7 @@ def extract_unread_data_from_um_rows(
|
|||||||
else: # nocoverage # TODO: Test wildcard mentions in PMs.
|
else: # nocoverage # TODO: Test wildcard mentions in PMs.
|
||||||
mentions.add(message_id)
|
mentions.add(message_id)
|
||||||
|
|
||||||
return dict(
|
return raw_unread_messages
|
||||||
pm_dict=pm_dict,
|
|
||||||
stream_dict=stream_dict,
|
|
||||||
muted_stream_ids=muted_stream_ids,
|
|
||||||
unmuted_stream_msgs=unmuted_stream_msgs,
|
|
||||||
huddle_dict=huddle_dict,
|
|
||||||
mentions=mentions,
|
|
||||||
)
|
|
||||||
|
|
||||||
def aggregate_unread_data(raw_data: RawUnreadMessagesResult) -> UnreadMessagesResult:
|
def aggregate_unread_data(raw_data: RawUnreadMessagesResult) -> UnreadMessagesResult:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user