2017-08-30 02:42:52 +02:00
|
|
|
from django.conf import settings
|
2017-01-24 01:48:35 +01:00
|
|
|
from zerver.models import UserProfile, UserHotspot
|
|
|
|
|
2017-04-15 05:50:59 +02:00
|
|
|
from typing import List, Text, Dict
|
|
|
|
|
|
|
|
ALL_HOTSPOTS = {
|
2017-07-14 03:20:27 +02:00
|
|
|
# TODO: Tag these for translation once we've finalized the content.
|
2017-08-30 02:13:04 +02:00
|
|
|
'intro_reply': {
|
|
|
|
'title': 'Reply to a message',
|
2017-07-14 03:20:27 +02:00
|
|
|
'description': 'Click anywhere on a message to reply.',
|
|
|
|
},
|
2017-08-30 02:19:55 +02:00
|
|
|
'intro_streams': {
|
|
|
|
'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.',
|
|
|
|
},
|
|
|
|
'intro_topics': {
|
|
|
|
'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:15:32 +02:00
|
|
|
'intro_compose': {
|
|
|
|
'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
|
|
|
},
|
2017-11-08 19:20:28 +01:00
|
|
|
} # type: Dict[str, Dict[str, Text]]
|
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]]:
|
2017-08-30 02:42:52 +02:00
|
|
|
# Only used for manual testing
|
|
|
|
SEND_ALL = False
|
|
|
|
if settings.DEVELOPMENT and SEND_ALL:
|
|
|
|
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 []
|