2019-05-10 17:09:07 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { FlatList, Text, View } from 'react-native';
|
2019-05-10 17:09:07 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2021-11-16 16:10:49 +00:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
2021-12-03 19:27:57 +00:00
|
|
|
import { CompositeNavigationProp, RouteProp } from '@react-navigation/core';
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-12-03 19:27:57 +00:00
|
|
|
import { MasterDetailInsideStackParamList } from '../../stacks/MasterDetailStack/types';
|
2020-05-08 17:07:58 +00:00
|
|
|
import Message from '../../containers/message';
|
2019-12-04 16:39:53 +00:00
|
|
|
import ActivityIndicator from '../../containers/ActivityIndicator';
|
2019-05-10 17:09:07 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import StatusBar from '../../containers/StatusBar';
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
import getFileUrlAndTypeFromMessage from './getFileUrlAndTypeFromMessage';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, withTheme } from '../../theme';
|
2020-02-11 14:09:14 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
2020-06-15 19:35:45 +00:00
|
|
|
import { withActionSheet } from '../../containers/ActionSheet';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2021-05-26 17:24:54 +00:00
|
|
|
import getThreadName from '../../lib/methods/getThreadName';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2021-12-03 19:27:57 +00:00
|
|
|
import { ChatsStackParamList } from '../../stacks/types';
|
2022-04-01 21:52:38 +00:00
|
|
|
import { IRoomInfoParam } from '../SearchMessagesView';
|
2022-05-11 02:22:17 +00:00
|
|
|
import {
|
|
|
|
IApplicationState,
|
|
|
|
TMessageModel,
|
|
|
|
ISubscription,
|
|
|
|
SubscriptionType,
|
|
|
|
IAttachment,
|
|
|
|
IMessage,
|
|
|
|
TAnyMessageModel,
|
2022-10-21 18:27:55 +00:00
|
|
|
IUrl,
|
|
|
|
TGetCustomEmoji,
|
|
|
|
ICustomEmoji
|
2022-05-11 02:22:17 +00:00
|
|
|
} from '../../definitions';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../../lib/services';
|
2023-06-29 21:10:49 +00:00
|
|
|
import { TNavigation } from '../../stacks/stackType';
|
feat: new audio player (#5160)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* first commit
* fix togglePlayPause
* separate audio to a folder inside components and minor tweak attachment
* created the slider with text
* play/pause button, currentTime equal the sound, can change the slider and reflect to the sound
* play/pause, track is working and onEnd
* update the icons with play-shaped-filled, pause-shape-filled, loading
* start the tweaks on layout
* can play multiple audios, pausing the previous to execute the new one
* loading animated
* added the audio rate
* layout fixed
* removed the sound manipulation from Slider to manipulate only in the index
* fix time margin horizontal
* fix play 2 audios and play/pause properly
* change the way we treat the audio
* remove audio copy
* minor tweak
* fix rate state
* remove the PAUSE_AUDIO
* fix unloadAll, add hit slop to slider, show the duration on the first render
* refactor colors to be the same as figmas name
* change the class' name and add the method pauseCurrentAudio
* pause audio when unmount a RoomView and unloadAll when focusing at RoomsListView
* pause audio when entering a thread
* fix where call the pauseCurrentAudio
* moved the player from messageAudio to audioPlayer
* refactor audio component
* remove loading
* update snapshot
* fix colors name
* pauseAudio when roomview is blur
* moved audio from message/component/audio to message/Audio
* add navigation focus to AudioPlayer component and fix the jest
* add the { androidImplementation: 'MediaPlayer' }
* fix action sheet swipe 02-room
* fix action sheet swipe 05-threads
* tweak touchable
* remove react.memo from playbutton
* hitSlop
* speed playback from array
* textinputprops
* tweak at names
* minor tweak at onEnd
* minor tweak at names
* update styles
* thumb seek size
* change marginBottom
* add the clamp, adjust the thumb position, remove the necessity of OnEndGestureHandler
* change the utils to constants
* change to audioState
* fix the seek for android
* TDownloadState
* speed array
* pause audio from messagesView when open the files
* update test
* minor tweak
* change the time after ony one click, fixes the thumb to move sync with the click
* Fix seek
* minor tweak Sound to Audio.Sound
* name of Icon
* enable PlaybackSpeed only when playing the audio
* playbackSpeed to mmkv
* mock implementation
* create native button
* minor tweak
* minor tweaks
* playbackSpeed after loadAudio
* avoid show the error when try to setRate without audio
* add messageID to differ audios inside a quote/forward from original one
* unloadRoomAudios instead of unloadAllAudios inside the roomsListView
* minor tweak
---------
Co-authored-by: Diego Mello <diegolmello@gmail.com>
Co-authored-by: Gleidson Daniel Silva <gleidson10daniel@hotmail.com>
2023-11-20 14:13:15 +00:00
|
|
|
import audioPlayer from '../../lib/methods/audioPlayer';
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-11-16 16:10:49 +00:00
|
|
|
interface IMessagesViewProps {
|
|
|
|
user: {
|
|
|
|
id: string;
|
2022-01-17 16:10:39 +00:00
|
|
|
username: string;
|
|
|
|
token: string;
|
2021-11-16 16:10:49 +00:00
|
|
|
};
|
|
|
|
baseUrl: string;
|
2021-12-03 19:27:57 +00:00
|
|
|
navigation: CompositeNavigationProp<
|
|
|
|
StackNavigationProp<ChatsStackParamList, 'MessagesView'>,
|
2023-06-29 21:10:49 +00:00
|
|
|
StackNavigationProp<MasterDetailInsideStackParamList & TNavigation>
|
2021-12-03 19:27:57 +00:00
|
|
|
>;
|
|
|
|
route: RouteProp<ChatsStackParamList, 'MessagesView'>;
|
2022-10-21 18:27:55 +00:00
|
|
|
customEmojis: { [key: string]: ICustomEmoji };
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-05-11 02:22:17 +00:00
|
|
|
showActionSheet: (params: { options: string[]; hasCancel: boolean }) => void;
|
2021-11-16 16:10:49 +00:00
|
|
|
useRealName: boolean;
|
|
|
|
isMasterDetail: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IMessagesViewState {
|
|
|
|
loading: boolean;
|
2022-05-11 02:22:17 +00:00
|
|
|
messages: IMessage[];
|
|
|
|
message?: IMessage;
|
2021-11-16 16:10:49 +00:00
|
|
|
fileLoading: boolean;
|
|
|
|
total: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IParams {
|
2021-12-03 19:27:57 +00:00
|
|
|
rid: string;
|
2022-01-11 13:51:48 +00:00
|
|
|
t: SubscriptionType;
|
2021-11-16 16:10:49 +00:00
|
|
|
tmid?: string;
|
2022-04-01 15:32:17 +00:00
|
|
|
message?: TMessageModel;
|
2021-11-16 16:10:49 +00:00
|
|
|
name?: string;
|
2021-12-03 19:27:57 +00:00
|
|
|
fname?: string;
|
|
|
|
prid?: string;
|
2022-05-11 02:22:17 +00:00
|
|
|
room?: ISubscription;
|
2021-12-03 19:27:57 +00:00
|
|
|
jumpToMessageId?: string;
|
|
|
|
jumpToThreadId?: string;
|
|
|
|
roomUserId?: string;
|
2021-11-16 16:10:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
class MessagesView extends React.Component<IMessagesViewProps, IMessagesViewState> {
|
2021-12-03 19:27:57 +00:00
|
|
|
private rid: string;
|
2022-01-11 13:51:48 +00:00
|
|
|
private t: SubscriptionType;
|
2021-11-16 16:10:49 +00:00
|
|
|
private content: any;
|
2022-05-11 02:22:17 +00:00
|
|
|
private room?: ISubscription;
|
2021-11-16 16:10:49 +00:00
|
|
|
|
|
|
|
constructor(props: IMessagesViewProps) {
|
2019-05-28 13:03:08 +00:00
|
|
|
super(props);
|
2019-05-10 17:09:07 +00:00
|
|
|
this.state = {
|
|
|
|
loading: false,
|
2019-05-20 20:43:50 +00:00
|
|
|
messages: [],
|
2022-05-11 02:22:17 +00:00
|
|
|
fileLoading: true,
|
2022-05-27 17:22:47 +00:00
|
|
|
total: -1
|
2019-05-10 17:09:07 +00:00
|
|
|
};
|
2020-07-24 19:58:14 +00:00
|
|
|
this.setHeader();
|
2020-06-15 14:00:46 +00:00
|
|
|
this.rid = props.route.params?.rid;
|
|
|
|
this.t = props.route.params?.t;
|
|
|
|
this.content = this.defineMessagesViewContent(props.route.params?.name);
|
2019-05-10 17:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
|
feat: new audio player (#5160)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* first commit
* fix togglePlayPause
* separate audio to a folder inside components and minor tweak attachment
* created the slider with text
* play/pause button, currentTime equal the sound, can change the slider and reflect to the sound
* play/pause, track is working and onEnd
* update the icons with play-shaped-filled, pause-shape-filled, loading
* start the tweaks on layout
* can play multiple audios, pausing the previous to execute the new one
* loading animated
* added the audio rate
* layout fixed
* removed the sound manipulation from Slider to manipulate only in the index
* fix time margin horizontal
* fix play 2 audios and play/pause properly
* change the way we treat the audio
* remove audio copy
* minor tweak
* fix rate state
* remove the PAUSE_AUDIO
* fix unloadAll, add hit slop to slider, show the duration on the first render
* refactor colors to be the same as figmas name
* change the class' name and add the method pauseCurrentAudio
* pause audio when unmount a RoomView and unloadAll when focusing at RoomsListView
* pause audio when entering a thread
* fix where call the pauseCurrentAudio
* moved the player from messageAudio to audioPlayer
* refactor audio component
* remove loading
* update snapshot
* fix colors name
* pauseAudio when roomview is blur
* moved audio from message/component/audio to message/Audio
* add navigation focus to AudioPlayer component and fix the jest
* add the { androidImplementation: 'MediaPlayer' }
* fix action sheet swipe 02-room
* fix action sheet swipe 05-threads
* tweak touchable
* remove react.memo from playbutton
* hitSlop
* speed playback from array
* textinputprops
* tweak at names
* minor tweak at onEnd
* minor tweak at names
* update styles
* thumb seek size
* change marginBottom
* add the clamp, adjust the thumb position, remove the necessity of OnEndGestureHandler
* change the utils to constants
* change to audioState
* fix the seek for android
* TDownloadState
* speed array
* pause audio from messagesView when open the files
* update test
* minor tweak
* change the time after ony one click, fixes the thumb to move sync with the click
* Fix seek
* minor tweak Sound to Audio.Sound
* name of Icon
* enable PlaybackSpeed only when playing the audio
* playbackSpeed to mmkv
* mock implementation
* create native button
* minor tweak
* minor tweaks
* playbackSpeed after loadAudio
* avoid show the error when try to setRate without audio
* add messageID to differ audios inside a quote/forward from original one
* unloadRoomAudios instead of unloadAllAudios inside the roomsListView
* minor tweak
---------
Co-authored-by: Diego Mello <diegolmello@gmail.com>
Co-authored-by: Gleidson Daniel Silva <gleidson10daniel@hotmail.com>
2023-11-20 14:13:15 +00:00
|
|
|
componentWillUnmount(): void {
|
|
|
|
audioPlayer.pauseCurrentAudio();
|
|
|
|
}
|
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
shouldComponentUpdate(nextProps: IMessagesViewProps, nextState: IMessagesViewState) {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { loading, messages, fileLoading } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
|
|
|
if (nextProps.theme !== theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-10 17:09:07 +00:00
|
|
|
if (nextState.loading !== loading) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextState.messages, messages)) {
|
2019-05-10 17:09:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-08-26 16:56:39 +00:00
|
|
|
if (fileLoading !== nextState.fileLoading) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-10 17:09:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-07-24 19:58:14 +00:00
|
|
|
|
|
|
|
setHeader = () => {
|
|
|
|
const { route, navigation } = this.props;
|
|
|
|
navigation.setOptions({
|
|
|
|
title: I18n.t(route.params?.name)
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-12-03 19:27:57 +00:00
|
|
|
navToRoomInfo = (navParam: IRoomInfoParam) => {
|
2023-11-08 18:03:53 +00:00
|
|
|
const { navigation } = this.props;
|
2020-02-17 16:06:46 +00:00
|
|
|
navigation.navigate('RoomInfoView', navParam);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-02-17 16:06:46 +00:00
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
jumpToMessage = async ({ item }: { item: IMessage }) => {
|
2021-05-26 17:24:54 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
2021-11-16 16:10:49 +00:00
|
|
|
let params: IParams = {
|
2021-05-26 17:24:54 +00:00
|
|
|
rid: this.rid,
|
|
|
|
jumpToMessageId: item._id,
|
|
|
|
t: this.t,
|
|
|
|
room: this.room
|
|
|
|
};
|
|
|
|
if (item.tmid) {
|
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('DrawerNavigator');
|
|
|
|
} else {
|
|
|
|
navigation.pop(2);
|
|
|
|
}
|
|
|
|
params = {
|
|
|
|
...params,
|
|
|
|
tmid: item.tmid,
|
|
|
|
name: await getThreadName(this.rid, item.tmid, item._id),
|
2022-01-11 13:51:48 +00:00
|
|
|
t: SubscriptionType.THREAD
|
2021-05-26 17:24:54 +00:00
|
|
|
};
|
|
|
|
navigation.push('RoomView', params);
|
|
|
|
} else {
|
|
|
|
navigation.navigate('RoomView', params);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2021-11-16 16:10:49 +00:00
|
|
|
defineMessagesViewContent = (name: string) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { user, baseUrl, theme, useRealName } = this.props;
|
2022-05-11 02:22:17 +00:00
|
|
|
const renderItemCommonProps = (item: TAnyMessageModel) => ({
|
2020-05-08 17:07:58 +00:00
|
|
|
item,
|
2019-05-10 17:09:07 +00:00
|
|
|
baseUrl,
|
|
|
|
user,
|
|
|
|
author: item.u || item.user,
|
|
|
|
timeFormat: 'MMM Do YYYY, h:mm:ss a',
|
2019-05-20 20:43:50 +00:00
|
|
|
isEdited: !!item.editedAt,
|
|
|
|
isHeader: true,
|
2021-05-26 17:24:54 +00:00
|
|
|
isThreadRoom: true,
|
2019-05-20 20:43:50 +00:00
|
|
|
attachments: item.attachments || [],
|
2020-08-26 14:06:14 +00:00
|
|
|
useRealName,
|
2019-12-18 21:13:11 +00:00
|
|
|
showAttachment: this.showAttachment,
|
2020-02-17 16:06:46 +00:00
|
|
|
getCustomEmoji: this.getCustomEmoji,
|
2021-05-26 17:24:54 +00:00
|
|
|
navToRoomInfo: this.navToRoomInfo,
|
2022-04-01 21:52:38 +00:00
|
|
|
onPress: () => this.jumpToMessage({ item }),
|
|
|
|
rid: this.rid
|
2019-05-10 17:09:07 +00:00
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
return {
|
2019-05-10 17:09:07 +00:00
|
|
|
// Files Messages Screen
|
|
|
|
Files: {
|
|
|
|
name: I18n.t('Files'),
|
2021-09-13 20:41:05 +00:00
|
|
|
fetchFunc: async () => {
|
2020-07-17 18:59:18 +00:00
|
|
|
const { messages } = this.state;
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.getFiles(this.rid, this.t, messages.length);
|
2022-03-10 15:29:33 +00:00
|
|
|
if (result.success) {
|
|
|
|
return { ...result, messages: result.files };
|
|
|
|
}
|
2019-05-10 17:09:07 +00:00
|
|
|
},
|
|
|
|
noDataMsg: I18n.t('No_files'),
|
|
|
|
testID: 'room-files-view',
|
2022-03-02 14:18:01 +00:00
|
|
|
renderItem: (item: any) => (
|
2020-05-08 17:07:58 +00:00
|
|
|
<Message
|
|
|
|
{...renderItemCommonProps(item)}
|
2022-04-11 18:01:43 +00:00
|
|
|
theme={theme}
|
2020-05-08 17:07:58 +00:00
|
|
|
item={{
|
|
|
|
...item,
|
|
|
|
u: item.user,
|
2020-08-25 20:09:52 +00:00
|
|
|
ts: item.ts || item.uploadedAt,
|
2021-09-13 20:41:05 +00:00
|
|
|
attachments: [
|
|
|
|
{
|
|
|
|
title: item.name,
|
|
|
|
description: item.description,
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
...getFileUrlAndTypeFromMessage(item)
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
]
|
2020-05-08 17:07:58 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
2019-05-10 17:09:07 +00:00
|
|
|
},
|
|
|
|
// Mentions Messages Screen
|
|
|
|
Mentions: {
|
|
|
|
name: I18n.t('Mentions'),
|
2020-07-17 18:59:18 +00:00
|
|
|
fetchFunc: () => {
|
|
|
|
const { messages } = this.state;
|
2022-04-28 20:37:25 +00:00
|
|
|
return Services.getMessages(this.rid, this.t, { 'mentions._id': { $in: [user.id] } }, messages.length);
|
2020-07-17 18:59:18 +00:00
|
|
|
},
|
2019-05-10 17:09:07 +00:00
|
|
|
noDataMsg: I18n.t('No_mentioned_messages'),
|
|
|
|
testID: 'mentioned-messages-view',
|
2022-05-11 02:22:17 +00:00
|
|
|
renderItem: (item: TAnyMessageModel) => <Message {...renderItemCommonProps(item)} msg={item.msg} theme={theme} />
|
2019-05-10 17:09:07 +00:00
|
|
|
},
|
|
|
|
// Starred Messages Screen
|
|
|
|
Starred: {
|
|
|
|
name: I18n.t('Starred'),
|
2020-07-17 18:59:18 +00:00
|
|
|
fetchFunc: () => {
|
|
|
|
const { messages } = this.state;
|
2022-04-28 20:37:25 +00:00
|
|
|
return Services.getMessages(this.rid, this.t, { 'starred._id': { $in: [user.id] } }, messages.length);
|
2020-07-17 18:59:18 +00:00
|
|
|
},
|
2019-05-10 17:09:07 +00:00
|
|
|
noDataMsg: I18n.t('No_starred_messages'),
|
|
|
|
testID: 'starred-messages-view',
|
2022-05-11 02:22:17 +00:00
|
|
|
renderItem: (item: TAnyMessageModel) => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<Message {...renderItemCommonProps(item)} msg={item.msg} onLongPress={() => this.onLongPress(item)} theme={theme} />
|
2019-05-10 17:09:07 +00:00
|
|
|
),
|
2022-05-11 02:22:17 +00:00
|
|
|
action: (message: IMessage) => ({
|
2021-09-13 20:41:05 +00:00
|
|
|
title: I18n.t('Unstar'),
|
|
|
|
icon: message.starred ? 'star-filled' : 'star',
|
|
|
|
onPress: this.handleActionPress
|
|
|
|
}),
|
2022-05-11 02:22:17 +00:00
|
|
|
handleActionPress: (message: IMessage) => Services.toggleStarMessage(message._id, message.starred)
|
2019-05-10 17:09:07 +00:00
|
|
|
},
|
|
|
|
// Pinned Messages Screen
|
|
|
|
Pinned: {
|
|
|
|
name: I18n.t('Pinned'),
|
2020-07-17 18:59:18 +00:00
|
|
|
fetchFunc: () => {
|
|
|
|
const { messages } = this.state;
|
2022-04-28 20:37:25 +00:00
|
|
|
return Services.getMessages(this.rid, this.t, { pinned: true }, messages.length);
|
2020-07-17 18:59:18 +00:00
|
|
|
},
|
2019-05-10 17:09:07 +00:00
|
|
|
noDataMsg: I18n.t('No_pinned_messages'),
|
|
|
|
testID: 'pinned-messages-view',
|
2022-05-11 02:22:17 +00:00
|
|
|
renderItem: (item: TAnyMessageModel) => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<Message {...renderItemCommonProps(item)} msg={item.msg} onLongPress={() => this.onLongPress(item)} theme={theme} />
|
2019-05-10 17:09:07 +00:00
|
|
|
),
|
2020-06-15 19:35:45 +00:00
|
|
|
action: () => ({ title: I18n.t('Unpin'), icon: 'pin', onPress: this.handleActionPress }),
|
2022-05-11 02:22:17 +00:00
|
|
|
handleActionPress: (message: IMessage) => Services.togglePinMessage(message._id, message.pinned)
|
2019-05-10 17:09:07 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
}[name];
|
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
load = async () => {
|
|
|
|
const { messages, total, loading } = this.state;
|
2019-05-10 17:09:07 +00:00
|
|
|
if (messages.length === total || loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
|
|
|
try {
|
|
|
|
const result = await this.content.fetchFunc();
|
|
|
|
if (result.success) {
|
2022-05-03 19:52:56 +00:00
|
|
|
const urlRenderMessages = result.messages?.map((message: any) => {
|
|
|
|
if (message.urls && message.urls.length > 0) {
|
|
|
|
message.urls = message.urls?.map((url: any, index: any) => {
|
|
|
|
if (url.meta) {
|
|
|
|
return {
|
|
|
|
_id: index,
|
|
|
|
title: url.meta.pageTitle,
|
|
|
|
description: url.meta.ogDescription,
|
|
|
|
image: url.meta.ogImage,
|
|
|
|
url: url.url
|
|
|
|
} as IUrl;
|
|
|
|
}
|
|
|
|
return {} as IUrl;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return message;
|
|
|
|
});
|
2019-05-10 17:09:07 +00:00
|
|
|
this.setState({
|
2022-05-03 19:52:56 +00:00
|
|
|
messages: [...messages, ...urlRenderMessages],
|
2019-05-10 17:09:07 +00:00
|
|
|
total: result.total,
|
|
|
|
loading: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.setState({ loading: false });
|
|
|
|
console.warn('MessagesView -> catch -> error', error);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
getCustomEmoji: TGetCustomEmoji = name => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { customEmojis } = this.props;
|
|
|
|
const emoji = customEmojis[name];
|
|
|
|
if (emoji) {
|
|
|
|
return emoji;
|
|
|
|
}
|
|
|
|
return null;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
showAttachment = (attachment: IAttachment) => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate('AttachmentView', { attachment });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
onLongPress = (message: IMessage) => {
|
2020-06-15 19:35:45 +00:00
|
|
|
this.setState({ message }, this.showActionSheet);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
|
|
|
showActionSheet = () => {
|
2020-06-15 19:35:45 +00:00
|
|
|
const { message } = this.state;
|
|
|
|
const { showActionSheet } = this.props;
|
|
|
|
showActionSheet({ options: [this.content.action(message)], hasCancel: true });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
handleActionPress = async () => {
|
2020-06-15 19:35:45 +00:00
|
|
|
const { message } = this.state;
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2020-06-15 19:35:45 +00:00
|
|
|
try {
|
|
|
|
const result = await this.content.handleActionPress(message);
|
|
|
|
if (result.success) {
|
2021-11-16 16:10:49 +00:00
|
|
|
this.setState((prevState: IMessagesViewState) => ({
|
2022-05-11 02:22:17 +00:00
|
|
|
messages: prevState.messages.filter((item: IMessage) => item._id !== message?._id),
|
2020-06-15 19:35:45 +00:00
|
|
|
total: prevState.total - 1
|
|
|
|
}));
|
2019-05-10 17:09:07 +00:00
|
|
|
}
|
2020-06-15 19:35:45 +00:00
|
|
|
} catch {
|
|
|
|
// Do nothing
|
2019-05-10 17:09:07 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-11-16 16:10:49 +00:00
|
|
|
setFileLoading = (fileLoading: boolean) => {
|
2019-08-26 16:56:39 +00:00
|
|
|
this.setState({ fileLoading });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-08-26 16:56:39 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderEmpty = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
<View style={[styles.listEmptyContainer, { backgroundColor: themes[theme].backgroundColor }]} testID={this.content.testID}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.noDataFound, { color: themes[theme].titleText }]}>{this.content.noDataMsg}</Text>
|
|
|
|
</View>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
renderItem = ({ item }: { item: IMessage }) => this.content.renderItem(item);
|
2019-05-10 17:09:07 +00:00
|
|
|
|
|
|
|
render() {
|
2019-12-18 21:13:11 +00:00
|
|
|
const { messages, loading } = this.state;
|
|
|
|
const { theme } = this.props;
|
2019-05-10 17:09:07 +00:00
|
|
|
|
|
|
|
if (!loading && messages.length === 0) {
|
|
|
|
return this.renderEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
<SafeAreaView style={{ backgroundColor: themes[theme].backgroundColor }} testID={this.content.testID}>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
2019-05-10 17:09:07 +00:00
|
|
|
<FlatList
|
|
|
|
data={messages}
|
|
|
|
renderItem={this.renderItem}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.list, { backgroundColor: themes[theme].backgroundColor }]}
|
2019-05-10 17:09:07 +00:00
|
|
|
keyExtractor={item => item._id}
|
|
|
|
onEndReached={this.load}
|
2022-03-18 02:37:10 +00:00
|
|
|
ListFooterComponent={loading ? <ActivityIndicator /> : null}
|
2019-05-10 17:09:07 +00:00
|
|
|
/>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2020-02-11 14:09:14 +00:00
|
|
|
baseUrl: state.server.server,
|
|
|
|
user: getUserSelector(state),
|
2020-08-26 14:06:14 +00:00
|
|
|
customEmojis: state.customEmojis,
|
2021-05-26 17:24:54 +00:00
|
|
|
useRealName: state.settings.UI_Use_Real_Name,
|
|
|
|
isMasterDetail: state.app.isMasterDetail
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2020-06-15 19:35:45 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(withActionSheet(MessagesView)));
|