Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/webview/js/generatedEs3.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function someVisibleMessage(top, bottom) {
function idFromMessage(element) {
var idStr = element.getAttribute('data-msg-id');

if (!idStr) {
if (idStr === null || idStr === undefined) {
throw new Error('Bad message element');
}

Expand Down Expand Up @@ -231,6 +231,7 @@ var sendScrollMessageIfListShort = function sendScrollMessageIfListShort() {

var scrollEventsDisabled = true;
var lastTouchEventTimestamp = 0;
var hasLongPressed = false;
var lastTouchPositionX = -1;
var lastTouchPositionY = -1;

Expand Down Expand Up @@ -421,6 +422,12 @@ var requireAttribute = function requireAttribute(e, name) {
documentBody.addEventListener('click', function (e) {
e.preventDefault();
lastTouchEventTimestamp = 0;

if (hasLongPressed) {
hasLongPressed = false;
return;
}

var target = e.target;

if (!(target instanceof Element)) {
Expand Down Expand Up @@ -495,10 +502,12 @@ var handleLongPress = function handleLongPress(target) {
}

lastTouchEventTimestamp = 0;
hasLongPressed = true;
sendMessage({
type: 'longPress',
target: target.matches('.header') ? 'header' : 'message',
messageId: getMessageIdFromNode(target)
target: target.matches('.header') ? 'header' : target.matches('a') ? 'link' : 'message',
messageId: getMessageIdFromNode(target),
href: target.matches('a') ? requireAttribute(target, 'href') : null
});
};

Expand All @@ -512,6 +521,7 @@ documentBody.addEventListener('touchstart', function (e) {
lastTouchPositionX = e.changedTouches[0].pageX;
lastTouchPositionY = e.changedTouches[0].pageY;
lastTouchEventTimestamp = Date.now();
hasLongPressed = false;
setTimeout(function () {
return handleLongPress(target);
}, 500);
Expand Down
13 changes: 12 additions & 1 deletion src/webview/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ const sendScrollMessageIfListShort = () => {
let scrollEventsDisabled = true;

let lastTouchEventTimestamp = 0;
let hasLongPressed = false;
let lastTouchPositionX = -1;
let lastTouchPositionY = -1;

Expand Down Expand Up @@ -558,6 +559,13 @@ documentBody.addEventListener('click', (e: MouseEvent) => {
e.preventDefault();
lastTouchEventTimestamp = 0;

/* Without a flag `hasLongPressed`, both the short press and the long
* press actions get triggered. See PR #3404 for more context. */
if (hasLongPressed) {
hasLongPressed = false;
return;
}

const { target } = e;

if (!(target instanceof Element)) {
Expand Down Expand Up @@ -650,11 +658,13 @@ const handleLongPress = (target: Element) => {
}

lastTouchEventTimestamp = 0;
hasLongPressed = true;

sendMessage({
type: 'longPress',
target: target.matches('.header') ? 'header' : 'message',
target: target.matches('.header') ? 'header' : target.matches('a') ? 'link' : 'message',
messageId: getMessageIdFromNode(target),
href: target.matches('a') ? requireAttribute(target, 'href') : null,
});
};

Expand All @@ -667,6 +677,7 @@ documentBody.addEventListener('touchstart', (e: TouchEvent) => {
lastTouchPositionX = e.changedTouches[0].pageX;
lastTouchPositionY = e.changedTouches[0].pageY;
lastTouchEventTimestamp = Date.now();
hasLongPressed = false;
setTimeout(() => handleLongPress(target), 500);
});

Expand Down
22 changes: 18 additions & 4 deletions src/webview/webViewEventHandlers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* @flow strict-local */
import { Clipboard } from 'react-native';
import { emojiReactionAdd, emojiReactionRemove, queueMarkAsRead } from '../api';
import config from '../config';
import type { Dispatch, GetText, Message, Narrow } from '../types';
import type { BackgroundData } from './MessageList';
import type { ShowActionSheetWithOptions } from '../message/messageActionSheet';
import { showToast } from '../utils/info';
import { isUrlAnImage } from '../utils/url';
import { logErrorRemotely } from '../utils/logging';
import { filterUnreadMessagesInRange } from '../utils/unread';
Expand Down Expand Up @@ -78,8 +80,9 @@ type MessageListEventUrl = {|

type MessageListEventLongPress = {|
type: 'longPress',
target: 'message' | 'header',
target: 'message' | 'header' | 'link',
messageId: number,
href: string | null,
|};

type MessageListEventDebug = {|
Expand Down Expand Up @@ -151,13 +154,24 @@ const handleImage = (props: Props, src: string, messageId: number) => {
}
};

const handleLongPress = (props: Props, _: GetText, isHeader: boolean, messageId: number) => {
const handleLongPress = (
props: Props,
_: GetText,
target: 'message' | 'header' | 'link',
messageId: number,
href: string | null,
) => {
if (href !== null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, but this revision is incomplete -- there's still the redundant distinction of link from message, appearing in several places in the code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, also the commit message still describes your v1 design:

    I have added
    another event to `MessageListEvent` which abstracts a long press on a
    url, and edited the long press listener on `js.js` a little bit.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I purposely left the distinction between link and message for the sake of readability of code. Do you think I should remove it?

Fixed the commit message (in WIP)! :)

Clipboard.setString(href);
showToast(_('Link copied to clipboard'));
return;
}
const message = props.messages.find(x => x.id === messageId);
if (!message) {
return;
}
const { dispatch, showActionSheetWithOptions, backgroundData, narrow } = props;
showActionSheet(isHeader, dispatch, showActionSheetWithOptions, _, {
showActionSheet(target === 'header', dispatch, showActionSheetWithOptions, _, {
backgroundData,
message,
narrow,
Expand Down Expand Up @@ -188,7 +202,7 @@ export const handleMessageListEvent = (props: Props, _: GetText, event: MessageL
break;

case 'longPress':
handleLongPress(props, _, event.target === 'header', event.messageId);
handleLongPress(props, _, event.target, event.messageId, event.href);
break;

case 'url':
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Reply",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Mute topic",
"Unmute topic": "Unmute topic",
"Mute stream": "Mute stream",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Отговори",
"Add a reaction": "Добави реакция",
"Copy to clipboard": "Копирай в клипборд",
"Link copied to clipboard": "Линкът е копиран в клипборда",
"Mute topic": "Заглуши тема",
"Unmute topic": "Не заглушавай тема",
"Mute stream": "Заглуши канал",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Respondre",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copiar al porta-retalls",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Silenciar tema",
"Unmute topic": "Unmute topic",
"Mute stream": "Silenciar canal",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Odpovědět",
"Add a reaction": "Přidat odpověď",
"Copy to clipboard": "Kopírovat do schránky",
"Link copied to clipboard": "Odkaz zkopírován do schránky",
"Mute topic": "Ztlumit téma",
"Unmute topic": "Zrušit ztlumení tématu",
"Mute stream": "Ztlumit kanál",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_da.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Reply",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Mute topic",
"Unmute topic": "Unmute topic",
"Mute stream": "Mute stream",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Antworten",
"Add a reaction": "Reaktion hinzufügen",
"Copy to clipboard": "In die Ablage kopieren",
"Link copied to clipboard": "Link in die Ablage kopiert",
"Mute topic": "Thema stummschalten",
"Unmute topic": "Stummschaltung aufheben",
"Mute stream": "Stream stummschalten",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Reply",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Mute topic",
"Unmute topic": "Unmute topic",
"Mute stream": "Mute stream",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Responder",
"Add a reaction": "Añadir una reacción",
"Copy to clipboard": "Copiar al portapapeles",
"Link copied to clipboard": "Enlace copiado al portapapeles",
"Mute topic": "Silenciar tema",
"Unmute topic": "No silenciar el tema",
"Mute stream": "Silenciar canal",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Reply",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Mute topic",
"Unmute topic": "Unmute topic",
"Mute stream": "Mute stream",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Vastaa",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Kopioi leikepöydälle",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Mykistä aihe",
"Unmute topic": "Poista aiheen mykistys",
"Mute stream": "Mykistä kanava",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Répondre",
"Add a reaction": "Ajouter une réaction",
"Copy to clipboard": "Copier dans le presse-papier",
"Link copied to clipboard": "Lien copié vers le presse-papier",
"Mute topic": "Rendre le sujet muet",
"Unmute topic": "Ne plus rendre le sujet muet",
"Mute stream": "Rendre le canal muet ",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_gl.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Responder",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copiar no portarretallos",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Silenciar este tema",
"Unmute topic": "Deixar de silenciar este tema",
"Mute stream": "Silenciar o fío",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "जवाब दें",
"Add a reaction": "एक प्रतिक्रिया जोड़ें",
"Copy to clipboard": "क्लिपबोर्ड पर कॉपी करें",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "विषय म्यूट करें",
"Unmute topic": "विषय अनम्यूट करें",
"Mute stream": " धारा म्यूट करें",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_hr.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Reply",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Mute topic",
"Unmute topic": "Unmute topic",
"Mute stream": "Mute stream",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Válasz",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Másolás vágólapra",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Téma némítása",
"Unmute topic": "Téma némítás feloldása",
"Mute stream": "Üzenetfolyam némítása",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_id_ID.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Balas",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Salin ke clipboard",
"Link copied to clipboard": "Tautan disalin ke clipboard",
"Mute topic": "Senyapkan topik",
"Unmute topic": "Nyalakan topik",
"Mute stream": "Senyapkan stream",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_it.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Rispondi",
"Add a reaction": "Aggiungi una reazione",
"Copy to clipboard": "Copia negli appunti",
"Link copied to clipboard": "Link copiato negli appunti",
"Mute topic": "Silenzia il topic",
"Unmute topic": "Riattiva audio dell'argomento",
"Mute stream": "Zittisci il canale",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "返信",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "クリップボードにコピー",
"Link copied to clipboard": "リンクをクリップボードにコピー",
"Mute topic": "トピックをミュート",
"Unmute topic": "トピックのミュートを解除",
"Mute stream": "ストリームをミュート",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "답장",
"Add a reaction": "반응 추가",
"Copy to clipboard": "클립보드에 복사하기",
"Link copied to clipboard": "링크가 클립보드에 복사되었습니다.",
"Mute topic": "주제 뮤트하기",
"Unmute topic": "주제 언뮤트하기",
"Mute stream": "스트림 뮤트하기",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_ml.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "മറുപടി",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Mute topic",
"Unmute topic": "Unmute topic",
"Mute stream": "Mute stream",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Antwoorden",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Kopiëren",
"Link copied to clipboard": "Link gekopieerd naar klembord",
"Mute topic": "Onderwerp dempen",
"Unmute topic": "Onderwerp aanzetten",
"Mute stream": "Kanaal dempen",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Odpowiedz",
"Add a reaction": "Dodaj reakcje",
"Copy to clipboard": "Kopiuj do schowka",
"Link copied to clipboard": "Link skopiowany do schowka",
"Mute topic": "Wycisz wątek",
"Unmute topic": "Przywróć powiadomienia w wątku",
"Mute stream": "Wycisz kanał",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Responder",
"Add a reaction": "Adicionar uma reação",
"Copy to clipboard": "Copiar para área de transferência",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Silenciar tópico",
"Unmute topic": "Cancelar o silenciamento do tópico",
"Mute stream": "Silenciar fluxo",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Răspunde",
"Add a reaction": "Reacționează",
"Copy to clipboard": "Copiere în clipboard",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Dezactivează sunetele pentru subiect",
"Unmute topic": "Activează sunetele pentru subiect",
"Mute stream": "Dezactivează sunetele pentru flux",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Ответить",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Скопировать в буфер обмена",
"Link copied to clipboard": "Ссылка скопирована в буфер обмена",
"Mute topic": "Заглушить тему",
"Unmute topic": "Включить тему",
"Mute stream": "Заглушить канал",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_sr.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Reply",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Mute topic",
"Unmute topic": "Unmute topic",
"Mute stream": "Mute stream",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Reply",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Mute topic",
"Unmute topic": "Unmute topic",
"Mute stream": "Mute stream",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_ta.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "மறுமொழி",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "நகல் நினைவியை நகலெடுக்கவும்",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "தலைப்பை அமைதியாக்கு",
"Unmute topic": "தலைப்பு தடையை நீக்கு",
"Mute stream": "தொடரை அமைதியாக்கு",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Yanıtla",
"Add a reaction": "Tepki ekle",
"Copy to clipboard": "Panoya kopyala",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Konuyu susturun",
"Unmute topic": "Konunun sesini açın",
"Mute stream": "Kanalı sessize al",
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Відповісти",
"Add a reaction": "Додати реакцію",
"Copy to clipboard": "Копіювати в буфер обміну",
"Link copied to clipboard": "Link copied to clipboard",
"Mute topic": "Заглушити тему",
"Unmute topic": "Увімкнути сповіщення теми",
"Mute stream": "Заглушити канал",
Expand Down
Loading