mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
hotspots: Refactor backend for hotspots v2.
This commit is contained in:
@@ -3,15 +3,31 @@ from zerver.models import UserProfile, UserHotspot
|
|||||||
from typing import List, Text, Dict
|
from typing import List, Text, Dict
|
||||||
|
|
||||||
ALL_HOTSPOTS = {
|
ALL_HOTSPOTS = {
|
||||||
'click_to_reply': 'Click anywhere on a message to reply.',
|
# TODO: Tag these for translation once we've finalized the content.
|
||||||
'new_topic_botton': 'Click the "New topic" button to start a new conversation.',
|
'click_to_reply': {
|
||||||
'stream_settings': 'Most discussion on Zulip happens in streams. Click here to create or join additional streams.',
|
'title': 'Respond to a message',
|
||||||
}
|
'description': 'Click anywhere on a message to reply.',
|
||||||
|
},
|
||||||
|
'new_topic_button': {
|
||||||
|
'title': 'Start a new topic',
|
||||||
|
'description': 'Click the "New topic" button to start a new conversation.',
|
||||||
|
},
|
||||||
|
'stream_settings': {
|
||||||
|
'title': 'Stream settings',
|
||||||
|
'description': 'Most discussion on Zulip happens in streams. Click here to create or join additional streams.',
|
||||||
|
},
|
||||||
|
} # type Dict[str, Dict[str, Text]]
|
||||||
|
|
||||||
def get_next_hotspots(user):
|
def get_next_hotspots(user):
|
||||||
# type: (UserProfile) -> List[Dict[str, Text]]
|
# type: (UserProfile) -> List[Dict[str, object]]
|
||||||
seen_hotspots = frozenset(UserHotspot.objects.filter(user=user).values_list('hotspot', flat=True))
|
seen_hotspots = frozenset(UserHotspot.objects.filter(user=user).values_list('hotspot', flat=True))
|
||||||
for hotspot in ['click_to_reply', 'new_topic_botton', 'stream_settings']:
|
for hotspot in ['click_to_reply', 'new_topic_button', 'stream_settings']:
|
||||||
if hotspot not in seen_hotspots:
|
if hotspot not in seen_hotspots:
|
||||||
return [{'name': hotspot, 'description': ALL_HOTSPOTS[hotspot]}]
|
return [{
|
||||||
|
'name': hotspot,
|
||||||
|
'title': ALL_HOTSPOTS[hotspot]['title'],
|
||||||
|
'description': ALL_HOTSPOTS[hotspot]['description'],
|
||||||
|
'delay': 5,
|
||||||
|
}]
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -1369,7 +1369,9 @@ class EventsRegisterTest(ZulipTestCase):
|
|||||||
('type', equals('hotspots')),
|
('type', equals('hotspots')),
|
||||||
('hotspots', check_list(check_dict_only([
|
('hotspots', check_list(check_dict_only([
|
||||||
('name', check_string),
|
('name', check_string),
|
||||||
|
('title', check_string),
|
||||||
('description', check_string),
|
('description', check_string),
|
||||||
|
('delay', check_int),
|
||||||
]))),
|
]))),
|
||||||
])
|
])
|
||||||
events = self.do_test(lambda: do_mark_hotspot_as_read(self.user_profile, 'click_to_reply'))
|
events = self.do_test(lambda: do_mark_hotspot_as_read(self.user_profile, 'click_to_reply'))
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class TestGetNextHotspots(ZulipTestCase):
|
|||||||
do_mark_hotspot_as_read(user, 'stream_settings')
|
do_mark_hotspot_as_read(user, 'stream_settings')
|
||||||
hotspots = get_next_hotspots(user)
|
hotspots = get_next_hotspots(user)
|
||||||
self.assertEqual(len(hotspots), 1)
|
self.assertEqual(len(hotspots), 1)
|
||||||
self.assertEqual(hotspots[0]['name'], 'new_topic_botton')
|
self.assertEqual(hotspots[0]['name'], 'new_topic_button')
|
||||||
|
|
||||||
def test_all_done(self):
|
def test_all_done(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
|||||||
Reference in New Issue
Block a user