2024-06-18 13:34:32 +02:00
|
|
|
# See https://zulip.readthedocs.io/en/latest/subsystems/onboarding-steps.html
|
|
|
|
# for documentation on this subsystem.
|
2023-04-09 16:48:08 +02:00
|
|
|
from dataclasses import dataclass
|
2024-07-12 02:30:17 +02:00
|
|
|
from typing import Any
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2017-08-30 02:42:52 +02:00
|
|
|
from django.conf import settings
|
2018-04-18 18:16:30 +02:00
|
|
|
|
2023-12-01 08:20:48 +01:00
|
|
|
from zerver.models import OnboardingStep, UserProfile
|
2017-04-15 05:50:59 +02:00
|
|
|
|
2023-04-09 16:48:08 +02:00
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
@dataclass
|
|
|
|
class OneTimeNotice:
|
|
|
|
name: str
|
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def to_dict(self) -> dict[str, str]:
|
2023-12-01 14:36:24 +01:00
|
|
|
return {
|
|
|
|
"type": "one_time_notice",
|
|
|
|
"name": self.name,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-24 13:51:19 +02:00
|
|
|
@dataclass
|
|
|
|
class OneTimeAction:
|
|
|
|
name: str
|
|
|
|
|
|
|
|
def to_dict(self) -> dict[str, str]:
|
|
|
|
return {
|
|
|
|
"type": "one_time_action",
|
|
|
|
"name": self.name,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
ONE_TIME_NOTICES: list[OneTimeNotice] = [
|
2023-12-02 13:34:05 +01:00
|
|
|
OneTimeNotice(
|
|
|
|
name="visibility_policy_banner",
|
|
|
|
),
|
2024-03-05 12:03:05 +01:00
|
|
|
OneTimeNotice(
|
|
|
|
name="intro_inbox_view_modal",
|
|
|
|
),
|
2024-03-05 13:18:56 +01:00
|
|
|
OneTimeNotice(
|
|
|
|
name="intro_recent_view_modal",
|
|
|
|
),
|
2024-04-04 13:58:27 +02:00
|
|
|
OneTimeNotice(
|
|
|
|
name="first_stream_created_banner",
|
|
|
|
),
|
2024-04-03 12:01:57 +02:00
|
|
|
OneTimeNotice(
|
|
|
|
name="jump_to_conversation_banner",
|
|
|
|
),
|
2024-04-05 13:32:42 +02:00
|
|
|
OneTimeNotice(
|
|
|
|
name="non_interleaved_view_messages_fading",
|
|
|
|
),
|
2024-04-23 09:04:05 +02:00
|
|
|
OneTimeNotice(
|
|
|
|
name="interleaved_view_messages_fading",
|
|
|
|
),
|
2024-09-20 16:29:28 +02:00
|
|
|
OneTimeNotice(
|
|
|
|
name="intro_resolve_topic",
|
|
|
|
),
|
2023-12-02 13:34:05 +01:00
|
|
|
]
|
2023-12-01 14:36:24 +01:00
|
|
|
|
2024-07-24 13:51:19 +02:00
|
|
|
ONE_TIME_ACTIONS = [OneTimeAction(name="narrow_to_dm_with_welcome_bot_new_user")]
|
|
|
|
|
|
|
|
ALL_ONBOARDING_STEPS: list[OneTimeNotice | OneTimeAction] = ONE_TIME_NOTICES + ONE_TIME_ACTIONS
|
2023-04-09 16:48:08 +02:00
|
|
|
|
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def get_next_onboarding_steps(user: UserProfile) -> list[dict[str, Any]]:
|
2024-05-10 15:37:43 +02:00
|
|
|
# If a Zulip server has disabled the tutorial, never send any
|
|
|
|
# onboarding steps.
|
2021-03-11 17:19:49 +01:00
|
|
|
if not settings.TUTORIAL_ENABLED:
|
|
|
|
return []
|
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
seen_onboarding_steps = frozenset(
|
2023-12-01 08:20:48 +01:00
|
|
|
OnboardingStep.objects.filter(user=user).values_list("onboarding_step", flat=True)
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
onboarding_steps: list[dict[str, Any]] = []
|
2024-07-24 13:51:19 +02:00
|
|
|
for onboarding_step in ALL_ONBOARDING_STEPS:
|
|
|
|
if onboarding_step.name in seen_onboarding_steps:
|
2023-12-01 14:36:24 +01:00
|
|
|
continue
|
2024-07-24 13:51:19 +02:00
|
|
|
onboarding_steps.append(onboarding_step.to_dict())
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
return onboarding_steps
|
2018-06-13 14:10:53 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2024-05-10 13:14:45 +02:00
|
|
|
def copy_onboarding_steps(source_profile: UserProfile, target_profile: UserProfile) -> None:
|
|
|
|
for onboarding_step in frozenset(OnboardingStep.objects.filter(user=source_profile)):
|
2023-12-01 08:20:48 +01:00
|
|
|
OnboardingStep.objects.create(
|
|
|
|
user=target_profile,
|
2024-05-10 13:14:45 +02:00
|
|
|
onboarding_step=onboarding_step.onboarding_step,
|
|
|
|
timestamp=onboarding_step.timestamp,
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|