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
3 changes: 3 additions & 0 deletions __tests__/Storyshots.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import initStoryshots from '@storybook/addon-storyshots';

jest.mock('../app/lib/database', () => jest.fn(() => null));
global.Date.now = jest.fn(() => new Date('2019-10-10').getTime());

initStoryshots();
7 changes: 5 additions & 2 deletions app/containers/Avatar/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const Avatar = React.memo(({
avatarETag,
isStatic,
rid,
blockUnauthenticatedAccess
blockUnauthenticatedAccess,
serverVersion
}) => {
if ((!text && !avatar && !emoji && !rid) || !server) {
return null;
Expand Down Expand Up @@ -60,6 +61,7 @@ const Avatar = React.memo(({
avatar,
server,
avatarETag,
serverVersion,
rid,
blockUnauthenticatedAccess
});
Expand Down Expand Up @@ -114,7 +116,8 @@ Avatar.propTypes = {
avatarETag: PropTypes.string,
isStatic: PropTypes.bool,
rid: PropTypes.string,
blockUnauthenticatedAccess: PropTypes.bool
blockUnauthenticatedAccess: PropTypes.bool,
serverVersion: PropTypes.string
};

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

static defaultProps = {
Expand Down Expand Up @@ -83,9 +84,11 @@ class AvatarContainer extends React.Component {

render() {
const { avatarETag } = this.state;
const { serverVersion } = this.props;
return (
<Avatar
avatarETag={avatarETag}
serverVersion={serverVersion}
{...this.props}
/>
);
Expand All @@ -94,7 +97,8 @@ class AvatarContainer extends React.Component {

const mapStateToProps = state => ({
user: getUserSelector(state),
server: state.share.server || state.server.server,
server: state.share.server.server || state.server.server,
serverVersion: state.share.server.version || state.server.version,
blockUnauthenticatedAccess:
state.share.settings?.Accounts_AvatarBlockUnauthenticatedAccess
?? state.settings.Accounts_AvatarBlockUnauthenticatedAccess
Expand Down
2 changes: 1 addition & 1 deletion app/containers/MessageBox/EmojiKeyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class EmojiKeyboard extends React.PureComponent {
constructor(props) {
super(props);
const state = store.getState();
this.baseUrl = state.share.server || state.server.server;
this.baseUrl = state.share.server.server || state.server.server;
}

onEmojiSelected = (emoji) => {
Expand Down
7 changes: 2 additions & 5 deletions app/containers/message/MessageAvatar.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useContext } from 'react';
import PropTypes from 'prop-types';

import Avatar from '../Avatar/Avatar';
import Avatar from '../Avatar';
import styles from './styles';
import MessageContext from './Context';

const MessageAvatar = React.memo(({
isHeader, avatar, author, small, navToRoomInfo, emoji, getCustomEmoji, theme
}) => {
const { baseUrl, user } = useContext(MessageContext);
const { user } = useContext(MessageContext);
if (isHeader && author) {
const navParam = {
t: 'd',
Expand All @@ -22,9 +22,6 @@ const MessageAvatar = React.memo(({
borderRadius={small ? 2 : 4}
onPress={author._id === user.id ? undefined : () => navToRoomInfo(navParam)}
getCustomEmoji={getCustomEmoji}
user={user}
server={baseUrl}
avatarETag={author.avatarETag}
avatar={avatar}
emoji={emoji}
theme={theme}
Expand Down
26 changes: 2 additions & 24 deletions app/containers/message/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { SYSTEM_MESSAGES, getMessageTranslation } from './utils';
import { E2E_MESSAGE_TYPE, E2E_STATUS } from '../../lib/encryption/constants';
import messagesStatus from '../../constants/messagesStatus';
import { withTheme } from '../../theme';
import database from '../../lib/database';

class MessageContainer extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -74,31 +73,14 @@ class MessageContainer extends React.Component {
theme: 'light'
}

state = {
author: null
}

async componentDidMount() {
componentDidMount() {
const { item } = this.props;
if (item && item.observe) {
const observable = item.observe();
this.subscription = observable.subscribe(() => {
this.forceUpdate();
});
}

const db = database.active;
const usersCollection = db.collections.get('users');
try {
const user = await usersCollection.find(item.u?._id);
const observable = user.observe();
this.userSubscription = observable.subscribe((author) => {
this.setState({ author });
this.forceUpdate();
});
} catch {
// Do nothing
}
}

shouldComponentUpdate(nextProps) {
Expand All @@ -113,9 +95,6 @@ class MessageContainer extends React.Component {
if (this.subscription && this.subscription.unsubscribe) {
this.subscription.unsubscribe();
}
if (this.userSubscription && this.userSubscription.unsubscribe) {
this.userSubscription.unsubscribe();
}
}

onPress = debounce(() => {
Expand Down Expand Up @@ -264,7 +243,6 @@ class MessageContainer extends React.Component {
}

render() {
const { author } = this.state;
const {
item, user, style, archived, baseUrl, useRealName, broadcast, fetchThreadName, showAttachment, timeFormat, isReadReceiptEnabled, autoTranslateRoom, autoTranslateLanguage, navToRoomInfo, getCustomEmoji, isThreadRoom, callJitsi, blockAction, rid, theme, getBadgeColor, toggleFollowThread
} = this.props;
Expand Down Expand Up @@ -302,7 +280,7 @@ class MessageContainer extends React.Component {
id={id}
msg={message}
rid={rid}
author={author || u}
author={u}
ts={ts}
type={t}
attachments={attachments}
Expand Down
2 changes: 1 addition & 1 deletion app/i18n/locales/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ export default {
Logout_failed: 'Выход не успешен!',
Log_analytics_events: 'Журнал событий аналитики',
E2E_encryption_change_password_title: 'Изменить пароль шифрования',
E2E_encryption_change_password_description: 'Теперь вы можете создавать зашифрованные прватные чаты и личные беседы. Вы так же можете сделать существующие приватные чаты и личные беседы шифрованными. \nЭто сквозное шифрование, поэтому ключь для шифрования\дешифрования ваших сообщений не будет сохранен на сервере. Именно поэтому вам необходимо сохранить ваш пароль в надежном и безопасном месте. Вам необходимо вводить этот пароль на всех устройствах, где вы хотите использовать E2E шифрование.',
E2E_encryption_change_password_description: 'Теперь вы можете создавать зашифрованные прватные чаты и личные беседы. Вы так же можете сделать существующие приватные чаты и личные беседы шифрованными. \nЭто сквозное шифрование, поэтому ключь для шифрования\nдешифрования ваших сообщений не будет сохранен на сервере. Именно поэтому вам необходимо сохранить ваш пароль в надежном и безопасном месте. Вам необходимо вводить этот пароль на всех устройствах, где вы хотите использовать E2E шифрование.',
E2E_encryption_change_password_error: 'Ошибка при смене пароля E2E ключа!',
E2E_encryption_change_password_success: 'Пароль ключа E2E изменен успешно!',
E2E_encryption_change_password_message: 'Убедитесь, что вы сохранили пароль в надежном мпсте.',
Expand Down
11 changes: 10 additions & 1 deletion app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,16 @@ const RocketChat = {
this.shareSDK = new RocketchatClient({ host: server, protocol: 'ddp', useSsl: useSsl(server) });

// set Server
const currentServer = { server };
const serversDB = database.servers;
reduxStore.dispatch(shareSelectServer(server));
const serversCollection = serversDB.collections.get('servers');
try {
const serverRecord = await serversCollection.find(server);
currentServer.version = serverRecord.version;
} catch {
// Record not found
}
reduxStore.dispatch(shareSelectServer(currentServer));

RocketChat.setCustomEmojis();

Expand Down Expand Up @@ -368,6 +376,7 @@ const RocketChat = {
}
database.share = null;

reduxStore.dispatch(shareSelectServer({}));
reduxStore.dispatch(shareSetUser({}));
reduxStore.dispatch(shareSetSettings({}));
},
Expand Down
16 changes: 2 additions & 14 deletions app/presentation/RoomItem/RoomItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ const RoomItem = ({
avatar,
width,
avatarSize,
baseUrl,
userId,
username,
token,
showLastMessage,
status,
useRealName,
Expand All @@ -48,8 +45,7 @@ const RoomItem = ({
onPress,
toggleFav,
toggleRead,
hideChannel,
avatarETag
hideChannel
}) => (
<Touchable
onPress={onPress}
Expand All @@ -70,11 +66,7 @@ const RoomItem = ({
accessibilityLabel={accessibilityLabel}
avatar={avatar}
avatarSize={avatarSize}
avatarETag={avatarETag}
type={type}
baseUrl={baseUrl}
userId={userId}
token={token}
theme={theme}
rid={rid}
>
Expand Down Expand Up @@ -160,11 +152,8 @@ RoomItem.propTypes = {
prid: PropTypes.string,
name: PropTypes.string.isRequired,
avatar: PropTypes.string.isRequired,
baseUrl: PropTypes.string.isRequired,
showLastMessage: PropTypes.bool,
userId: PropTypes.string,
username: PropTypes.string,
token: PropTypes.string,
avatarSize: PropTypes.number,
testID: PropTypes.string,
width: PropTypes.number,
Expand All @@ -191,8 +180,7 @@ RoomItem.propTypes = {
toggleFav: PropTypes.func,
toggleRead: PropTypes.func,
onPress: PropTypes.func,
hideChannel: PropTypes.func,
avatarETag: PropTypes.string
hideChannel: PropTypes.func
};

RoomItem.defaultProps = {
Expand Down
13 changes: 1 addition & 12 deletions app/presentation/RoomItem/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import PropTypes from 'prop-types';

import styles from './styles';
import { themes } from '../../constants/colors';
import Avatar from '../../containers/Avatar/Avatar';
import Avatar from '../../containers/Avatar';

const Wrapper = ({
accessibilityLabel,
avatar,
avatarSize,
avatarETag,
type,
baseUrl,
userId,
token,
theme,
rid,
children
Expand All @@ -28,9 +24,6 @@ const Wrapper = ({
size={avatarSize}
type={type}
style={styles.avatar}
server={baseUrl}
user={{ id: userId, token }}
avatarETag={avatarETag}
rid={rid}
/>
<View
Expand All @@ -50,11 +43,7 @@ Wrapper.propTypes = {
accessibilityLabel: PropTypes.string,
avatar: PropTypes.string,
avatarSize: PropTypes.number,
avatarETag: PropTypes.string,
type: PropTypes.string,
baseUrl: PropTypes.string,
userId: PropTypes.string,
token: PropTypes.string,
theme: PropTypes.string,
rid: PropTypes.string,
children: PropTypes.element
Expand Down
Loading