2017-08-30 02:42:52 +02:00
|
|
|
from django.conf import settings
|
2018-04-18 18:16:30 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
2017-01-24 01:48:35 +01:00
|
|
|
from zerver.models import UserProfile, UserHotspot
|
|
|
|
|
2018-05-10 19:13:36 +02:00
|
|
|
from typing import List, Dict
|
2017-04-15 05:50:59 +02:00
|
|
|
|
|
|
|
ALL_HOTSPOTS = {
|
2017-08-30 02:13:04 +02:00
|
|
|
'intro_reply': {
|
2018-04-18 18:16:30 +02:00
|
|
|
'title': _('Reply to a message'),
|
|
|
|
'description': _('Click anywhere on a message to reply.'),
|
2017-07-14 03:20:27 +02:00
|
|
|
},
|
2017-08-30 02:19:55 +02:00
|
|
|
'intro_streams': {
|
2018-04-18 18:16:30 +02:00
|
|
|
'title': _('Catch up on a stream'),
|
|
|
|
'description': _('Messages sent to a stream are seen by everyone subscribed '
|
|
|
|
'to that stream. Try clicking on one of the stream links below.'),
|
2017-08-30 02:19:55 +02:00
|
|
|
},
|
|
|
|
'intro_topics': {
|
2018-04-18 18:16:30 +02:00
|
|
|
'title': _('Topics'),
|
|
|
|
'description': _('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.'),
|
2017-08-30 02:19:55 +02:00
|
|
|
},
|
2017-08-30 02:15:32 +02:00
|
|
|
'intro_compose': {
|
2018-04-18 18:16:30 +02:00
|
|
|
'title': _('Compose'),
|
|
|
|
'description': _('Click here to start a new conversation. Pick a topic '
|
|
|
|
'(2-3 words is best), and give it a go!'),
|
2017-07-14 03:20:27 +02:00
|
|
|
},
|
2018-05-10 19:13:36 +02:00
|
|
|
} # type: Dict[str, Dict[str, str]]
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2017-11-05 11:15:10 +01:00
|
|
|
def get_next_hotspots(user: UserProfile) -> List[Dict[str, object]]:
|
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
|
|
|
|
# make it easy to click on all of the hotspots.
|
|
|
|
if settings.ALWAYS_SEND_ALL_HOTSPOTS:
|
2017-08-30 02:42:52 +02:00
|
|
|
return [{
|
|
|
|
'name': hotspot,
|
|
|
|
'title': ALL_HOTSPOTS[hotspot]['title'],
|
|
|
|
'description': ALL_HOTSPOTS[hotspot]['description'],
|
|
|
|
'delay': 0,
|
|
|
|
} for hotspot in ALL_HOTSPOTS]
|
2017-08-02 07:23:27 +02:00
|
|
|
|
2017-08-31 18:20:03 +02:00
|
|
|
if user.tutorial_status == UserProfile.TUTORIAL_FINISHED:
|
|
|
|
return []
|
|
|
|
|
2017-01-24 01:48:35 +01:00
|
|
|
seen_hotspots = frozenset(UserHotspot.objects.filter(user=user).values_list('hotspot', flat=True))
|
2017-08-30 02:19:55 +02:00
|
|
|
for hotspot in ['intro_reply', 'intro_streams', 'intro_topics', 'intro_compose']:
|
2017-01-24 01:48:35 +01:00
|
|
|
if hotspot not in seen_hotspots:
|
2017-07-14 03:20:27 +02:00
|
|
|
return [{
|
|
|
|
'name': hotspot,
|
|
|
|
'title': ALL_HOTSPOTS[hotspot]['title'],
|
|
|
|
'description': ALL_HOTSPOTS[hotspot]['description'],
|
2017-08-31 05:13:37 +02:00
|
|
|
'delay': 0.5,
|
2017-07-14 03:20:27 +02:00
|
|
|
}]
|
2017-08-31 18:20:03 +02:00
|
|
|
|
|
|
|
user.tutorial_status = UserProfile.TUTORIAL_FINISHED
|
|
|
|
user.save(update_fields=['tutorial_status'])
|
2017-01-24 01:48:35 +01:00
|
|
|
return []
|