From 7728a4e70343b9af9c1d63255ac0319849cb84f3 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 28 Jul 2021 17:09:53 +0300 Subject: [PATCH] Message Context Menu: Fix copying message link on iOS (#1337) --- src/api/gramjs/methods/index.ts | 2 +- src/api/gramjs/methods/messages.ts | 9 --------- .../middle/message/ContextMenuContainer.tsx | 15 ++++++--------- src/components/middle/message/Message.tsx | 5 +++++ src/global/types.ts | 2 +- src/lib/gramjs/tl/apiTl.js | 1 - src/lib/gramjs/tl/static/api.reduced.tl | 1 - src/modules/actions/api/messages.ts | 19 ------------------- 8 files changed, 13 insertions(+), 41 deletions(-) diff --git a/src/api/gramjs/methods/index.ts b/src/api/gramjs/methods/index.ts index 31ead19b..c56ee47c 100644 --- a/src/api/gramjs/methods/index.ts +++ b/src/api/gramjs/methods/index.ts @@ -22,7 +22,7 @@ export { markMessageListRead, markMessagesRead, requestThreadInfoUpdate, searchMessagesLocal, searchMessagesGlobal, fetchWebPagePreview, editMessage, forwardMessages, loadPollOptionResults, sendPollVote, findFirstMessageIdAfterDate, fetchPinnedMessages, fetchScheduledHistory, sendScheduledMessages, rescheduleMessage, deleteScheduledMessages, - fetchMessageLink, reportMessages, + reportMessages, } from './messages'; export { diff --git a/src/api/gramjs/methods/messages.ts b/src/api/gramjs/methods/messages.ts index 80954347..784e4ac5 100644 --- a/src/api/gramjs/methods/messages.ts +++ b/src/api/gramjs/methods/messages.ts @@ -1079,15 +1079,6 @@ export async function sendScheduledMessages({ chat, ids }: { chat: ApiChat; ids: }), true); } -export function fetchMessageLink({ chat, message }: { chat: ApiChat; message: ApiMessage }) { - return invokeRequest(new GramJs.channels.ExportMessageLink({ - id: message.id, - channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel, - ...(message.isInAlbum && { grouped: true }), - ...(message.threadInfo && message.threadInfo.topMessageId !== message.id && { thread: true }), - })); -} - function updateLocalDb(result: ( GramJs.messages.MessagesSlice | GramJs.messages.Messages | GramJs.messages.ChannelMessages | GramJs.messages.DiscussionMessage diff --git a/src/components/middle/message/ContextMenuContainer.tsx b/src/components/middle/message/ContextMenuContainer.tsx index 7817ac1e..33ebc968 100644 --- a/src/components/middle/message/ContextMenuContainer.tsx +++ b/src/components/middle/message/ContextMenuContainer.tsx @@ -18,9 +18,11 @@ import PinMessageModal from '../../common/PinMessageModal'; import MessageContextMenu from './MessageContextMenu'; import CalendarModal from '../../common/CalendarModal'; import { getDayStartAt } from '../../../util/dateFormat'; +import { copyTextToClipboard } from '../../../util/clipboard'; export type OwnProps = { isOpen: boolean; + chatUsername?: string; message: ApiMessage; album?: IAlbum; anchor: IAnchorPosition; @@ -49,13 +51,13 @@ type StateProps = { type DispatchProps = Pick; const ContextMenuContainer: FC = ({ isOpen, messageListType, + chatUsername, message, album, anchor, @@ -85,7 +87,6 @@ const ContextMenuContainer: FC = ({ toggleMessageSelection, sendScheduledMessages, rescheduleMessage, - loadMessageLink, }) => { const { transitionClassNames } = useShowTransition(isOpen, onCloseAnimationEnd, undefined, false); const [isMenuOpen, setIsMenuOpen] = useState(true); @@ -201,12 +202,9 @@ const ContextMenuContainer: FC = ({ }, [message.chatId, message.id, rescheduleMessage]); const handleCopyLink = useCallback(() => { - loadMessageLink({ - messageId: message.id, - chatId: message.chatId, - }); + copyTextToClipboard(`https://t.me/${chatUsername || `c/${Math.abs(message.chatId)}`}/${message.id}`); closeMenu(); - }, [closeMenu, loadMessageLink, message.chatId, message.id]); + }, [chatUsername, closeMenu, message.chatId, message.id]); useEffect(() => { disableScrolling(); @@ -340,6 +338,5 @@ export default memo(withGlobal( 'toggleMessageSelection', 'sendScheduledMessages', 'rescheduleMessage', - 'loadMessageLink', ]), )(ContextMenuContainer)); diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index 05c551c5..e5d17b0a 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -124,6 +124,7 @@ type OwnProps = { type StateProps = { theme: ISettings['theme']; forceSenderName?: boolean; + chatUsername?: string; sender?: ApiUser | ApiChat; originSender?: ApiUser | ApiChat; botSender?: ApiUser; @@ -173,6 +174,7 @@ const ANDROID_KEYBOARD_HIDE_DELAY_MS = 350; const Message: FC = ({ message, + chatUsername, observeIntersectionForBottom, observeIntersectionForMedia, observeIntersectionForAnimatedStickers, @@ -869,6 +871,7 @@ const Message: FC = ({ anchor={contextMenuPosition} message={message} album={album} + chatUsername={chatUsername} messageListType={messageListType} onClose={handleContextMenuClose} onCloseAnimationEnd={handleContextMenuHide} @@ -915,6 +918,7 @@ export default memo(withGlobal( const chat = selectChat(global, chatId); const isChatWithSelf = selectIsChatWithSelf(global, chatId); const isChannel = chat && isChatChannel(chat); + const chatUsername = chat && chat.username; const forceSenderName = !isChatWithSelf && isAnonymousOwnMessage(message); const canShowSender = withSenderName || withAvatar || forceSenderName; @@ -955,6 +959,7 @@ export default memo(withGlobal( return { theme: selectTheme(global), + chatUsername, forceSenderName, sender, originSender, diff --git a/src/global/types.ts b/src/global/types.ts index 4c257f08..33ecaabd 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -446,7 +446,7 @@ export type ActionTypes = ( 'editMessage' | 'deleteHistory' | 'enterMessageSelectMode' | 'toggleMessageSelection' | 'exitMessageSelectMode' | 'openTelegramLink' | 'openChatByUsername' | 'requestThreadInfoUpdate' | 'setScrollOffset' | 'unpinAllMessages' | 'setReplyingToId' | 'setEditingId' | 'editLastMessage' | 'saveDraft' | 'clearDraft' | 'loadPinnedMessages' | - 'loadMessageLink' | 'toggleMessageWebPage' | 'replyToNextMessage' | 'deleteChatUser' | 'deleteChat' | + 'toggleMessageWebPage' | 'replyToNextMessage' | 'deleteChatUser' | 'deleteChat' | 'reportMessages' | 'focusNextReply' | // scheduled messages 'loadScheduledHistory' | 'sendScheduledMessages' | 'rescheduleMessage' | 'deleteScheduledMessages' | diff --git a/src/lib/gramjs/tl/apiTl.js b/src/lib/gramjs/tl/apiTl.js index 65a7c2c1..38a3f1d2 100644 --- a/src/lib/gramjs/tl/apiTl.js +++ b/src/lib/gramjs/tl/apiTl.js @@ -1071,7 +1071,6 @@ channels.joinChannel#24b524c5 channel:InputChannel = Updates; channels.leaveChannel#f836aa95 channel:InputChannel = Updates; channels.inviteToChannel#199f3a6c channel:InputChannel users:Vector = Updates; channels.deleteChannel#c0111fe3 channel:InputChannel = Updates; -channels.exportMessageLink#e63fadeb flags:# grouped:flags.0?true thread:flags.1?true channel:InputChannel id:int = ExportedMessageLink; channels.toggleSignatures#1f69b606 channel:InputChannel enabled:Bool = Updates; channels.editBanned#96e6cd81 channel:InputChannel participant:InputPeer banned_rights:ChatBannedRights = Updates; channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector = Bool; diff --git a/src/lib/gramjs/tl/static/api.reduced.tl b/src/lib/gramjs/tl/static/api.reduced.tl index 318c41f6..f74fdda7 100644 --- a/src/lib/gramjs/tl/static/api.reduced.tl +++ b/src/lib/gramjs/tl/static/api.reduced.tl @@ -1071,7 +1071,6 @@ channels.joinChannel#24b524c5 channel:InputChannel = Updates; channels.leaveChannel#f836aa95 channel:InputChannel = Updates; channels.inviteToChannel#199f3a6c channel:InputChannel users:Vector = Updates; channels.deleteChannel#c0111fe3 channel:InputChannel = Updates; -channels.exportMessageLink#e63fadeb flags:# grouped:flags.0?true thread:flags.1?true channel:InputChannel id:int = ExportedMessageLink; channels.toggleSignatures#1f69b606 channel:InputChannel enabled:Bool = Updates; channels.editBanned#96e6cd81 channel:InputChannel participant:InputPeer banned_rights:ChatBannedRights = Updates; channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector = Bool; diff --git a/src/modules/actions/api/messages.ts b/src/modules/actions/api/messages.ts index d45de56a..961650f1 100644 --- a/src/modules/actions/api/messages.ts +++ b/src/modules/actions/api/messages.ts @@ -52,7 +52,6 @@ import { selectNoWebPage, } from '../../selectors'; import { rafPromise, throttle } from '../../../util/schedulers'; -import { copyTextToClipboard } from '../../../util/clipboard'; import { IS_IOS } from '../../../util/environment'; const uploadProgressCallbacks = new Map(); @@ -858,24 +857,6 @@ addReducer('loadPinnedMessages', (global, actions, payload) => { void loadPinnedMessages(chat); }); -addReducer('loadMessageLink', (global, actions, payload) => { - const { messageId, chatId } = payload; - const chat = selectChat(global, chatId); - const message = selectChatMessage(global, chatId, messageId); - - if (!chat || !message) { - return; - } - - (async () => { - const result = await callApi('fetchMessageLink', { chat, message }); - - if (result) { - copyTextToClipboard(result.link); - } - })(); -}); - async function loadPinnedMessages(chat: ApiChat) { const result = await callApi('fetchPinnedMessages', { chat }); if (!result) {