From e6422b118d0b64e09e88fff5646b0b188d113152 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Sun, 28 Jan 2018 00:43:06 +0000 Subject: [PATCH] Display NSFW channel warning --- discordbot/titanembeds/utils.py | 1 + webapp/titanembeds/static/css/embedstyle.css | 6 ++++- webapp/titanembeds/static/js/embed.js | 27 ++++++++++++++++++-- webapp/titanembeds/templates/embed.html.j2 | 11 ++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/discordbot/titanembeds/utils.py b/discordbot/titanembeds/utils.py index 235673d..847f9a4 100644 --- a/discordbot/titanembeds/utils.py +++ b/discordbot/titanembeds/utils.py @@ -91,6 +91,7 @@ def get_channels_list(guildchannels): "type": str(channel.type), "permission_overwrites": overwrites, "parent_id": parent, + "nsfw": channel.is_nsfw, }) return channels diff --git a/webapp/titanembeds/static/css/embedstyle.css b/webapp/titanembeds/static/css/embedstyle.css index 83e832e..cdb8580 100644 --- a/webapp/titanembeds/static/css/embedstyle.css +++ b/webapp/titanembeds/static/css/embedstyle.css @@ -891,10 +891,14 @@ p.mentioned span.chatmessage { width: 302px; } -#logout_btn { +#logout_btn, #proceed_nsfw_btn { background-color: red; } +#nsfwmodal i { + color: yellow; +} + #message-spinner { position: fixed; top: 50%; diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index bee6be4..8e6cd56 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -179,6 +179,12 @@ inDuration: 400, outDuration: 400, }); + $("#nsfwmodal").modal({ + dismissible: true, + opacity: .3, + inDuration: 400, + outDuration: 400, + }); $("#usercard").modal({ opacity: .5, }); @@ -225,6 +231,17 @@ } }); + $("#proceed_nsfw_btn").click(function () { + var channel_id = $("#proceed_nsfw_btn").attr("channel_id"); + var should_animate = parseInt($("#proceed_nsfw_btn").attr("should_animate")); + $("#nsfwmodal").modal("close"); + select_channel(channel_id, should_animate, true); + }); + + $("#dismiss_nsfw_btn").click(function () { + $("#nsfwmodal").modal("close"); + }); + $( "#theme-selector" ).change(function () { var theme = $("#theme-selector option:selected").val(); var keep_custom_css = $("#overwrite_theme_custom_css_checkbox").is(':checked'); @@ -793,15 +810,21 @@ element.css("opacity", opacity); } - function select_channel(channel_id, animate_it) { + function select_channel(channel_id, animate_it, acknowledge_nsfw) { if (selected_channel != channel_id && guild_channels[channel_id] && guild_channels[channel_id].read) { + if (guild_channels[channel_id].channel.nsfw && !acknowledge_nsfw) { + $("#proceed_nsfw_btn").attr("channel_id", channel_id); + $("#proceed_nsfw_btn").attr("should_animate", animate_it ? 1 : 0); + $("#nsfwmodal").modal("open"); + return; + } if (animate_it) { $("#guild-btn").sideNav("show"); $("#channel-"+channel_id)[0].scrollIntoView({behavior: "smooth"}); flashElement($("#channel-"+channel_id)); setTimeout(function () { $("#guild-btn").sideNav("hide"); - select_channel(channel_id); + select_channel(channel_id, false, true); }, 1000); return; } diff --git a/webapp/titanembeds/templates/embed.html.j2 b/webapp/titanembeds/templates/embed.html.j2 index 8d8b60b..ea03f92 100644 --- a/webapp/titanembeds/templates/embed.html.j2 +++ b/webapp/titanembeds/templates/embed.html.j2 @@ -204,6 +204,17 @@ + +