removed the avatarETagUser and search by username and text

This commit is contained in:
Reinaldo Neto 2022-12-21 19:22:22 -03:00
parent 34993dace2
commit 7e1dec41e9
13 changed files with 24 additions and 57 deletions

View File

@ -14,7 +14,6 @@ import { useTheme } from '../../theme';
import styles from './styles'; import styles from './styles';
interface IAvatarContainer extends IAvatar { interface IAvatarContainer extends IAvatar {
isUserProfile?: boolean;
handleEdit?: () => void; handleEdit?: () => void;
} }
@ -31,23 +30,21 @@ const AvatarContainer = ({
getCustomEmoji, getCustomEmoji,
isStatic, isStatic,
rid, rid,
handleEdit, handleEdit
isUserProfile
}: IAvatarContainer): React.ReactElement => { }: IAvatarContainer): React.ReactElement => {
const subscription = useRef<Subscription>(); const subscription = useRef<Subscription>();
const [avatarETag, setAvatarETag] = useState<string | undefined>(''); const [avatarETag, setAvatarETag] = useState<string | undefined>('');
const previousAvatarEtag = useRef<string | undefined>('');
const { colors } = useTheme(); const { colors } = useTheme();
const isDirect = () => type === 'd'; const isDirect = () => type === 'd';
const server = useSelector((state: IApplicationState) => state.share.server.server || state.server.server); 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 serverVersion = useSelector((state: IApplicationState) => state.share.server.version || state.server.version);
const { id, token, avatarETagUser } = useSelector( const { id, token, username } = useSelector(
(state: IApplicationState) => ({ (state: IApplicationState) => ({
id: getUserSelector(state).id, id: getUserSelector(state).id,
token: getUserSelector(state).token, token: getUserSelector(state).token,
avatarETagUser: getUserSelector(state).avatarETag username: getUserSelector(state).username
}), }),
shallowEqual shallowEqual
); );
@ -62,14 +59,21 @@ const AvatarContainer = ({
true true
); );
const unsubscribeQuery = () => {
if (subscription?.current?.unsubscribe) {
subscription.current.unsubscribe();
}
};
const init = async () => { const init = async () => {
unsubscribeQuery();
const db = database.active; const db = database.active;
const usersCollection = db.get('users'); const usersCollection = db.get('users');
const subsCollection = db.get('subscriptions'); const subsCollection = db.get('subscriptions');
let record; let record;
try { try {
if (isDirect()) { if (isDirect() || username === text) {
const [user] = await usersCollection.query(Q.where('username', text)).fetch(); const [user] = await usersCollection.query(Q.where('username', text)).fetch();
record = user; record = user;
} else if (rid) { } else if (rid) {
@ -88,19 +92,12 @@ const AvatarContainer = ({
}; };
useEffect(() => { useEffect(() => {
if (!avatarETag || avatarETag !== previousAvatarEtag.current) { if (!avatarETag) {
init(); init();
} }
return () => { }, [text]); // testar se precisa do avatarETag
if (subscription?.current?.unsubscribe) {
subscription.current.unsubscribe();
}
};
}, [text, type, size, avatarETag, externalProviderUrl]);
useEffect(() => { useEffect(() => () => unsubscribeQuery(), []);
previousAvatarEtag.current = avatarETag;
}, [avatarETag]);
return ( return (
<> <>
@ -122,7 +119,7 @@ const AvatarContainer = ({
rid={rid} rid={rid}
blockUnauthenticatedAccess={blockUnauthenticatedAccess} blockUnauthenticatedAccess={blockUnauthenticatedAccess}
externalProviderUrl={externalProviderUrl} externalProviderUrl={externalProviderUrl}
avatarETag={isUserProfile ? avatarETagUser : avatarETag} avatarETag={avatarETag}
serverVersion={serverVersion} serverVersion={serverVersion}
/> />
{handleEdit ? ( {handleEdit ? (

View File

View File

@ -18,19 +18,11 @@ const IconOrAvatar = ({
teamMain, teamMain,
showLastMessage, showLastMessage,
displayMode, displayMode,
sourceType, sourceType
isUserProfile
}: IIconOrAvatar): React.ReactElement | null => { }: IIconOrAvatar): React.ReactElement | null => {
if (showAvatar) { if (showAvatar) {
return ( return (
<Avatar <Avatar text={avatar} size={displayMode === DisplayMode.Condensed ? 36 : 48} type={type} style={styles.avatar} rid={rid} />
isUserProfile={isUserProfile}
text={avatar}
size={displayMode === DisplayMode.Condensed ? 36 : 48}
type={type}
style={styles.avatar}
rid={rid}
/>
); );
} }

View File

@ -52,8 +52,7 @@ const RoomItem = ({
showAvatar, showAvatar,
displayMode, displayMode,
sourceType, sourceType,
hideMentionStatus, hideMentionStatus
isUserProfile
}: IRoomItemProps) => ( }: IRoomItemProps) => (
<Touchable <Touchable
onPress={onPress} onPress={onPress}
@ -84,7 +83,6 @@ const RoomItem = ({
showAvatar={showAvatar} showAvatar={showAvatar}
showLastMessage={!!showLastMessage} showLastMessage={!!showLastMessage}
sourceType={sourceType} sourceType={sourceType}
isUserProfile={isUserProfile}
> >
{showLastMessage && displayMode === DisplayMode.Expanded ? ( {showLastMessage && displayMode === DisplayMode.Expanded ? (
<> <>

View File

@ -34,8 +34,7 @@ const RoomItemContainer = React.memo(
getRoomTitle = () => 'title', getRoomTitle = () => 'title',
getRoomAvatar = () => '', getRoomAvatar = () => '',
getIsRead = () => false, getIsRead = () => false,
swipeEnabled = true, swipeEnabled = true
isUserProfile
}: IRoomItemContainerProps) => { }: IRoomItemContainerProps) => {
const name = getRoomTitle(item); const name = getRoomTitle(item);
const testID = `rooms-list-view-item-${name}`; const testID = `rooms-list-view-item-${name}`;
@ -128,7 +127,6 @@ const RoomItemContainer = React.memo(
showAvatar={showAvatar} showAvatar={showAvatar}
displayMode={displayMode} displayMode={displayMode}
sourceType={item.source} sourceType={item.source}
isUserProfile={isUserProfile}
/> />
); );
}, },

View File

@ -47,7 +47,6 @@ export interface IWrapperProps {
teamMain: boolean; teamMain: boolean;
showAvatar: boolean; showAvatar: boolean;
sourceType: IOmnichannelSource; sourceType: IOmnichannelSource;
isUserProfile: boolean;
} }
export interface ITypeIconProps { export interface ITypeIconProps {
@ -117,7 +116,6 @@ export interface IRoomItemProps extends IBaseRoomItem {
size?: number; size?: number;
sourceType: IOmnichannelSource; sourceType: IOmnichannelSource;
hideMentionStatus?: boolean; hideMentionStatus?: boolean;
isUserProfile: boolean;
} }
export interface ILastMessageProps { export interface ILastMessageProps {
@ -154,5 +152,4 @@ export interface IIconOrAvatar {
teamMain: boolean; teamMain: boolean;
showLastMessage: boolean; showLastMessage: boolean;
sourceType: IOmnichannelSource; sourceType: IOmnichannelSource;
isUserProfile: boolean;
} }

View File

@ -1,8 +1,6 @@
import React from 'react'; import React from 'react';
import { Pressable, StyleProp, StyleSheet, Text, View, ViewStyle } from 'react-native'; 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 Avatar from './Avatar';
import { CustomIcon, TIconsName } from './CustomIcon'; import { CustomIcon, TIconsName } from './CustomIcon';
import sharedStyles from '../views/Styles'; import sharedStyles from '../views/Styles';
@ -45,12 +43,10 @@ interface IUserItem {
style?: StyleProp<ViewStyle>; style?: StyleProp<ViewStyle>;
icon?: TIconsName | null; icon?: TIconsName | null;
iconColor?: string; 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 { colors } = useTheme();
const { userId } = useAppSelector(state => ({ userId: getUserSelector(state).id }));
return ( return (
<Pressable <Pressable
@ -65,7 +61,7 @@ const UserItem = ({ name, username, onPress, testID, onLongPress, style, icon, i
})} })}
> >
<View style={[styles.container, styles.button, style]}> <View style={[styles.container, styles.button, style]}>
<Avatar text={username} size={30} style={styles.avatar} isUserProfile={userId === id} /> <Avatar text={username} size={30} style={styles.avatar} />
<View style={styles.textContainer}> <View style={styles.textContainer}>
<Text style={[styles.name, { color: colors.bodyText }]} numberOfLines={1}> <Text style={[styles.name, { color: colors.bodyText }]} numberOfLines={1}>
{name} {name}

View File

@ -20,7 +20,6 @@ const MessageAvatar = React.memo(({ isHeader, avatar, author, small, navToRoomIn
size={small ? 20 : 36} size={small ? 20 : 36}
borderRadius={small ? 2 : 4} borderRadius={small ? 2 : 4}
onPress={author._id === user.id ? undefined : () => navToRoomInfo(navParam)} onPress={author._id === user.id ? undefined : () => navToRoomInfo(navParam)}
isUserProfile={author._id === user.id}
getCustomEmoji={getCustomEmoji} getCustomEmoji={getCustomEmoji}
avatar={avatar} avatar={avatar}
emoji={emoji} emoji={emoji}

View File

@ -288,7 +288,7 @@ export default function subscribeRooms() {
const [type, data] = ddpMessage.fields.args; const [type, data] = ddpMessage.fields.args;
const [, ev] = ddpMessage.fields.eventName.split('/'); const [, ev] = ddpMessage.fields.eventName.split('/');
if (/userData/.test(ev)) { if (/userData/.test(ev)) {
const [{ diff, unset }] = ddpMessage.fields.args; const [{ diff }] = ddpMessage.fields.args;
if (diff?.statusLivechat) { if (diff?.statusLivechat) {
store.dispatch(setUser({ statusLivechat: diff.statusLivechat })); store.dispatch(setUser({ statusLivechat: diff.statusLivechat }));
} }
@ -298,12 +298,6 @@ export default function subscribeRooms() {
if ((['settings.preferences.alsoSendThreadToChannel'] as any) in diff) { if ((['settings.preferences.alsoSendThreadToChannel'] as any) in diff) {
store.dispatch(setUser({ alsoSendThreadToChannel: diff['settings.preferences.alsoSendThreadToChannel'] })); 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 (/subscriptions/.test(ev)) {
if (type === 'removed') { if (type === 'removed') {

View File

@ -152,7 +152,6 @@ const ChangeAvatarView = () => {
avatar={avatar?.url} avatar={avatar?.url}
isStatic={avatar?.url} isStatic={avatar?.url}
size={100} size={100}
isUserProfile={fromUser}
type={t} type={t}
{...ridProps} {...ridProps}
/> />

View File

@ -416,7 +416,6 @@ class ProfileView extends React.Component<IProfileViewProps, IProfileViewState>
avatarETag={user.avatarETag} avatarETag={user.avatarETag}
size={100} size={100}
handleEdit={Accounts_AllowUserAvatarChange ? this.handleEditAvatar : undefined} handleEdit={Accounts_AllowUserAvatarChange ? this.handleEditAvatar : undefined}
isUserProfile
/> />
</View> </View>
<FormTextInput <FormTextInput

View File

@ -935,7 +935,7 @@ class RoomsListView extends React.Component<IRoomsListViewProps, IRoomsListViewS
const { item: currentItem } = this.state; const { item: currentItem } = this.state;
const { const {
user: { username, id: userId }, user: { username },
StoreLastMessage, StoreLastMessage,
useRealName, useRealName,
isMasterDetail, isMasterDetail,
@ -945,7 +945,6 @@ class RoomsListView extends React.Component<IRoomsListViewProps, IRoomsListViewS
} = this.props; } = this.props;
const id = getUidDirectMessage(item); const id = getUidDirectMessage(item);
const swipeEnabled = this.isSwipeEnabled(item); const swipeEnabled = this.isSwipeEnabled(item);
const isUserProfile = id === userId;
return ( return (
<RoomItem <RoomItem
@ -966,7 +965,6 @@ class RoomsListView extends React.Component<IRoomsListViewProps, IRoomsListViewS
swipeEnabled={swipeEnabled} swipeEnabled={swipeEnabled}
showAvatar={showAvatar} showAvatar={showAvatar}
displayMode={displayMode} displayMode={displayMode}
isUserProfile={isUserProfile}
/> />
); );
}; };

View File

@ -251,7 +251,7 @@ class Sidebar extends Component<ISidebarProps, ISidebarState> {
> >
<TouchableWithoutFeedback onPress={this.onPressUser} testID='sidebar-close-drawer'> <TouchableWithoutFeedback onPress={this.onPressUser} testID='sidebar-close-drawer'>
<View style={styles.header}> <View style={styles.header}>
<Avatar text={user.username} style={styles.avatar} size={30} isUserProfile /> <Avatar text={user.username} style={styles.avatar} size={30} />
<View style={styles.headerTextContainer}> <View style={styles.headerTextContainer}>
<View style={styles.headerUsername}> <View style={styles.headerUsername}>
<Text numberOfLines={1} style={[styles.username, { color: themes[theme!].titleText }]}> <Text numberOfLines={1} style={[styles.username, { color: themes[theme!].titleText }]}>