Finished the profile and fixed the avatar when change the user profile

This commit is contained in:
Reinaldo Neto 2022-12-09 18:29:16 -03:00
parent 90984de444
commit a283f41022
5 changed files with 25 additions and 9 deletions

View File

@ -26,8 +26,9 @@ const AvatarContainer = ({
getCustomEmoji, getCustomEmoji,
isStatic, isStatic,
rid, rid,
handleEdit handleEdit,
}: IAvatar & { handleEdit?: () => void }): React.ReactElement => { isUserProfile
}: IAvatar & { isUserProfile?: boolean; handleEdit?: () => void }): React.ReactElement => {
const subscription = useRef<Subscription>(); const subscription = useRef<Subscription>();
const [avatarETag, setAvatarETag] = useState<string | undefined>(''); const [avatarETag, setAvatarETag] = useState<string | undefined>('');
const { colors } = useTheme(); const { colors } = useTheme();
@ -36,10 +37,11 @@ const AvatarContainer = ({
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 } = useSelector( const { id, token, avatarETagUser } = 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
}), }),
shallowEqual shallowEqual
); );
@ -110,7 +112,7 @@ const AvatarContainer = ({
rid={rid} rid={rid}
blockUnauthenticatedAccess={blockUnauthenticatedAccess} blockUnauthenticatedAccess={blockUnauthenticatedAccess}
externalProviderUrl={externalProviderUrl} externalProviderUrl={externalProviderUrl}
avatarETag={avatarETag} avatarETag={isUserProfile ? avatarETagUser : avatarETag}
serverVersion={serverVersion} serverVersion={serverVersion}
/> />
{handleEdit ? ( {handleEdit ? (

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 }] = ddpMessage.fields.args; const [{ diff, unset }] = ddpMessage.fields.args;
if (diff?.statusLivechat) { if (diff?.statusLivechat) {
store.dispatch(setUser({ statusLivechat: diff.statusLivechat })); store.dispatch(setUser({ statusLivechat: diff.statusLivechat }));
} }
@ -298,6 +298,12 @@ 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

@ -158,11 +158,17 @@ const ChangeAvatarView = () => {
{...scrollPersistTaps} {...scrollPersistTaps}
> >
<View style={styles.avatarContainer} testID='change-avatar-view-avatar'> <View style={styles.avatarContainer} testID='change-avatar-view-avatar'>
<Avatar text={textAvatar || user.username} avatar={avatar?.url} isStatic={avatar?.url} size={100} /> <Avatar
text={textAvatar || user.username}
avatar={avatar?.url}
isStatic={avatar?.url}
size={100}
isUserProfile={fromUser}
/>
</View> </View>
<AvatarUrl submit={value => setAvatar({ url: value, data: value, service: 'url' })} /> <AvatarUrl submit={value => setAvatar({ url: value, data: value, service: 'url' })} />
<List.Separator style={styles.separator} /> <List.Separator style={styles.separator} />
{fromUser && avatarSuggestions.length ? ( {fromUser ? (
<AvatarSuggestion resetAvatar={resetAvatar} user={user} onPress={setAvatar} avatarSuggestions={avatarSuggestions} /> <AvatarSuggestion resetAvatar={resetAvatar} user={user} onPress={setAvatar} avatarSuggestions={avatarSuggestions} />
) : null} ) : null}

View File

@ -413,8 +413,10 @@ class ProfileView extends React.Component<IProfileViewProps, IProfileViewState>
<View style={styles.avatarContainer} testID='profile-view-avatar'> <View style={styles.avatarContainer} testID='profile-view-avatar'>
<Avatar <Avatar
text={user.username} text={user.username}
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

@ -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} /> <Avatar text={user.username} style={styles.avatar} size={30} isUserProfile />
<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 }]}>