def send_initial_realm_messages(realm): # type: (Realm) -> None welcome_bot = get_system_bot(settings.WELCOME_BOT) # Make sure each stream created in the realm creation process has at least one message below # Order corresponds to the ordering of the streams on the left sidebar, to make the initial Home # view slightly less overwhelming welcome_messages = [ {'stream': Realm.DEFAULT_NOTIFICATION_STREAM_NAME, 'topic': "welcome", 'content': "This is a message on stream `%s` with the topic `welcome`. We'll use this stream " "for system-generated notifications." % (Realm.DEFAULT_NOTIFICATION_STREAM_NAME,)}, {'stream': "core team", 'topic': "private streams", 'content': "This is a private stream. Only admins and people you invite " "to the stream will be able to see that this stream exists."}, {'stream': "general", 'topic': "welcome", 'content': "Welcome to #**general**."}, {'stream': "new members", 'topic': "onboarding", 'content': "A #**new members** stream is great for onboarding new members.\n\nIf you're " "reading this and aren't the first person here, introduce yourself in a new thread " "using your name as the topic! Type `c` or click on `New Topic` at the bottom of the " "screen to start a new topic."}, {'stream': "zulip", 'topic': "topic demonstration", 'content': "Here is a message in one topic. Replies to this message will go to this topic."}, {'stream': "zulip", 'topic': "topic demonstration", 'content': "A second message in this topic. With [turtles](/static/images/cute/turtle.png)!"}, {'stream': "zulip", 'topic': "second topic", 'content': "This is a message in a second topic.\n\nTopics are similar to email subjects, " "in that each conversation should get its own topic. Keep them short, though; one " "or two words will do it!"}, ] # type: List[Dict[str, Text]] messages = [internal_prep_stream_message( realm, welcome_bot, message['stream'], message['topic'], message['content']) for message in welcome_messages] message_ids = do_send_messages(messages) # We find the one of our just-sent messages with turtle.png in it, # and react to it. This is a bit hacky, but works and is kinda a # 1-off thing. turtle_message = Message.objects.get( id__in=message_ids, subject='topic demonstration', content__icontains='cute/turtle.png') do_add_reaction_legacy(welcome_bot, turtle_message, 'turtle')
def send_initial_realm_messages(realm: Realm) -> None: welcome_bot = get_system_bot(settings.WELCOME_BOT) # Make sure each stream created in the realm creation process has at least one message below # Order corresponds to the ordering of the streams on the left sidebar, to make the initial Home # view slightly less overwhelming welcome_messages = [ {'stream': Realm.DEFAULT_NOTIFICATION_STREAM_NAME, 'topic': "welcome", 'content': "This is a message on stream `%s` with the topic `welcome`. We'll use this stream " "for system-generated notifications." % (Realm.DEFAULT_NOTIFICATION_STREAM_NAME,)}, {'stream': Realm.INITIAL_PRIVATE_STREAM_NAME, 'topic': "private streams", 'content': "This is a private stream. Only admins and people you invite " "to the stream will be able to see that this stream exists."}, {'stream': "general", 'topic': "welcome", 'content': "Welcome to #**general**."}, {'stream': "new members", 'topic': "onboarding", 'content': "A #**new members** stream is great for onboarding new members.\n\nIf you're " "reading this and aren't the first person here, introduce yourself in a new thread " "using your name as the topic! Type `c` or click on `New Topic` at the bottom of the " "screen to start a new topic."}, {'stream': "zulip", 'topic': "topic demonstration", 'content': "Here is a message in one topic. Replies to this message will go to this topic."}, {'stream': "zulip", 'topic': "topic demonstration", 'content': "A second message in this topic. With [turtles](/static/images/cute/turtle.png)!"}, {'stream': "zulip", 'topic': "second topic", 'content': "This is a message in a second topic.\n\nTopics are similar to email subjects, " "in that each conversation should get its own topic. Keep them short, though; one " "or two words will do it!"}, ] # type: List[Dict[str, str]] messages = [internal_prep_stream_message( realm, welcome_bot, message['topic'], message['content'], stream_name=message['stream'] ) for message in welcome_messages] message_ids = do_send_messages(messages) # We find the one of our just-sent messages with turtle.png in it, # and react to it. This is a bit hacky, but works and is kinda a # 1-off thing. turtle_message = get_turtle_message(message_ids=message_ids) do_add_reaction_legacy(welcome_bot, turtle_message, 'turtle')
def send_initial_realm_messages(realm: Realm) -> None: welcome_bot = get_system_bot(settings.WELCOME_BOT) # Make sure each stream created in the realm creation process has at least one message below # Order corresponds to the ordering of the streams on the left sidebar, to make the initial Home # view slightly less overwhelming welcome_messages = [ {'stream': Realm.INITIAL_PRIVATE_STREAM_NAME, 'topic': "private streams", 'content': "This is a private stream, as indicated by the " "lock icon next to the stream name. Private streams are only visible to stream members. " "\n\nTo manage this stream, go to [Stream settings](#streams/subscribed) and click on " "`%(initial_private_stream_name)s`."}, {'stream': Realm.DEFAULT_NOTIFICATION_STREAM_NAME, 'topic': "topic demonstration", 'content': "This is a message on stream #**%(default_notification_stream_name)s** with the " "topic `topic demonstration`."}, {'stream': Realm.DEFAULT_NOTIFICATION_STREAM_NAME, 'topic': "topic demonstration", 'content': "Topics are a lightweight tool to keep conversations organized. " "You can learn more about topics at [Streams and topics](/help/about-streams-and-topics). "}, {'stream': realm.DEFAULT_NOTIFICATION_STREAM_NAME, 'topic': "swimming turtles", 'content': "This is a message on stream #**%(default_notification_stream_name)s** with the " "topic `swimming turtles`. " "\n\n[](/static/images/cute/turtle.png)" "\n\n[Start a new topic](/help/start-a-new-topic) any time you're not replying to a " "previous message."}, ] # type: List[Dict[str, str]] messages = [internal_prep_stream_message_by_name( realm, welcome_bot, message['stream'], message['topic'], message['content'] % { 'initial_private_stream_name': Realm.INITIAL_PRIVATE_STREAM_NAME, 'default_notification_stream_name': Realm.DEFAULT_NOTIFICATION_STREAM_NAME, } ) for message in welcome_messages] message_ids = do_send_messages(messages) # We find the one of our just-sent messages with turtle.png in it, # and react to it. This is a bit hacky, but works and is kinda a # 1-off thing. turtle_message = Message.objects.get( id__in=message_ids, content__icontains='cute/turtle.png') do_add_reaction_legacy(welcome_bot, turtle_message, 'turtle')
def add_reaction_legacy(request: HttpRequest, user_profile: UserProfile, message_id: int, emoji_name: Text) -> HttpResponse: # access_message will throw a JsonableError exception if the user # cannot see the message (e.g. for messages to private streams). message, user_message = access_message(user_profile, message_id) check_valid_emoji(message.sender.realm, emoji_name) # We could probably just make this check be a try/except for the # IntegrityError from it already existing, but this is a bit cleaner. if Reaction.objects.filter(user_profile=user_profile, message=message, emoji_name=emoji_name).exists(): raise JsonableError(_("Reaction already exists")) if user_message is None: create_historical_message(user_profile, message) do_add_reaction_legacy(user_profile, message, emoji_name) return json_success()
def add_message_formatting_conversation(self) -> None: realm = get_realm('zulip') stream, _ = create_stream_if_needed(realm, 'zulip features') UserProfile.objects.filter(email__contains='stage').delete() starr = do_create_user('*****@*****.**', 'password', realm, 'Ada Starr', '') self.set_avatar(starr, 'static/images/features/starr.png') fisher = do_create_user('*****@*****.**', 'password', realm, 'Bel Fisher', '') self.set_avatar(fisher, 'static/images/features/fisher.png') twitter_bot = do_create_user('*****@*****.**', 'password', realm, 'Twitter Bot', '', bot_type=UserProfile.DEFAULT_BOT) self.set_avatar(twitter_bot, 'static/images/features/twitter.png') bulk_add_subscriptions([stream], list(UserProfile.objects.filter(realm=realm))) staged_messages = [ { 'sender': starr, 'content': "Hey @**Bel Fisher**, check out Zulip's Markdown formatting! " "You can have:\n* bulleted lists\n * with sub-bullets too\n" "* **bold**, *italic*, and ~~strikethrough~~ text\n" "* LaTeX for mathematical formulas, both inline -- $$O(n^2)$$ -- and displayed:\n" "```math\n\\int_a^b f(t)\, dt=F(b)-F(a)\n```" }, { 'sender': fisher, 'content': "My favorite is the syntax highlighting for code blocks\n" "```python\ndef fib(n):\n # returns the n-th Fibonacci number\n" " return fib(n-1) + fib(n-2)\n```" }, { 'sender': starr, 'content': "I think you forgot your base case there, Bel :laughing:\n" "```quote\n```python\ndef fib(n):\n # returns the n-th Fibonacci number\n" " return fib(n-1) + fib(n-2)\n```\n```" }, { 'sender': fisher, 'content': "I'm also a big fan of inline link, tweet, video, and image previews. " "Check out this picture of Çet Whalin[](/static/images/features/whale.png)!" }, { 'sender': starr, 'content': "I just set up a custom linkifier, " "so `#1234` becomes [#1234](github.com/zulip/zulip/1234), " "a link to the corresponding GitHub issue." }, { 'sender': twitter_bot, 'content': 'https://twitter.com/gvanrossum/status/786661035637772288' }, { 'sender': fisher, 'content': "Oops, the Twitter bot I set up shouldn't be posting here. Let me go fix that." }, ] # type: List[Dict[str, Any]] messages = [ internal_prep_stream_message(realm, message['sender'], stream.name, 'message formatting', message['content']) for message in staged_messages ] message_ids = do_send_messages(messages) preview_message = Message.objects.get( id__in=message_ids, content__icontains='image previews') do_add_reaction_legacy(starr, preview_message, 'whale') twitter_message = Message.objects.get(id__in=message_ids, content__icontains='gvanrossum') # Setting up a twitter integration in dev is a decent amount of work. If you need # to update this tweet, either copy the format below, or send the link to the tweet # to chat.zulip.org and ask an admin of that server to get you the rendered_content. twitter_message.rendered_content = ( '<p><a>https://twitter.com/gvanrossum/status/786661035637772288</a></p>\n' '<div class="inline-preview-twitter"><div class="twitter-tweet">' '<a><img class="twitter-avatar" ' 'src="https://pbs.twimg.com/profile_images/424495004/GuidoAvatar_bigger.jpg"></a>' '<p>Great blog post about Zulip\'s use of mypy: ' '<a>http://blog.zulip.org/2016/10/13/static-types-in-python-oh-mypy/</a></p>' '<span>- Guido van Rossum (@gvanrossum)</span></div></div>') twitter_message.save(update_fields=['rendered_content']) # Put a short pause between the whale reaction and this, so that the # thumbs_up shows up second do_add_reaction_legacy(starr, preview_message, 'thumbs_up')
def add_message_formatting_conversation(self) -> None: realm = get_realm('zulip') stream, _ = create_stream_if_needed(realm, 'zulip features') UserProfile.objects.filter(email__contains='stage').delete() starr = do_create_user('*****@*****.**', 'password', realm, 'Ada Starr', '') self.set_avatar(starr, 'static/images/features/starr.png') fisher = do_create_user('*****@*****.**', 'password', realm, 'Bel Fisher', '') self.set_avatar(fisher, 'static/images/features/fisher.png') twitter_bot = do_create_user('*****@*****.**', 'password', realm, 'Twitter Bot', '', bot_type=UserProfile.DEFAULT_BOT) self.set_avatar(twitter_bot, 'static/images/features/twitter.png') bulk_add_subscriptions([stream], list(UserProfile.objects.filter(realm=realm))) staged_messages = [ {'sender': starr, 'content': "Hey @**Bel Fisher**, check out Zulip's Markdown formatting! " "You can have:\n* bulleted lists\n * with sub-bullets too\n" "* **bold**, *italic*, and ~~strikethrough~~ text\n" "* LaTeX for mathematical formulas, both inline -- $$O(n^2)$$ -- and displayed:\n" "```math\n\\int_a^b f(t)\, dt=F(b)-F(a)\n```"}, {'sender': fisher, 'content': "My favorite is the syntax highlighting for code blocks\n" "```python\ndef fib(n: int) -> int:\n # returns the n-th Fibonacci number\n" " return fib(n-1) + fib(n-2)\n```"}, {'sender': starr, 'content': "I think you forgot your base case there, Bel :laughing:\n" "```quote\n```python\ndef fib(n: int) -> int:\n # returns the n-th Fibonacci number\n" " return fib(n-1) + fib(n-2)\n```\n```"}, {'sender': fisher, 'content': "I'm also a big fan of inline link, tweet, video, and image previews. " "Check out this picture of Çet Whalin[](/static/images/features/whale.png)!"}, {'sender': starr, 'content': "I just set up a custom linkifier, " "so `#1234` becomes [#1234](github.com/zulip/zulip/1234), " "a link to the corresponding GitHub issue."}, {'sender': twitter_bot, 'content': 'https://twitter.com/gvanrossum/status/786661035637772288'}, {'sender': fisher, 'content': "Oops, the Twitter bot I set up shouldn't be posting here. Let me go fix that."}, ] # type: List[Dict[str, Any]] messages = [internal_prep_stream_message( realm, message['sender'], stream.name, 'message formatting', message['content'] ) for message in staged_messages] message_ids = do_send_messages(messages) preview_message = Message.objects.get(id__in=message_ids, content__icontains='image previews') do_add_reaction_legacy(starr, preview_message, 'whale') twitter_message = Message.objects.get(id__in=message_ids, content__icontains='gvanrossum') # Setting up a twitter integration in dev is a decent amount of work. If you need # to update this tweet, either copy the format below, or send the link to the tweet # to chat.zulip.org and ask an admin of that server to get you the rendered_content. twitter_message.rendered_content = ( '<p><a>https://twitter.com/gvanrossum/status/786661035637772288</a></p>\n' '<div class="inline-preview-twitter"><div class="twitter-tweet">' '<a><img class="twitter-avatar" ' 'src="https://pbs.twimg.com/profile_images/424495004/GuidoAvatar_bigger.jpg"></a>' '<p>Great blog post about Zulip\'s use of mypy: ' '<a>http://blog.zulip.org/2016/10/13/static-types-in-python-oh-mypy/</a></p>' '<span>- Guido van Rossum (@gvanrossum)</span></div></div>') twitter_message.save(update_fields=['rendered_content']) # Put a short pause between the whale reaction and this, so that the # thumbs_up shows up second do_add_reaction_legacy(starr, preview_message, 'thumbs_up')