From efe1ace42a4719920609a64356a0e2cd79b6b36c Mon Sep 17 00:00:00 2001 From: Bastard Operator Date: Mon, 28 Dec 2020 15:01:15 +0100 Subject: [PATCH] Emoji feature done! (well enough) + some fixes --- src/routes/_actions/emoji.js | 18 ++++++---- .../dialog/components/EmojiDialog.html | 2 +- src/routes/_database/timelines/insertion.js | 7 ---- src/routes/_layout.html | 25 +++++++++++-- src/scss/themes/ozark.scss | 6 ++++ static/fedilove-no-react.js | 35 ++++++------------- 6 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/routes/_actions/emoji.js b/src/routes/_actions/emoji.js index 373507e1..e27cf332 100644 --- a/src/routes/_actions/emoji.js +++ b/src/routes/_actions/emoji.js @@ -32,11 +32,15 @@ export async function setupCustomEmojiForInstance (instanceName) { export function insertEmoji (realm, emoji) { const emojiText = emoji.unicode || `:${emoji.name}:` - const { composeSelectionStart } = store.get() - const idx = composeSelectionStart || 0 - const oldText = store.getComposeData(realm, 'text') || '' - const pre = oldText.substring(0, idx) - const post = oldText.substring(idx) - const newText = `${pre}${emojiText} ${post}` - store.setComposeData(realm, { text: newText }) + if (window.location.pathname.startsWith('/statuses/')) { + window.fediloveEvents.onEmojiPicked(emojiText); + } else { + const { composeSelectionStart } = store.get() + const idx = composeSelectionStart || 0 + const oldText = store.getComposeData(realm, 'text') || '' + const pre = oldText.substring(0, idx) + const post = oldText.substring(idx) + const newText = `${pre}${emojiText} ${post}` + store.setComposeData(realm, { text: newText }) + } } diff --git a/src/routes/_components/dialog/components/EmojiDialog.html b/src/routes/_components/dialog/components/EmojiDialog.html index c2b8aa7f..de3b3737 100644 --- a/src/routes/_components/dialog/components/EmojiDialog.html +++ b/src/routes/_components/dialog/components/EmojiDialog.html @@ -10,7 +10,7 @@ ref:picker locale={emojiPickerLocale} data-source={emojiPickerDataSource} - class={darkMode ? 'dark' : 'light'} + class="light" on:emoji-click="onEmojiSelected(event)" on:keydown="onPickerKeydown(event)" > diff --git a/src/routes/_database/timelines/insertion.js b/src/routes/_database/timelines/insertion.js index bba9f6d0..69fa42ed 100644 --- a/src/routes/_database/timelines/insertion.js +++ b/src/routes/_database/timelines/insertion.js @@ -118,13 +118,6 @@ export async function insertTimelineItems (instanceName, timeline, timelineItems return insertTimelineNotifications(instanceName, timeline, timelineItems) } else if (timeline.startsWith('status/') || timeline.startsWith('/statuses/')) { const statusId = timeline.split('/').slice(-1)[0] - var _this = setInterval(function() { - const elem = $('div.the-list > div.list-item > article.status-in-own-thread'); - if ( elem.length > 0 && elem.is(':visible') ) { - clearInterval(_this); - setTimeout(function() { window.fediloveEvents.onMessagesLoaded(); }, 250); - } - }, 100); return insertStatusThread(instanceName, statusId, timelineItems) } else { return insertTimelineStatuses(instanceName, timeline, timelineItems) diff --git a/src/routes/_layout.html b/src/routes/_layout.html index 96d477ee..13ebc80a 100644 --- a/src/routes/_layout.html +++ b/src/routes/_layout.html @@ -3,7 +3,14 @@
- + @@ -35,11 +42,14 @@ diff --git a/src/scss/themes/ozark.scss b/src/scss/themes/ozark.scss index 14b454f7..743be740 100644 --- a/src/scss/themes/ozark.scss +++ b/src/scss/themes/ozark.scss @@ -119,6 +119,12 @@ div.main-content.chat { display: none; } } +div.main-content.direct { + div.timeline-slot-reveal-container { + visibility: collapse; + display: none; + } +} div.timeline > div.the-list { div.list-item { diff --git a/static/fedilove-no-react.js b/static/fedilove-no-react.js index 558672af..446016db 100644 --- a/static/fedilove-no-react.js +++ b/static/fedilove-no-react.js @@ -96,12 +96,6 @@ var fediloveUI = { clearInterval(_this); } }, 150); - }, - paintToolbarCompose: function() { - if (fediloveData.toolbarElement != null) { - console.log(fediloveData.toolbarElement); - $('#chat-compose-global #tools-placeholder').html(fediloveData.toolbarElement); - } } }; @@ -119,26 +113,17 @@ var fediloveApi = { return parts[parts.length-1]; } }; +var fediloveReact = {}; var fediloveFunctions = {}; var fediloveData = { - currentChat: null, - toolbarFilled: false, - toolbarElement: null + currentChat: null }; var fediloveEvents = { - onMessagesLoaded: function () { - if (fediloveData.toolbarFilled) return true; - - fediloveData.toolbarFilled = true; - - // click on the reply button on the highlighted message (only once, save state) - $('div.the-list > div.list-item > article.status-in-own-thread > div.status-toolbar > button.status-toolbar-reply-button').click(); - - // load the highlighted message compose tools on our custom compose bar to re-use functionality - setTimeout(function() { - fediloveData.toolbarElement = $('div.the-list > div.list-item > article.status-in-own-thread > div.status-article-compose-box div.compose-box-toolbar').clone(); - fediloveUI.paintToolbarCompose(); - }, 500); + onEmojiPicked: function(emoji) { + var $txt = $("#chat-compose-global textarea"); + var caretPos = $txt[0].selectionStart; + var textAreaTxt = $txt.val(); + $txt.val(textAreaTxt.substring(0, caretPos) + emoji + textAreaTxt.substring(caretPos)); }, onNewNotification: function (dataItems) { if (window.location.pathname.startsWith('/statuses/')) { @@ -162,7 +147,6 @@ function fedilove_customization() { { $('div.main-content').addClass('chat'); document.querySelector('#chat-compose-global').style = ''; - fediloveUI.paintToolbarCompose(); // add some animations var style = document.createElement('style'); @@ -214,10 +198,11 @@ function fedilove_customization() { makeMessageUIModifications(localStorage.store_userAccountId); } } + else if (window.location.pathname == '/direct') { + $('div.main-content').addClass('direct'); + } else if (window.location.pathname.startsWith('/notifications/mentions')) { $('nav.notification-filters li > a.focus-fix').attr('onclick', 'return false;'); - } else { - fediloveData.toolbarFilled = false; } }
+ +