From 7e1dec41e9b61fe062c46fc18d9c34947ed0f1c7 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 21 Dec 2022 19:22:22 -0300 Subject: [PATCH] removed the avatarETagUser and search by username and text --- app/containers/Avatar/index.tsx | 33 +++++++++++------------- app/containers/Avatar/useAvatarETag.ts | 0 app/containers/RoomItem/IconOrAvatar.tsx | 12 ++------- app/containers/RoomItem/RoomItem.tsx | 4 +-- app/containers/RoomItem/index.tsx | 4 +-- app/containers/RoomItem/interfaces.ts | 3 --- app/containers/UserItem.tsx | 8 ++---- app/containers/message/MessageAvatar.tsx | 1 - app/lib/methods/subscriptions/rooms.ts | 8 +----- app/views/ChangeAvatarView/index.tsx | 1 - app/views/ProfileView/index.tsx | 1 - app/views/RoomsListView/index.tsx | 4 +-- app/views/SidebarView/index.tsx | 2 +- 13 files changed, 24 insertions(+), 57 deletions(-) create mode 100644 app/containers/Avatar/useAvatarETag.ts diff --git a/app/containers/Avatar/index.tsx b/app/containers/Avatar/index.tsx index e21056966..324922410 100644 --- a/app/containers/Avatar/index.tsx +++ b/app/containers/Avatar/index.tsx @@ -14,7 +14,6 @@ import { useTheme } from '../../theme'; import styles from './styles'; interface IAvatarContainer extends IAvatar { - isUserProfile?: boolean; handleEdit?: () => void; } @@ -31,23 +30,21 @@ const AvatarContainer = ({ getCustomEmoji, isStatic, rid, - handleEdit, - isUserProfile + handleEdit }: IAvatarContainer): React.ReactElement => { const subscription = useRef(); const [avatarETag, setAvatarETag] = useState(''); - const previousAvatarEtag = useRef(''); const { colors } = useTheme(); const isDirect = () => type === 'd'; const server = useSelector((state: IApplicationState) => state.share.server.server || state.server.server); const serverVersion = useSelector((state: IApplicationState) => state.share.server.version || state.server.version); - const { id, token, avatarETagUser } = useSelector( + const { id, token, username } = useSelector( (state: IApplicationState) => ({ id: getUserSelector(state).id, token: getUserSelector(state).token, - avatarETagUser: getUserSelector(state).avatarETag + username: getUserSelector(state).username }), shallowEqual ); @@ -62,14 +59,21 @@ const AvatarContainer = ({ true ); + const unsubscribeQuery = () => { + if (subscription?.current?.unsubscribe) { + subscription.current.unsubscribe(); + } + }; + const init = async () => { + unsubscribeQuery(); const db = database.active; const usersCollection = db.get('users'); const subsCollection = db.get('subscriptions'); let record; try { - if (isDirect()) { + if (isDirect() || username === text) { const [user] = await usersCollection.query(Q.where('username', text)).fetch(); record = user; } else if (rid) { @@ -88,19 +92,12 @@ const AvatarContainer = ({ }; useEffect(() => { - if (!avatarETag || avatarETag !== previousAvatarEtag.current) { + if (!avatarETag) { init(); } - return () => { - if (subscription?.current?.unsubscribe) { - subscription.current.unsubscribe(); - } - }; - }, [text, type, size, avatarETag, externalProviderUrl]); + }, [text]); // testar se precisa do avatarETag - useEffect(() => { - previousAvatarEtag.current = avatarETag; - }, [avatarETag]); + useEffect(() => () => unsubscribeQuery(), []); return ( <> @@ -122,7 +119,7 @@ const AvatarContainer = ({ rid={rid} blockUnauthenticatedAccess={blockUnauthenticatedAccess} externalProviderUrl={externalProviderUrl} - avatarETag={isUserProfile ? avatarETagUser : avatarETag} + avatarETag={avatarETag} serverVersion={serverVersion} /> {handleEdit ? ( diff --git a/app/containers/Avatar/useAvatarETag.ts b/app/containers/Avatar/useAvatarETag.ts new file mode 100644 index 000000000..e69de29bb diff --git a/app/containers/RoomItem/IconOrAvatar.tsx b/app/containers/RoomItem/IconOrAvatar.tsx index f9a9132bf..7d929189f 100644 --- a/app/containers/RoomItem/IconOrAvatar.tsx +++ b/app/containers/RoomItem/IconOrAvatar.tsx @@ -18,19 +18,11 @@ const IconOrAvatar = ({ teamMain, showLastMessage, displayMode, - sourceType, - isUserProfile + sourceType }: IIconOrAvatar): React.ReactElement | null => { if (showAvatar) { return ( - + ); } diff --git a/app/containers/RoomItem/RoomItem.tsx b/app/containers/RoomItem/RoomItem.tsx index 0678278d2..1e832aeea 100644 --- a/app/containers/RoomItem/RoomItem.tsx +++ b/app/containers/RoomItem/RoomItem.tsx @@ -52,8 +52,7 @@ const RoomItem = ({ showAvatar, displayMode, sourceType, - hideMentionStatus, - isUserProfile + hideMentionStatus }: IRoomItemProps) => ( {showLastMessage && displayMode === DisplayMode.Expanded ? ( <> diff --git a/app/containers/RoomItem/index.tsx b/app/containers/RoomItem/index.tsx index 5af96d2f4..5dd7d5469 100644 --- a/app/containers/RoomItem/index.tsx +++ b/app/containers/RoomItem/index.tsx @@ -34,8 +34,7 @@ const RoomItemContainer = React.memo( getRoomTitle = () => 'title', getRoomAvatar = () => '', getIsRead = () => false, - swipeEnabled = true, - isUserProfile + swipeEnabled = true }: IRoomItemContainerProps) => { const name = getRoomTitle(item); const testID = `rooms-list-view-item-${name}`; @@ -128,7 +127,6 @@ const RoomItemContainer = React.memo( showAvatar={showAvatar} displayMode={displayMode} sourceType={item.source} - isUserProfile={isUserProfile} /> ); }, diff --git a/app/containers/RoomItem/interfaces.ts b/app/containers/RoomItem/interfaces.ts index 0a8dfd88f..bf2cc3604 100644 --- a/app/containers/RoomItem/interfaces.ts +++ b/app/containers/RoomItem/interfaces.ts @@ -47,7 +47,6 @@ export interface IWrapperProps { teamMain: boolean; showAvatar: boolean; sourceType: IOmnichannelSource; - isUserProfile: boolean; } export interface ITypeIconProps { @@ -117,7 +116,6 @@ export interface IRoomItemProps extends IBaseRoomItem { size?: number; sourceType: IOmnichannelSource; hideMentionStatus?: boolean; - isUserProfile: boolean; } export interface ILastMessageProps { @@ -154,5 +152,4 @@ export interface IIconOrAvatar { teamMain: boolean; showLastMessage: boolean; sourceType: IOmnichannelSource; - isUserProfile: boolean; } diff --git a/app/containers/UserItem.tsx b/app/containers/UserItem.tsx index 9188dbdec..02739d2f8 100644 --- a/app/containers/UserItem.tsx +++ b/app/containers/UserItem.tsx @@ -1,8 +1,6 @@ import React from 'react'; import { Pressable, StyleProp, StyleSheet, Text, View, ViewStyle } from 'react-native'; -import { useAppSelector } from '../lib/hooks'; -import { getUserSelector } from '../selectors/login'; import Avatar from './Avatar'; import { CustomIcon, TIconsName } from './CustomIcon'; import sharedStyles from '../views/Styles'; @@ -45,12 +43,10 @@ interface IUserItem { style?: StyleProp; icon?: TIconsName | null; iconColor?: string; - id?: string; } -const UserItem = ({ name, username, onPress, testID, onLongPress, style, icon, iconColor, id }: IUserItem) => { +const UserItem = ({ name, username, onPress, testID, onLongPress, style, icon, iconColor }: IUserItem) => { const { colors } = useTheme(); - const { userId } = useAppSelector(state => ({ userId: getUserSelector(state).id })); return ( - + {name} diff --git a/app/containers/message/MessageAvatar.tsx b/app/containers/message/MessageAvatar.tsx index 26fd2f662..3852939f0 100644 --- a/app/containers/message/MessageAvatar.tsx +++ b/app/containers/message/MessageAvatar.tsx @@ -20,7 +20,6 @@ const MessageAvatar = React.memo(({ isHeader, avatar, author, small, navToRoomIn size={small ? 20 : 36} borderRadius={small ? 2 : 4} onPress={author._id === user.id ? undefined : () => navToRoomInfo(navParam)} - isUserProfile={author._id === user.id} getCustomEmoji={getCustomEmoji} avatar={avatar} emoji={emoji} diff --git a/app/lib/methods/subscriptions/rooms.ts b/app/lib/methods/subscriptions/rooms.ts index 7c80e37f5..5bbeffe3d 100644 --- a/app/lib/methods/subscriptions/rooms.ts +++ b/app/lib/methods/subscriptions/rooms.ts @@ -288,7 +288,7 @@ export default function subscribeRooms() { const [type, data] = ddpMessage.fields.args; const [, ev] = ddpMessage.fields.eventName.split('/'); if (/userData/.test(ev)) { - const [{ diff, unset }] = ddpMessage.fields.args; + const [{ diff }] = ddpMessage.fields.args; if (diff?.statusLivechat) { store.dispatch(setUser({ statusLivechat: diff.statusLivechat })); } @@ -298,12 +298,6 @@ export default function subscribeRooms() { if ((['settings.preferences.alsoSendThreadToChannel'] as any) in diff) { store.dispatch(setUser({ alsoSendThreadToChannel: diff['settings.preferences.alsoSendThreadToChannel'] })); } - if (diff?.avatarETag) { - store.dispatch(setUser({ avatarETag: diff.avatarETag })); - } - if (unset?.avatarETag) { - store.dispatch(setUser({ avatarETag: '' })); - } } if (/subscriptions/.test(ev)) { if (type === 'removed') { diff --git a/app/views/ChangeAvatarView/index.tsx b/app/views/ChangeAvatarView/index.tsx index 892e97172..23fc61836 100644 --- a/app/views/ChangeAvatarView/index.tsx +++ b/app/views/ChangeAvatarView/index.tsx @@ -152,7 +152,6 @@ const ChangeAvatarView = () => { avatar={avatar?.url} isStatic={avatar?.url} size={100} - isUserProfile={fromUser} type={t} {...ridProps} /> diff --git a/app/views/ProfileView/index.tsx b/app/views/ProfileView/index.tsx index 4647686d0..dca6b0dc3 100644 --- a/app/views/ProfileView/index.tsx +++ b/app/views/ProfileView/index.tsx @@ -416,7 +416,6 @@ class ProfileView extends React.Component avatarETag={user.avatarETag} size={100} handleEdit={Accounts_AllowUserAvatarChange ? this.handleEditAvatar : undefined} - isUserProfile /> ); }; diff --git a/app/views/SidebarView/index.tsx b/app/views/SidebarView/index.tsx index d28fdcf64..068d9257e 100644 --- a/app/views/SidebarView/index.tsx +++ b/app/views/SidebarView/index.tsx @@ -251,7 +251,7 @@ class Sidebar extends Component { > - +