diff --git a/layouts/header/script.js b/layouts/header/script.js index d83f8a45..c5cdce34 100644 --- a/layouts/header/script.js +++ b/layouts/header/script.js @@ -791,9 +791,10 @@ let userDataFunction = async user => { if(inboxData) { let conversations = Array.isArray(inboxData.conversations) ? inboxData.conversations : Object.values(inboxData.conversations); let realConvo = conversations.find(c => c.id_str === lastConvo.id_str); - if(+lastConvo.max_entry_id >= +realConvo.last_read_event_id) { - API.inbox.markRead(lastConvo.max_entry_id); - realConvo.last_read_event_id = lastConvo.max_entry_id; + let lastEventId = lastConvo.conversations[lastConvo.conversation_id].sort_event_id; //reactions dont count towards max_entry_id, but they do towards sort_event_id so that conversations appear above others when theres a new reaction + if(+lastEventId >= +realConvo.last_read_event_id) { + API.inbox.markRead(lastEventId); + realConvo.last_read_event_id = lastEventId; } } window.history.pushState(null, document.title, window.location.href) @@ -1048,11 +1049,35 @@ let userDataFunction = async user => { messageElement.classList.add('inbox-message-unread'); isUnread = true; } + let messageEntry = {} + if(messageUsers.length === 1) { //regular user + if (messageUsers[0].default_profile_image && vars.useOldDefaultProfileImage) { + messageEntry.icon = chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(messageUsers[0].id_str) % 7}_normal.png`); + } else { + messageEntry.icon = messageUsers[0].profile_image_url_https; + } + + messageEntry.name = escapeHTML(messageUsers[0].name); + messageEntry.screen_name = '@' + messageUsers[0].screen_name; + } else if (messageUsers.length > 1) { //groups + messageEntry.icon = c.avatar_image_https || chrome.runtime.getURL('/images/group.jpg'); + messageEntry.name = c.name ? escapeHTML(c.name) : messageUsers.map(i => escapeHTML(i.name)).join(', ').slice(0, 128); + messageEntry.screen_name = ''; + } else if (messageUsers.length === 0) { //weird twitter bug, if you dm yourself (why?) it counts as no messageUsers + if (user.default_profile_image && vars.useOldDefaultProfileImage) { + messageEntry.icon = chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(user.id_str) % 7}_normal.png`); + } else { + messageEntry.icon = user.profile_image_url_https; + } + + messageEntry.name = user.name; + messageEntry.screen_name = '@' + user.screen_name; + } messageElement.innerHTML = /*html*/` - +
- ${messageUsers.length === 1 ? escapeHTML(messageUsers[0].name) : (c.name ? escapeHTML(c.name) : messageUsers.map(i => escapeHTML(i.name)).join(', ').slice(0, 128))} - ${messageUsers.length === 1 ? "@"+messageUsers[0].screen_name : ''} + ${messageEntry.name} + ${messageEntry.screen_name} ${timeElapsed(new Date(+lastMessage.time))}
${lastMessage.reason ? 'Accepted conversation' : lastMessage.message_data.text.startsWith('dmservice_reaction_') ? `${lastMessage.message_data.sender_id === user.id_str ? 'You reacted to message' : `${escapeHTML(lastMessageUser.name)} reacted to message`}` : escapeHTML(lastMessage.message_data.text)} @@ -1071,9 +1096,9 @@ let userDataFunction = async user => { modal.querySelector('.name-top').hidden = false; modal.querySelector('.inbox').hidden = true; modal.querySelector('.new-message-box').hidden = true; - messageHeaderName.innerText = messageUsers.length === 1 ? messageUsers[0].name : (c.name || messageUsers.map(i => i.name).join(', ').slice(0, 80)); - messageHeaderAvatar.src = messageUsers.length === 1 ? `${(messageUsers[0].default_profile_image && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(messageUsers[0].id_str) % 7}_normal.png`): messageUsers[0].profile_image_url_https}` : (c.avatar_image_https || chrome.runtime.getURL(`/images/group.jpg`)); - if(messageUsers.length === 1) messageHeaderLink.href = `https://twitter.com/${messageUsers[0].screen_name}`; + messageHeaderName.innerText = messageEntry.name; + messageHeaderAvatar.src = messageEntry.icon; + if(messageUsers.length <= 1) messageHeaderLink.href = `https://twitter.com/${messageEntry.screen_name}`; setTimeout(() => { modal.querySelector(".message-new-input").focus(); if(tweetUrlToShareInDMs) modal.querySelector(".message-new-input").value = tweetUrlToShareInDMs; @@ -1222,7 +1247,7 @@ let userDataFunction = async user => { let userElement = document.createElement('div'); userElement.classList.add('new-message-user'); userElement.innerHTML = ` - +
${escapeHTML(u.name)} @${u.screen_name} @@ -1239,7 +1264,7 @@ let userDataFunction = async user => { modal.querySelector('.inbox').hidden = true; modal.querySelector('.new-message-box').hidden = true; messageHeaderName.innerText = u.name; - messageHeaderAvatar.src = `${(u.default_profile_image && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(u.id_str) % 7}_normal.png`): u.profile_image_url_https}`; + messageHeaderAvatar.src = `${(u.profile_image_url_https.includes('default_profile_images') && vars.useOldDefaultProfileImage) ? chrome.runtime.getURL(`images/default_profile_images/default_profile_${Number(u.id_str) % 7}_normal.png`): u.profile_image_url_https}`; messageHeaderLink.href = `https://twitter.com/${u.screen_name}`; setTimeout(() => { modal.querySelector(".message-new-input").focus(); @@ -1636,7 +1661,7 @@ let userDataFunction = async user => { userElement.className = 'search-result-item'; if(index === 0) userElement.classList.add('search-result-item-active'); userElement.innerHTML = ` - + ${escapeHTML(user.name)} @${user.screen_name} `; @@ -1989,7 +2014,7 @@ let userDataFunction = async user => { userElement.href = `/${user.screen_name}`; userElement.className = 'search-result-item'; userElement.innerHTML = ` - + ${user.name} @${user.screen_name} `; diff --git a/scripts/injection.js b/scripts/injection.js index ca209f17..cc62f96f 100644 --- a/scripts/injection.js +++ b/scripts/injection.js @@ -122,12 +122,15 @@ if(realPath === '/intent/follow') { let screen_name = location.search.split('screen_name=')[1].split('&')[0]; location.replace(`/${screen_name}`); } -if (!hrefUrl.includes('newtwitter=true') && +if ( + !hrefUrl.includes('newtwitter=true') && ( realPath.startsWith('/i/flow/') || realPath.startsWith('/i/premium_sign_up/') || realPath.startsWith('/i/events/') || realPath.startsWith('/i/spaces/') || + realPath.startsWith('/i/oauth2') || + realPath.startsWith('/account') || realPath.startsWith('/settings') || /^\/[A-z-0-9-_]{1,15}\/status\/\d{5,32}\/analytics$/.test(realPath) )