Skip to content

Commit

Permalink
Merge branch 'develop' into fix.placeholder-workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello authored Jul 11, 2024
2 parents 0487f0f + 6982fd2 commit 9a3b89f
Show file tree
Hide file tree
Showing 69 changed files with 2,103 additions and 879 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode VERSIONCODE as Integer
versionName "4.50.0"
versionName "4.50.1"
vectorDrawables.useSupportLibrary = true
if (!isFoss) {
manifestPlaceholders = [BugsnagAPIKey: BugsnagAPIKey as String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.dylanvann.fastimage.FastImageOkHttpUrlLoader;

import expo.modules.av.player.datasource.SharedCookiesDataSourceFactory;
import expo.modules.filesystem.FileSystemModule;

public class SSLPinningModule extends ReactContextBaseJavaModule implements KeyChainAliasCallback {

Expand Down Expand Up @@ -113,6 +114,8 @@ public void setCertificate(String data, Promise promise) {
FastImageOkHttpUrlLoader.setOkHttpClient(getOkHttpClient());
// Expo AV network layer
SharedCookiesDataSourceFactory.setOkHttpClient(getOkHttpClient());
// Expo File System network layer
FileSystemModule.setOkHttpClient(getOkHttpClient());

promise.resolve(null);
}
Expand Down
2 changes: 2 additions & 0 deletions app/containers/MessageComposer/MessageComposer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ describe('MessageComposer', () => {
const onSendMessage = jest.fn();
render(<Render context={{ onSendMessage }} />);
expect(screen.getByTestId('message-composer-send-audio')).toBeOnTheScreen();
expect(screen.queryByTestId('message-composer-send')).not.toBeOnTheScreen();

await user.type(screen.getByTestId('message-composer-input'), 'test');
expect(screen.getByTestId('message-composer-input')).not.toBe('');
expect(screen.queryByTestId('message-composer-send-audio')).not.toBeOnTheScreen();
expect(screen.getByTestId('message-composer-send')).toBeOnTheScreen();

Expand Down
5 changes: 3 additions & 2 deletions app/containers/MessageComposer/components/ComposerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ export const ComposerInput = memo(
}));

const setInput: TSetInput = (text, selection) => {
textRef.current = text;
const message = text.trim();
textRef.current = message;
if (inputRef.current) {
inputRef.current.setNativeProps({ text });
}
Expand All @@ -163,7 +164,7 @@ export const ComposerInput = memo(
selectionRef.current = selection;
}, 50);
}
setMicOrSend(text.length === 0 ? 'mic' : 'send');
setMicOrSend(message.length === 0 ? 'mic' : 'send');
};

const focus = () => {
Expand Down
6 changes: 4 additions & 2 deletions app/containers/MessageComposer/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ export const IMAGE_PICKER_CONFIG = {
cropping: true,
avoidEmptySpaceAroundImage: false,
freeStyleCropEnabled: true,
forceJpg: true
forceJpg: true,
includeExif: true
};

export const LIBRARY_PICKER_CONFIG: Options = {
multiple: true,
compressVideoPreset: 'Passthrough',
mediaType: 'any'
mediaType: 'any',
includeExif: true
};

export const VIDEO_PICKER_CONFIG: Options = {
Expand Down
2 changes: 1 addition & 1 deletion app/containers/UIKit/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StyleSheet, View } from 'react-native';
import FastImage from 'react-native-fast-image';
import { BlockContext } from '@rocket.chat/ui-kit';

import ImageContainer from '../message/Image';
import ImageContainer from '../message/Components/Attachments/Image';
import Navigation from '../../lib/navigation/appNavigation';
import { IThumb, IImage, IElement } from './interfaces';
import { IAttachment } from '../../definitions';
Expand Down
47 changes: 47 additions & 0 deletions app/containers/message/Components/Attachments/AttachedActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useContext } from 'react';

import Button from '../../../Button';
import MessageContext from '../../Context';
import { IAttachment, TGetCustomEmoji } from '../../../../definitions';
import openLink from '../../../../lib/methods/helpers/openLink';
import Markdown from '../../../markdown';

export type TElement = {
type: string;
msg?: string;
url?: string;
text: string;
};

const AttachedActions = ({ attachment, getCustomEmoji }: { attachment: IAttachment; getCustomEmoji: TGetCustomEmoji }) => {
const { onAnswerButtonPress } = useContext(MessageContext);

if (!attachment.actions) {
return null;
}

const attachedButtons = attachment.actions.map((element: TElement) => {
const onPress = () => {
if (element.msg) {
onAnswerButtonPress(element.msg);
}

if (element.url) {
openLink(element.url);
}
};

if (element.type === 'button') {
return <Button onPress={onPress} title={element.text} />;
}

return null;
});
return (
<>
<Markdown msg={attachment.text} getCustomEmoji={getCustomEmoji} />
{attachedButtons}
</>
);
};
export default AttachedActions;
Original file line number Diff line number Diff line change
@@ -1,57 +1,16 @@
import React, { useContext } from 'react';
import { dequal } from 'dequal';

import { IMessageAttachments } from './interfaces';
import Image from './Image';
import Audio from './Audio';
import Video from './Video';
import { Reply } from './components';
import Button from '../Button';
import MessageContext from './Context';
import { IAttachment, TGetCustomEmoji } from '../../definitions';
import CollapsibleQuote from './Components/CollapsibleQuote';
import openLink from '../../lib/methods/helpers/openLink';
import Markdown from '../markdown';
import { getMessageFromAttachment } from './utils';

export type TElement = {
type: string;
msg?: string;
url?: string;
text: string;
};

const AttachedActions = ({ attachment, getCustomEmoji }: { attachment: IAttachment; getCustomEmoji: TGetCustomEmoji }) => {
const { onAnswerButtonPress } = useContext(MessageContext);

if (!attachment.actions) {
return null;
}

const attachedButtons = attachment.actions.map((element: TElement) => {
const onPress = () => {
if (element.msg) {
onAnswerButtonPress(element.msg);
}

if (element.url) {
openLink(element.url);
}
};

if (element.type === 'button') {
return <Button onPress={onPress} title={element.text} />;
}

return null;
});
return (
<>
<Markdown msg={attachment.text} getCustomEmoji={getCustomEmoji} />
{attachedButtons}
</>
);
};
import CollapsibleQuote from './CollapsibleQuote';
import AttachedActions from './AttachedActions';
import MessageContext from '../../Context';
import { IMessageAttachments } from '../../interfaces';
import { IAttachment } from '../../../../definitions';
import { getMessageFromAttachment } from '../../utils';

const Attachments: React.FC<IMessageAttachments> = React.memo(
({ attachments, timeFormat, showAttachment, style, getCustomEmoji, isReply, author }: IMessageAttachments) => {
Expand Down Expand Up @@ -101,6 +60,7 @@ const Attachments: React.FC<IMessageAttachments> = React.memo(
getCustomEmoji={getCustomEmoji}
style={style}
isReply={isReply}
author={author}
msg={msg}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import React, { useContext, useEffect, useState } from 'react';
import React, { useCallback, useContext, useEffect, useState } from 'react';
import { StyleProp, TextStyle } from 'react-native';

import Markdown from '../markdown';
import MessageContext from './Context';
import { TGetCustomEmoji } from '../../definitions/IEmoji';
import { IAttachment, IUserMessage } from '../../definitions';
import {
TDownloadState,
downloadMediaFile,
getMediaCache,
isDownloadActive,
resumeMediaFile
} from '../../lib/methods/handleMediaDownload';
import { fetchAutoDownloadEnabled } from '../../lib/methods/autoDownloadPreference';
import AudioPlayer from '../AudioPlayer';
import { useAudioUrl } from './hooks/useAudioUrl';
import { getAudioUrlToCache } from '../../lib/methods/getAudioUrl';
import { emitter } from '../../../../lib/methods/helpers';
import Markdown from '../../../markdown';
import MessageContext from '../../Context';
import { TGetCustomEmoji } from '../../../../definitions/IEmoji';
import { IAttachment, IUserMessage } from '../../../../definitions';
import { TDownloadState, downloadMediaFile, getMediaCache, isDownloadActive } from '../../../../lib/methods/handleMediaDownload';
import { fetchAutoDownloadEnabled } from '../../../../lib/methods/autoDownloadPreference';
import AudioPlayer from '../../../AudioPlayer';
import { useAudioUrl } from '../../hooks/useAudioUrl';
import { getAudioUrlToCache } from '../../../../lib/methods/getAudioUrl';

interface IMessageAudioProps {
file: IAttachment;
Expand All @@ -31,7 +26,6 @@ const MessageAudio = ({ file, getCustomEmoji, author, isReply, style, msg }: IMe
const [downloadState, setDownloadState] = useState<TDownloadState>('loading');
const [fileUri, setFileUri] = useState('');
const { baseUrl, user, id, rid } = useContext(MessageContext);

const audioUrl = useAudioUrl({ audioUrl: file.audio_url });

const onPlayButtonPress = async () => {
Expand All @@ -48,12 +42,15 @@ const MessageAudio = ({ file, getCustomEmoji, author, isReply, style, msg }: IMe
setDownloadState('loading');
try {
if (audioUrl) {
const audio = await downloadMediaFile({
const audioUri = await downloadMediaFile({
messageId: id,
downloadUrl: getAudioUrlToCache({ token: user.token, userId: user.id, url: audioUrl }),
type: 'audio',
mimeType: file.audio_type
mimeType: file.audio_type,
encryption: file.encryption,
originalChecksum: file.hashes?.sha256
});
setFileUri(audio);
setFileUri(audioUri);
setDownloadState('downloaded');
}
} catch {
Expand Down Expand Up @@ -83,26 +80,16 @@ const MessageAudio = ({ file, getCustomEmoji, author, isReply, style, msg }: IMe
mimeType: file.audio_type,
urlToCache: audioUrl
});
if (cachedAudioResult?.exists) {
const result = cachedAudioResult?.exists && file.e2e !== 'pending';
if (result) {
setFileUri(cachedAudioResult.uri);
setDownloadState('downloaded');
}
return !!cachedAudioResult?.exists;
return result;
};

const handleResumeDownload = async () => {
try {
setDownloadState('loading');
if (audioUrl) {
const videoUri = await resumeMediaFile({
downloadUrl: audioUrl
});
setFileUri(videoUri);
setDownloadState('downloaded');
}
} catch (e) {
setDownloadState('to-download');
}
const handleResumeDownload = () => {
emitter.on(`downloadMedia${id}`, downloadMediaListener);
};

useEffect(() => {
Expand All @@ -122,6 +109,15 @@ const MessageAudio = ({ file, getCustomEmoji, author, isReply, style, msg }: IMe
}
}, [audioUrl]);

const downloadMediaListener = useCallback((uri: string) => {
setFileUri(uri);
setDownloadState('downloaded');
}, []);

useEffect(() => () => {
emitter.off(`downloadMedia${id}`, downloadMediaListener);
});

if (!baseUrl) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { View } from 'react-native';

import MessageContext from '../../Context';
import MessageContext from '../../../Context';
import CollapsibleQuote from '.';

const testAttachment = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fireEvent, render, within } from '@testing-library/react-native';
import React from 'react';

import MessageContext from '../../Context';
import MessageContext from '../../../Context';
import CollapsibleQuote from '.';

const testAttachment = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { dequal } from 'dequal';
import React, { useContext, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';

import { themes } from '../../../../lib/constants';
import { IAttachment } from '../../../../definitions/IAttachment';
import { TGetCustomEmoji } from '../../../../definitions/IEmoji';
import { CustomIcon } from '../../../CustomIcon';
import { useTheme } from '../../../../theme';
import sharedStyles from '../../../../views/Styles';
import Markdown from '../../../markdown';
import MessageContext from '../../Context';
import Touchable from '../../Touchable';
import { BUTTON_HIT_SLOP } from '../../utils';
import { themes } from '../../../../../lib/constants';
import { IAttachment } from '../../../../../definitions/IAttachment';
import { TGetCustomEmoji } from '../../../../../definitions/IEmoji';
import { CustomIcon } from '../../../../CustomIcon';
import { useTheme } from '../../../../../theme';
import sharedStyles from '../../../../../views/Styles';
import Markdown from '../../../../markdown';
import MessageContext from '../../../Context';
import Touchable from '../../../Touchable';
import { BUTTON_HIT_SLOP } from '../../../utils';

const styles = StyleSheet.create({
button: {
Expand Down Expand Up @@ -156,8 +156,7 @@ const CollapsibleQuote = React.memo(
}
]}
background={Touchable.Ripple(themes[theme].surfaceNeutral)}
hitSlop={BUTTON_HIT_SLOP}
>
hitSlop={BUTTON_HIT_SLOP}>
<View style={styles.touchableContainer}>
<View style={styles.attachmentContainer}>
<View style={styles.authorContainer}>
Expand Down
Loading

0 comments on commit 9a3b89f

Please sign in to comment.