|
1 | | -import type { FC } from '../../../lib/teact/teact'; |
2 | 1 | import { |
3 | 2 | memo, useEffect, useMemo, useState, |
4 | 3 | } from '../../../lib/teact/teact'; |
@@ -33,6 +32,7 @@ import { |
33 | 32 | areReactionsEmpty, |
34 | 33 | getCanPostInChat, |
35 | 34 | getIsDownloading, |
| 35 | + getMessageAudio, |
36 | 36 | getMessageVideo, |
37 | 37 | getUserFullName, |
38 | 38 | hasMessageTtl, |
@@ -172,12 +172,14 @@ type StateProps = { |
172 | 172 | savedDialogId?: string; |
173 | 173 | noForwardsMyEnabled?: boolean; |
174 | 174 | noForwardsPeerEnabled?: boolean; |
| 175 | + savedMusicById?: Record<string, true>; |
| 176 | + isSavedMusicLoading?: boolean; |
175 | 177 | }; |
176 | 178 |
|
177 | 179 | const selection = window.getSelection(); |
178 | 180 | const UNQUOTABLE_OFFSET = -1; |
179 | 181 |
|
180 | | -const ContextMenuContainer: FC<OwnProps & StateProps> = ({ |
| 182 | +const ContextMenuContainer = ({ |
181 | 183 | threadId, |
182 | 184 | availableReactions, |
183 | 185 | topReactions, |
@@ -247,9 +249,11 @@ const ContextMenuContainer: FC<OwnProps & StateProps> = ({ |
247 | 249 | savedDialogId, |
248 | 250 | noForwardsMyEnabled, |
249 | 251 | noForwardsPeerEnabled, |
| 252 | + savedMusicById, |
| 253 | + isSavedMusicLoading, |
250 | 254 | onClose, |
251 | 255 | onCloseAnimationEnd, |
252 | | -}) => { |
| 256 | +}: OwnProps & StateProps) => { |
253 | 257 | const { |
254 | 258 | openThread, |
255 | 259 | updateDraftReplyInfo, |
@@ -291,6 +295,8 @@ const ContextMenuContainer: FC<OwnProps & StateProps> = ({ |
291 | 295 | showNotification, |
292 | 296 | setSettingOption, |
293 | 297 | loadRichMessage, |
| 298 | + loadSavedMusicIds, |
| 299 | + toggleMusicInProfile, |
294 | 300 | } = getActions(); |
295 | 301 |
|
296 | 302 | const oldLang = useOldLang(); |
@@ -319,6 +325,17 @@ const ContextMenuContainer: FC<OwnProps & StateProps> = ({ |
319 | 325 | // `undefined` indicates that emoji are present and loading |
320 | 326 | const hasCustomEmoji = !message.isEphemeral |
321 | 327 | && (customEmojiSetsInfo === undefined || Boolean(customEmojiSetsInfo.length)); |
| 328 | + const audio = getMessageAudio(message); |
| 329 | + const isLocalMessage = isMessageLocal(message); |
| 330 | + const canManageMusicInProfile = Boolean(audio && !isLocalMessage); |
| 331 | + const isMusicProfileStatusLoaded = Boolean(savedMusicById); |
| 332 | + const isMusicSaved = Boolean(audio && savedMusicById?.[audio.id]); |
| 333 | + |
| 334 | + useEffect(() => { |
| 335 | + if (isOpen && audio && !isLocalMessage && !savedMusicById && !isSavedMusicLoading) { |
| 336 | + loadSavedMusicIds(); |
| 337 | + } |
| 338 | + }, [audio, isLocalMessage, isOpen, isSavedMusicLoading, loadSavedMusicIds, savedMusicById]); |
322 | 339 |
|
323 | 340 | useEffect(() => { |
324 | 341 | if (canShowSeenBy && isOpen) { |
@@ -661,6 +678,11 @@ const ContextMenuContainer: FC<OwnProps & StateProps> = ({ |
661 | 678 | closeMenu(); |
662 | 679 | }); |
663 | 680 |
|
| 681 | + const handleToggleMusicInProfile = useLastCallback(() => { |
| 682 | + toggleMusicInProfile({ audio: audio! }); |
| 683 | + closeMenu(); |
| 684 | + }); |
| 685 | + |
664 | 686 | const handleToggleReaction = useLastCallback((reaction: ApiReaction) => { |
665 | 687 | if (isInSavedMessages && !isCurrentUserPremium) { |
666 | 688 | openPremiumModal({ |
@@ -791,6 +813,10 @@ const ContextMenuContainer: FC<OwnProps & StateProps> = ({ |
791 | 813 | canSelect={canSelect} |
792 | 814 | canDownload={canDownload} |
793 | 815 | canSaveGif={canSaveGif} |
| 816 | + canManageMusicInProfile={canManageMusicInProfile} |
| 817 | + isMusicProfileStatusLoaded={isMusicProfileStatusLoaded} |
| 818 | + isMusicProfileActionLoading={isSavedMusicLoading} |
| 819 | + isMusicSaved={isMusicSaved} |
794 | 820 | canRevote={canRevote} |
795 | 821 | canClosePoll={canClosePoll} |
796 | 822 | canShowSeenBy={canShowSeenBy} |
@@ -830,6 +856,7 @@ const ContextMenuContainer: FC<OwnProps & StateProps> = ({ |
830 | 856 | onCopyNumber={handleCopyNumber} |
831 | 857 | onDownload={handleDownloadClick} |
832 | 858 | onSaveGif={handleSaveGif} |
| 859 | + onToggleMusicInProfile={handleToggleMusicInProfile} |
833 | 860 | onCancelVote={handleCancelVote} |
834 | 861 | onClosePoll={openClosePollDialog} |
835 | 862 | onShowSeenBy={handleOpenSeenByModal} |
@@ -1058,6 +1085,8 @@ export default memo(withGlobal<OwnProps>( |
1058 | 1085 | webPage, |
1059 | 1086 | noForwardsMyEnabled: userFullInfo?.noForwardsMyEnabled, |
1060 | 1087 | noForwardsPeerEnabled: userFullInfo?.noForwardsPeerEnabled, |
| 1088 | + savedMusicById: global.users.savedMusicById, |
| 1089 | + isSavedMusicLoading: global.users.isSavedMusicLoading, |
1061 | 1090 | }; |
1062 | 1091 | }, |
1063 | 1092 | )(ContextMenuContainer)); |
0 commit comments