-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[FIX] Avatar cache invalidation #2311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
8d8a1d7
[WIP] Avatar cache invalidation
djorkaeffalexandre c10d857
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre ba0e3dd
[WIP] Avatar container
djorkaeffalexandre 78f8198
[IMPROVEMENT] Avatar container
djorkaeffalexandre a053698
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre b64eb53
[CHORE] Improve code
djorkaeffalexandre ec82478
Merge develop
djorkaeffalexandre be8f178
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre 7191240
Allow static image on Avatar
djorkaeffalexandre ff73068
Fix avatar changing while change username (#1583)
djorkaeffalexandre b8041fa
Add default props to properly update on Sidebar and ProfileView
djorkaeffalexandre b1c46e6
Fix subscribing on the wrong moment
djorkaeffalexandre 9eaf2ae
Storyshots update
djorkaeffalexandre 87eb1eb
Merge develop
djorkaeffalexandre 9ce6eb1
RoomItem using Avatar Component
djorkaeffalexandre 1649d3a
Merge develop
djorkaeffalexandre 0bf5551
use iife to unsubscribe from user
djorkaeffalexandre 441ad88
Use component on avatar container
djorkaeffalexandre 0ae1114
RoomItem as a React.Component
djorkaeffalexandre c1ecd07
Move servers models to servers folder
djorkaeffalexandre 6a81401
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre 7caa0e0
Avatar -> AvatarContainer
djorkaeffalexandre 739836e
Users indexed fields
djorkaeffalexandre c6ffbf7
Initialize author and check if u is present
djorkaeffalexandre df75c65
Not was found -> User not found (turn comments more relevant)
djorkaeffalexandre c0c61ea
RoomItemInner -> Wrapper
djorkaeffalexandre 78b7767
Revert Avatar Touchable logic
djorkaeffalexandre 19b12fd
Revert responsability of LeftButton on Tablet Mode
djorkaeffalexandre 615c5c7
Prevent setState on constructor
djorkaeffalexandre 95e49c8
Run avatarURL only when its not static
djorkaeffalexandre e39c08e
Add streams RC Version
djorkaeffalexandre ddb41ea
Move entire add user logic to result.success
djorkaeffalexandre 94d7f09
Reorder init on RoomItem
djorkaeffalexandre 92eac28
onPress as a class function
djorkaeffalexandre f63738b
Fix roomItem using same username
djorkaeffalexandre ef0a261
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre b4401d3
Merge branch 'develop' into fix.avatar-cache-invalidation
diegolmello f602fb4
Add avatar Stories
djorkaeffalexandre e34c49b
Merge branch 'fix.avatar-cache-invalidation' of https://github.com/Ro…
djorkaeffalexandre f72d272
Fix pick an image from gallery on ProfileView
djorkaeffalexandre 8f88836
merge develop
djorkaeffalexandre 2142fe7
Merge branch 'develop' into fix.avatar-cache-invalidation
djorkaeffalexandre d880f36
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre 5471d17
get avatar etag on select users of create discussion
djorkaeffalexandre a412d58
Merge branch 'fix.avatar-cache-invalidation' of https://github.com/Ro…
djorkaeffalexandre 4eb7cb2
invalidate ci cache
djorkaeffalexandre e5d3138
Merge branch 'develop' into fix.avatar-cache-invalidation
diegolmello 2ffc269
Fix migration
diegolmello 53794d6
Fix sidebar avatar not updating
diegolmello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import FastImage from '@rocket.chat/react-native-fast-image'; | ||
| import Touchable from 'react-native-platform-touchable'; | ||
| import { settings as RocketChatSettings } from '@rocket.chat/sdk'; | ||
|
|
||
| import { avatarURL } from '../../utils/avatar'; | ||
| import Emoji from '../markdown/Emoji'; | ||
|
|
||
| const Avatar = React.memo(({ | ||
| text, | ||
| size, | ||
| server, | ||
| borderRadius, | ||
| style, | ||
| avatar, | ||
| type, | ||
| children, | ||
| user, | ||
| onPress, | ||
| emoji, | ||
| theme, | ||
| getCustomEmoji, | ||
| avatarETag, | ||
| isStatic | ||
| }) => { | ||
| if ((!text && !avatar) || !server) { | ||
| return null; | ||
| } | ||
|
|
||
| const avatarStyle = { | ||
| width: size, | ||
| height: size, | ||
| borderRadius | ||
| }; | ||
|
|
||
| let image; | ||
| if (emoji) { | ||
| image = ( | ||
| <Emoji | ||
| theme={theme} | ||
| baseUrl={server} | ||
| getCustomEmoji={getCustomEmoji} | ||
| isMessageContainsOnlyEmoji | ||
| literal={emoji} | ||
| /> | ||
| ); | ||
| } else { | ||
| const uri = avatarURL({ | ||
| type, | ||
| text, | ||
| size, | ||
| user, | ||
| avatar, | ||
| server, | ||
| avatarETag | ||
| }); | ||
|
|
||
| image = ( | ||
| <FastImage | ||
| style={avatarStyle} | ||
| source={{ | ||
| uri: isStatic ? avatar : uri, | ||
| headers: RocketChatSettings.customHeaders, | ||
| priority: FastImage.priority.high | ||
| }} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| return ( | ||
|
djorkaeffalexandre marked this conversation as resolved.
|
||
| <Touchable style={[avatarStyle, style]} disabled={!onPress} onPress={onPress}> | ||
| <> | ||
| {image} | ||
| {children} | ||
| </> | ||
| </Touchable> | ||
| ); | ||
| }); | ||
|
|
||
| Avatar.propTypes = { | ||
| server: PropTypes.string, | ||
| style: PropTypes.any, | ||
| text: PropTypes.string, | ||
| avatar: PropTypes.string, | ||
| emoji: PropTypes.string, | ||
| size: PropTypes.number, | ||
| borderRadius: PropTypes.number, | ||
| type: PropTypes.string, | ||
| children: PropTypes.object, | ||
| user: PropTypes.shape({ | ||
| id: PropTypes.string, | ||
| token: PropTypes.string | ||
| }), | ||
| theme: PropTypes.string, | ||
| onPress: PropTypes.func, | ||
| getCustomEmoji: PropTypes.func, | ||
| avatarETag: PropTypes.string, | ||
| isStatic: PropTypes.bool | ||
| }; | ||
|
|
||
| Avatar.defaultProps = { | ||
| text: '', | ||
| size: 25, | ||
| type: 'd', | ||
| borderRadius: 4 | ||
| }; | ||
|
|
||
| export default Avatar; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import React, { useEffect, useState } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { connect } from 'react-redux'; | ||
| import { Q } from '@nozbe/watermelondb'; | ||
|
|
||
| import database from '../../lib/database'; | ||
| import { getUserSelector } from '../../selectors/login'; | ||
| import Component from './Avatar'; | ||
|
djorkaeffalexandre marked this conversation as resolved.
Outdated
|
||
|
|
||
| const Avatar = React.memo(({ type, text, ...props }) => { | ||
| const [avatarETag, setAvatarETag] = useState(); | ||
|
|
||
| useEffect(() => { | ||
| let subscription; | ||
| (async() => { | ||
|
djorkaeffalexandre marked this conversation as resolved.
Outdated
|
||
| if (type === 'd') { | ||
| const db = database.active; | ||
| const usersCollection = db.collections.get('users'); | ||
| try { | ||
| const [userRecord] = await usersCollection.query(Q.where('username', text)).fetch(); | ||
| if (userRecord) { | ||
| const observable = userRecord.observe(); | ||
| subscription = observable.subscribe((u) => { | ||
| setAvatarETag(u.avatarETag); | ||
| }); | ||
| } | ||
| } catch { | ||
| // Do nothing | ||
| } | ||
| } | ||
| })(); | ||
| return () => { | ||
| subscription?.unsubscribe?.(); | ||
| }; | ||
| }, []); | ||
|
|
||
| return ( | ||
| <Component | ||
| text={text} | ||
| type={type} | ||
| avatarETag={avatarETag} | ||
| {...props} | ||
| /> | ||
| ); | ||
| }); | ||
| Avatar.propTypes = { | ||
| text: PropTypes.string, | ||
| type: PropTypes.string | ||
| }; | ||
| Avatar.defaultProps = { | ||
| text: '', | ||
| type: 'd' | ||
| }; | ||
|
|
||
| const mapStateToProps = state => ({ | ||
| user: getUserSelector(state), | ||
| server: state.share.server || state.server.server | ||
| }); | ||
| export default connect(mapStateToProps)(Avatar); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.