diff --git a/app/definitions/TChangeAvatarViewContext.ts b/app/definitions/TChangeAvatarViewContext.ts new file mode 100644 index 000000000..00c9ac831 --- /dev/null +++ b/app/definitions/TChangeAvatarViewContext.ts @@ -0,0 +1 @@ +export type TChangeAvatarViewContext = 'profile' | 'room'; diff --git a/app/lib/methods/helpers/image.ts b/app/lib/methods/helpers/image.ts index 363d80115..04aaedad3 100644 --- a/app/lib/methods/helpers/image.ts +++ b/app/lib/methods/helpers/image.ts @@ -1,6 +1,7 @@ // Fast Image can't render a svg image from a uri yet, because of that we aren't test the svg within the RegEx const regExpUrlImage = new RegExp( - '.(jpg|jpeg|png|webp|avif|gif)' + // type of the URL - '(\\?[;&a-z\\d%_.~+=-]*)?' // query string + '.(jpg|jpeg|png|webp|avif|gif|tiff)' + // type of the URL + '(\\?[;&a-z\\d%_.~+=-]*)?', + 'i' // query string ); export const isImage = (url: string) => regExpUrlImage.test(url); diff --git a/app/stacks/MasterDetailStack/types.ts b/app/stacks/MasterDetailStack/types.ts index 181a35d35..42215d5ff 100644 --- a/app/stacks/MasterDetailStack/types.ts +++ b/app/stacks/MasterDetailStack/types.ts @@ -6,6 +6,7 @@ import { IMessage } from '../../definitions/IMessage'; import { ISubscription, SubscriptionType, TSubscriptionModel } from '../../definitions/ISubscription'; import { ILivechatDepartment } from '../../definitions/ILivechatDepartment'; import { ILivechatTag } from '../../definitions/ILivechatTag'; +import { TChangeAvatarViewContext } from '../../definitions/TChangeAvatarViewContext'; export type MasterDetailChatsStackParamList = { RoomView: { @@ -59,7 +60,7 @@ export type ModalStackParamList = { isRadio?: boolean; }; ChangeAvatarView: { - fromUser?: boolean; + context: TChangeAvatarViewContext; titleHeader?: string; room?: ISubscription; t?: SubscriptionType; diff --git a/app/stacks/types.ts b/app/stacks/types.ts index d6a1bd6d4..ea58cac9f 100644 --- a/app/stacks/types.ts +++ b/app/stacks/types.ts @@ -13,6 +13,7 @@ import { ModalStackParamList } from './MasterDetailStack/types'; import { TThreadModel } from '../definitions'; import { ILivechatDepartment } from '../definitions/ILivechatDepartment'; import { ILivechatTag } from '../definitions/ILivechatTag'; +import { TChangeAvatarViewContext } from '../definitions/TChangeAvatarViewContext'; export type ChatsStackParamList = { ModalStackNavigator: NavigatorScreenParams; @@ -181,7 +182,7 @@ export type ChatsStackParamList = { videoConf?: boolean; }; ChangeAvatarView: { - fromUser?: boolean; + context: TChangeAvatarViewContext; titleHeader?: string; room?: ISubscription; t?: SubscriptionType; @@ -201,7 +202,7 @@ export type ProfileStackParamList = { onChangeValue: Function; }; ChangeAvatarView: { - fromUser?: boolean; + context: TChangeAvatarViewContext; titleHeader?: string; room?: ISubscription; t?: SubscriptionType; diff --git a/app/views/ChangeAvatarView/AvatarSuggestion.tsx b/app/views/ChangeAvatarView/AvatarSuggestion.tsx index 0e8ad7159..2b85f7bbd 100644 --- a/app/views/ChangeAvatarView/AvatarSuggestion.tsx +++ b/app/views/ChangeAvatarView/AvatarSuggestion.tsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from 'react'; import { Text, View } from 'react-native'; -import { IAvatar, IUser } from '../../definitions'; +import { IAvatar } from '../../definitions'; import { Services } from '../../lib/services'; import I18n from '../../i18n'; import styles from './styles'; @@ -10,11 +10,11 @@ import AvatarSuggestionItem from './AvatarSuggestionItem'; const AvatarSuggestion = ({ onPress, - user, + username, resetAvatar }: { onPress: (value: IAvatar | null) => void; - user?: IUser; + username?: string; resetAvatar?: () => void; }) => { const [avatarSuggestions, setAvatarSuggestions] = useState([]); @@ -40,11 +40,11 @@ const AvatarSuggestion = ({ }, []); return ( - + {I18n.t('Images_uploaded')} - {user?.username && resetAvatar ? ( - + {username && resetAvatar ? ( + ) : null} {avatarSuggestions.slice(0, 7).map(item => ( diff --git a/app/views/ChangeAvatarView/index.tsx b/app/views/ChangeAvatarView/index.tsx index eff658ca1..e3fcec23b 100644 --- a/app/views/ChangeAvatarView/index.tsx +++ b/app/views/ChangeAvatarView/index.tsx @@ -32,8 +32,9 @@ const ChangeAvatarView = () => { const [textAvatar, setTextAvatar] = useState(''); const [saving, setSaving] = useState(false); const { colors } = useTheme(); - const { user, serverVersion } = useAppSelector(state => ({ - user: getUserSelector(state), + const { userId, username, serverVersion } = useAppSelector(state => ({ + userId: getUserSelector(state).id, + username: getUserSelector(state).username, isMasterDetail: state.app.isMasterDetail, serverVersion: state.server.version })); @@ -41,7 +42,7 @@ const ChangeAvatarView = () => { const avatarUrl = useRef(''); const navigation = useNavigation>(); - const { fromUser, titleHeader, room, t } = useRoute>().params; + const { context, titleHeader, room, t } = useRoute>().params; useLayoutEffect(() => { navigation.setOptions({ @@ -75,7 +76,7 @@ const ChangeAvatarView = () => { const submit = async () => { let result; - if (!fromUser && room?.rid) { + if ((context === 'room') && room?.rid) { // Change Rooms Avatar result = await changeRoomsAvatar(room.rid); } else if (avatar?.url) { @@ -118,7 +119,7 @@ const ChangeAvatarView = () => { const resetUserAvatar = async () => { try { - await Services.resetAvatar(user.id); + await Services.resetAvatar(userId); return true; } catch (e) { return handleError(e, 'setAvatarFromService', 'changing_avatar'); @@ -137,8 +138,8 @@ const ChangeAvatarView = () => { const resetAvatar = () => { setAvatar(null); - setTextAvatar(`@${user.username}`); - avatarUrl.current = `@${user.username}`; + setTextAvatar(`@${username}`); + avatarUrl.current = `@${username}`; }; const resetRoomAvatar = () => { @@ -181,7 +182,7 @@ const ChangeAvatarView = () => { > { {...ridProps} /> - {fromUser ? setAvatar({ url: value, data: value, service: 'url' })} /> : null} + {context=== 'profile' ? setAvatar({ url: value, data: value, service: 'url' })} /> : null} - {fromUser ? : null} + {context=== 'profile' ? : null}