Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/actions/actionsTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const LOGIN = createRequestTypes('LOGIN', [
export const SHARE = createRequestTypes('SHARE', [
'SELECT_SERVER',
'SET_USER',
'SET_SETTINGS',
'SET_SERVER_INFO'
]);
export const USER = createRequestTypes('USER', ['SET']);
Expand Down
7 changes: 7 additions & 0 deletions app/actions/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ export function shareSelectServer(server) {
};
}

export function shareSetSettings(settings) {
return {
type: SHARE.SET_SETTINGS,
settings
};
}

export function shareSetUser(user) {
return {
type: SHARE.SET_USER,
Expand Down
3 changes: 3 additions & 0 deletions app/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default {
Accounts_AllowUsernameChange: {
type: 'valueAsBoolean'
},
Accounts_AvatarBlockUnauthenticatedAccess: {
type: 'valueAsBoolean'
},
Accounts_CustomFields: {
type: 'valueAsString'
},
Expand Down
9 changes: 6 additions & 3 deletions app/containers/Avatar/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const Avatar = React.memo(({
getCustomEmoji,
avatarETag,
isStatic,
rid
rid,
blockUnauthenticatedAccess
}) => {
if ((!text && !avatar && !emoji && !rid) || !server) {
return null;
Expand Down Expand Up @@ -59,7 +60,8 @@ const Avatar = React.memo(({
avatar,
server,
avatarETag,
rid
rid,
blockUnauthenticatedAccess
});
}

Expand Down Expand Up @@ -111,7 +113,8 @@ Avatar.propTypes = {
getCustomEmoji: PropTypes.func,
avatarETag: PropTypes.string,
isStatic: PropTypes.bool,
rid: PropTypes.string
rid: PropTypes.string,
blockUnauthenticatedAccess: PropTypes.bool
};

Avatar.defaultProps = {
Expand Down
9 changes: 7 additions & 2 deletions app/containers/Avatar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class AvatarContainer extends React.Component {
static propTypes = {
rid: PropTypes.string,
text: PropTypes.string,
type: PropTypes.string
type: PropTypes.string,
blockUnauthenticatedAccess: PropTypes.bool
};

static defaultProps = {
Expand Down Expand Up @@ -93,6 +94,10 @@ class AvatarContainer extends React.Component {

const mapStateToProps = state => ({
user: getUserSelector(state),
server: state.share.server || state.server.server
server: state.share.server || state.server.server,
blockUnauthenticatedAccess:
state.share.settings?.Accounts_AvatarBlockUnauthenticatedAccess
?? state.settings.Accounts_AvatarBlockUnauthenticatedAccess
?? true
});
export default connect(mapStateToProps)(AvatarContainer);
1 change: 1 addition & 0 deletions app/lib/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class DB {
Permission,
CustomEmoji,
FrequentlyUsedEmoji,
Setting,
User
],
actionsEnabled: true
Expand Down
22 changes: 18 additions & 4 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import fetch from '../utils/fetch';
import { encryptionInit } from '../actions/encryption';
import { setUser, setLoginServices, loginRequest } from '../actions/login';
import { disconnect, connectSuccess, connectRequest } from '../actions/connect';
import {
shareSelectServer, shareSetUser
} from '../actions/share';
import { shareSelectServer, shareSetUser, shareSetSettings } from '../actions/share';

import subscribeRooms from './methods/subscriptions/rooms';
import getUsersPresence, { getUserPresence, subscribeUsersPresence } from './methods/getUsersPresence';
Expand Down Expand Up @@ -324,8 +322,23 @@ const RocketChat = {

RocketChat.setCustomEmojis();

// set User info
try {
// set Settings
const settings = ['Accounts_AvatarBlockUnauthenticatedAccess'];
const db = database.active;
const settingsCollection = db.collections.get('settings');
const settingsRecords = await settingsCollection.query(Q.where('id', Q.oneOf(settings))).fetch();
const parsed = Object.values(settingsRecords).map(item => ({
_id: item.id,
valueAsString: item.valueAsString,
valueAsBoolean: item.valueAsBoolean,
valueAsNumber: item.valueAsNumber,
valueAsArray: item.valueAsArray,
_updatedAt: item._updatedAt
}));
reduxStore.dispatch(shareSetSettings(this.parseSettings(parsed)));

// set User info
const userId = await UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`);
const userCollections = serversDB.collections.get('users');
let user = null;
Expand Down Expand Up @@ -353,6 +366,7 @@ const RocketChat = {
database.share = null;

reduxStore.dispatch(shareSetUser({}));
reduxStore.dispatch(shareSetSettings({}));
},

async e2eFetchMyKeys() {
Expand Down
8 changes: 7 additions & 1 deletion app/reducers/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { SHARE } from '../actions/actionsTypes';

const initialState = {
user: {},
server: ''
server: '',
settings: {}
};

export default function share(state = initialState, action) {
Expand All @@ -17,6 +18,11 @@ export default function share(state = initialState, action) {
...state,
user: action.user
};
case SHARE.SET_SETTINGS:
return {
...state,
settings: action.settings
};
default:
return state;
}
Expand Down
4 changes: 2 additions & 2 deletions app/utils/avatar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const formatUrl = (url, size, query) => `${ url }?format=png&size=${ size }${ query }`;

export const avatarURL = ({
type, text, size, user = {}, avatar, server, avatarETag, rid
type, text, size, user = {}, avatar, server, avatarETag, rid, blockUnauthenticatedAccess
}) => {
let room;
if (type === 'd') {
Expand All @@ -16,7 +16,7 @@ export const avatarURL = ({

const { id, token } = user;
let query = '';
if (id && token) {
if (id && token && blockUnauthenticatedAccess) {
query += `&rc_token=${ token }&rc_uid=${ id }`;
}
if (avatarETag) {
Expand Down
6 changes: 4 additions & 2 deletions app/views/CreateDiscussionView/SelectChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { themes } from '../../constants/colors';
import styles from './styles';

const SelectChannel = ({
server, token, userId, onChannelSelect, initial, theme
server, token, userId, onChannelSelect, initial, blockUnauthenticatedAccess, theme
}) => {
const [channels, setChannels] = useState([]);

Expand All @@ -31,7 +31,8 @@ const SelectChannel = ({
user: { id: userId, token },
server,
avatarETag: item.avatarETag,
rid: item.rid
rid: item.rid,
blockUnauthenticatedAccess
});

return (
Expand Down Expand Up @@ -61,6 +62,7 @@ SelectChannel.propTypes = {
userId: PropTypes.string,
initial: PropTypes.object,
onChannelSelect: PropTypes.func,
blockUnauthenticatedAccess: PropTypes.bool,
theme: PropTypes.string
};

Expand Down
10 changes: 8 additions & 2 deletions app/views/CreateDiscussionView/SelectUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import styles from './styles';
import { themes } from '../../constants/colors';

const SelectUsers = ({
server, token, userId, selected, onUserSelect, theme
server, token, userId, selected, onUserSelect, blockUnauthenticatedAccess, theme
}) => {
const [users, setUsers] = useState([]);

Expand Down Expand Up @@ -48,7 +48,12 @@ const SelectUsers = ({
}, 300);

const getAvatar = item => avatarURL({
text: RocketChat.getRoomAvatar(item), type: 'd', user: { id: userId, token }, server, avatarETag: item.avatarETag
text: RocketChat.getRoomAvatar(item),
type: 'd',
user: { id: userId, token },
server,
avatarETag: item.avatarETag,
blockUnauthenticatedAccess
});

return (
Expand Down Expand Up @@ -78,6 +83,7 @@ SelectUsers.propTypes = {
userId: PropTypes.string,
selected: PropTypes.array,
onUserSelect: PropTypes.func,
blockUnauthenticatedAccess: PropTypes.bool,
theme: PropTypes.string
};

Expand Down
8 changes: 6 additions & 2 deletions app/views/CreateDiscussionView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class CreateChannelView extends React.Component {
failure: PropTypes.bool,
error: PropTypes.object,
theme: PropTypes.string,
isMasterDetail: PropTypes.bool
isMasterDetail: PropTypes.bool,
blockUnauthenticatedAccess: PropTypes.bool
}

constructor(props) {
Expand Down Expand Up @@ -143,7 +144,7 @@ class CreateChannelView extends React.Component {
render() {
const { name, users } = this.state;
const {
server, user, loading, theme
server, user, loading, blockUnauthenticatedAccess, theme
} = this.props;
return (
<KeyboardView
Expand All @@ -161,6 +162,7 @@ class CreateChannelView extends React.Component {
token={user.token}
initial={this.channel && { text: RocketChat.getRoomTitle(this.channel) }}
onChannelSelect={this.selectChannel}
blockUnauthenticatedAccess={blockUnauthenticatedAccess}
theme={theme}
/>
<TextInput
Expand All @@ -177,6 +179,7 @@ class CreateChannelView extends React.Component {
token={user.token}
selected={users}
onUserSelect={this.selectUsers}
blockUnauthenticatedAccess={blockUnauthenticatedAccess}
theme={theme}
/>
<TextInput
Expand All @@ -203,6 +206,7 @@ const mapStateToProps = state => ({
failure: state.createDiscussion.failure,
loading: state.createDiscussion.isFetching,
result: state.createDiscussion.result,
blockUnauthenticatedAccess: state.settings.Accounts_AvatarBlockUnauthenticatedAccess ?? true,
isMasterDetail: state.app.isMasterDetail
});

Expand Down
5 changes: 4 additions & 1 deletion app/views/ShareListView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ class ShareListView extends React.Component {
return true;
}

const { server, theme } = this.props;
const { server, theme, userId } = this.props;
if (server !== nextProps.server) {
return true;
}
if (userId !== nextProps.userId) {
return true;
}
if (theme !== nextProps.theme) {
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions storybook/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const reducers = combineReducers({
username: 'diego.mello'
}
}),
share: () => ({ settings: {} }),
meteor: () => ({ connected: true }),
activeUsers: () => ({ abc: { status: 'online', statusText: 'dog' } })
});
Expand Down Expand Up @@ -61,6 +62,7 @@ storiesOf('RoomItem', module)
.addDecorator(story => <Provider store={store}>{story()}</Provider>)
.add('list roomitem', () => <RoomItem theme={theme} />);
storiesOf('Message', module)
.addDecorator(story => <Provider store={store}>{story()}</Provider>)
.addDecorator(messageDecorator)
.add('list message', () => <Message theme={theme} />);

Expand Down