2019-02-27 19:19:49 +01:00
|
|
|
# See https://zulip.readthedocs.io/en/latest/subsystems/hotspots.html
|
|
|
|
# for documentation on this subsystem.
|
2023-04-09 16:48:08 +02:00
|
|
|
from dataclasses import dataclass
|
2023-12-01 14:36:24 +01:00
|
|
|
from typing import Any, Dict, List, Optional, Union
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2017-08-30 02:42:52 +02:00
|
|
|
from django.conf import settings
|
2021-04-16 00:57:30 +02:00
|
|
|
from django.utils.translation import gettext_lazy
|
2022-09-19 21:43:34 +02:00
|
|
|
from django_stubs_ext import StrPromise
|
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
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Hotspot:
|
|
|
|
name: str
|
|
|
|
title: Optional[StrPromise]
|
|
|
|
description: Optional[StrPromise]
|
|
|
|
has_trigger: bool = False
|
|
|
|
|
|
|
|
def to_dict(self, delay: float = 0) -> Dict[str, Union[str, float, bool]]:
|
|
|
|
return {
|
2023-12-05 12:47:03 +01:00
|
|
|
"type": "hotspot",
|
2023-04-09 16:48:08 +02:00
|
|
|
"name": self.name,
|
|
|
|
"title": str(self.title),
|
|
|
|
"description": str(self.description),
|
|
|
|
"delay": delay,
|
|
|
|
"has_trigger": self.has_trigger,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INTRO_HOTSPOTS: List[Hotspot] = [
|
|
|
|
Hotspot(
|
|
|
|
name="intro_streams",
|
|
|
|
title=gettext_lazy("Catch up on a stream"),
|
|
|
|
description=gettext_lazy(
|
2021-02-12 08:20:45 +01:00
|
|
|
"Messages sent to a stream are seen by everyone subscribed "
|
|
|
|
"to that stream. Try clicking on one of the stream links below."
|
2020-10-17 03:00:33 +02:00
|
|
|
),
|
2023-04-09 16:48:08 +02:00
|
|
|
),
|
|
|
|
Hotspot(
|
|
|
|
name="intro_topics",
|
|
|
|
title=gettext_lazy("Topics"),
|
|
|
|
description=gettext_lazy(
|
2021-02-12 08:20:45 +01:00
|
|
|
"Every message has a topic. Topics keep conversations "
|
|
|
|
"easy to follow, and make it easy to reply to conversations that start "
|
|
|
|
"while you are offline."
|
2020-10-17 03:00:33 +02:00
|
|
|
),
|
2023-04-09 16:48:08 +02:00
|
|
|
),
|
|
|
|
Hotspot(
|
2023-12-02 02:53:47 +01:00
|
|
|
# In theory, this should be renamed to intro_personal, since
|
|
|
|
# it's no longer attached to the gear menu, but renaming these
|
|
|
|
# requires a migration that is not worth doing at this time.
|
2023-04-09 16:48:08 +02:00
|
|
|
name="intro_gear",
|
|
|
|
title=gettext_lazy("Settings"),
|
|
|
|
description=gettext_lazy("Go to Settings to configure your notifications and preferences."),
|
|
|
|
),
|
|
|
|
Hotspot(
|
|
|
|
name="intro_compose",
|
|
|
|
title=gettext_lazy("Compose"),
|
|
|
|
description=gettext_lazy(
|
2021-02-12 08:20:45 +01:00
|
|
|
"Click here to start a new conversation. Pick a topic "
|
|
|
|
"(2-3 words is best), and give it a go!"
|
2020-10-17 03:00:33 +02:00
|
|
|
),
|
2023-04-09 16:48:08 +02:00
|
|
|
),
|
|
|
|
]
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2023-04-09 16:48:08 +02:00
|
|
|
NON_INTRO_HOTSPOTS: List[Hotspot] = []
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class OneTimeNotice:
|
|
|
|
name: str
|
|
|
|
|
|
|
|
def to_dict(self) -> Dict[str, str]:
|
|
|
|
return {
|
|
|
|
"type": "one_time_notice",
|
|
|
|
"name": self.name,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-02 13:34:05 +01:00
|
|
|
ONE_TIME_NOTICES: List[OneTimeNotice] = [
|
|
|
|
OneTimeNotice(
|
|
|
|
name="visibility_policy_banner",
|
|
|
|
),
|
|
|
|
]
|
2023-12-01 14:36:24 +01:00
|
|
|
|
2021-02-18 15:17:03 +01:00
|
|
|
# We would most likely implement new hotspots in the future that aren't
|
|
|
|
# a part of the initial tutorial. To that end, classifying them into
|
|
|
|
# categories which are aggregated in ALL_HOTSPOTS, seems like a good start.
|
2023-04-09 16:48:08 +02:00
|
|
|
ALL_HOTSPOTS = [*INTRO_HOTSPOTS, *NON_INTRO_HOTSPOTS]
|
2023-12-01 14:36:24 +01:00
|
|
|
ALL_ONBOARDING_STEPS: List[Union[Hotspot, OneTimeNotice]] = [*ALL_HOTSPOTS, *ONE_TIME_NOTICES]
|
2023-04-09 16:48:08 +02:00
|
|
|
|
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
def get_next_onboarding_steps(user: UserProfile) -> List[Dict[str, Any]]:
|
2018-03-18 20:59:10 +01:00
|
|
|
# For manual testing, it can be convenient to set
|
|
|
|
# ALWAYS_SEND_ALL_HOTSPOTS=True in `zproject/dev_settings.py` to
|
2021-05-08 11:08:08 +02:00
|
|
|
# make it easy to click on all of the hotspots.
|
2021-02-18 15:17:03 +01:00
|
|
|
#
|
2021-04-25 22:54:23 +02:00
|
|
|
# Since this is just for development purposes, it's convenient for us to send
|
2021-02-18 15:17:03 +01:00
|
|
|
# all the hotspots rather than any specific category.
|
2018-03-18 20:59:10 +01:00
|
|
|
if settings.ALWAYS_SEND_ALL_HOTSPOTS:
|
2023-04-09 16:48:08 +02:00
|
|
|
return [hotspot.to_dict() for hotspot in ALL_HOTSPOTS]
|
2017-08-02 07:23:27 +02:00
|
|
|
|
2021-03-11 17:19:49 +01:00
|
|
|
# If a Zulip server has disabled the tutorial, never send hotspots.
|
|
|
|
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
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
onboarding_steps: List[Dict[str, Any]] = [hotspot.to_dict() for hotspot in NON_INTRO_HOTSPOTS]
|
|
|
|
|
|
|
|
for one_time_notice in ONE_TIME_NOTICES:
|
|
|
|
if one_time_notice.name in seen_onboarding_steps:
|
|
|
|
continue
|
|
|
|
onboarding_steps.append(one_time_notice.to_dict())
|
2021-05-08 11:00:12 +02:00
|
|
|
|
|
|
|
if user.tutorial_status == UserProfile.TUTORIAL_FINISHED:
|
2023-12-01 14:36:24 +01:00
|
|
|
return onboarding_steps
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2023-04-09 16:48:08 +02:00
|
|
|
for hotspot in INTRO_HOTSPOTS:
|
2023-12-01 14:36:24 +01:00
|
|
|
if hotspot.name in seen_onboarding_steps:
|
2021-05-08 11:00:12 +02:00
|
|
|
continue
|
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
onboarding_steps.append(hotspot.to_dict(delay=0.5))
|
|
|
|
return onboarding_steps
|
2017-08-31 18:20:03 +02:00
|
|
|
|
|
|
|
user.tutorial_status = UserProfile.TUTORIAL_FINISHED
|
2021-02-12 08:20:45 +01:00
|
|
|
user.save(update_fields=["tutorial_status"])
|
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
|
|
|
|
2020-12-20 13:03:32 +01:00
|
|
|
def copy_hotspots(source_profile: UserProfile, target_profile: UserProfile) -> None:
|
2023-12-01 08:20:48 +01:00
|
|
|
for userhotspot in frozenset(OnboardingStep.objects.filter(user=source_profile)):
|
|
|
|
OnboardingStep.objects.create(
|
|
|
|
user=target_profile,
|
|
|
|
onboarding_step=userhotspot.onboarding_step,
|
|
|
|
timestamp=userhotspot.timestamp,
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2018-06-13 14:10:53 +02:00
|
|
|
|
|
|
|
target_profile.tutorial_status = source_profile.tutorial_status
|
|
|
|
target_profile.onboarding_steps = source_profile.onboarding_steps
|
2021-02-12 08:20:45 +01:00
|
|
|
target_profile.save(update_fields=["tutorial_status", "onboarding_steps"])
|