Update JS SDK version (#602)
This commit is contained in:
parent
d26f14d155
commit
2585038112
|
@ -14,26 +14,33 @@ jobs:
|
|||
steps:
|
||||
- checkout
|
||||
|
||||
- restore_cache:
|
||||
key: node-modules-{{ checksum ".circleci/config.yml" }}-{{ checksum "yarn.lock" }}
|
||||
|
||||
- run:
|
||||
name: Install NPM modules
|
||||
command: |
|
||||
npm install
|
||||
# npm install codecov
|
||||
yarn
|
||||
|
||||
- run:
|
||||
name: Lint
|
||||
command: |
|
||||
npm run lint
|
||||
yarn lint
|
||||
|
||||
- run:
|
||||
name: Test
|
||||
command: |
|
||||
npm run test
|
||||
yarn test
|
||||
|
||||
- run:
|
||||
name: Codecov
|
||||
command: |
|
||||
npx codecov
|
||||
yarn codecov
|
||||
|
||||
- save_cache:
|
||||
key: node-modules-{{ checksum ".circleci/config.yml" }}-{{ checksum "yarn.lock" }}
|
||||
paths:
|
||||
- ./node_modules
|
||||
|
||||
e2e-test:
|
||||
macos:
|
||||
|
@ -64,9 +71,8 @@ jobs:
|
|||
- run:
|
||||
name: Install NPM modules
|
||||
command: |
|
||||
rm -rf node_modules
|
||||
npm install
|
||||
npm install -g detox-cli
|
||||
yarn global add detox-cli
|
||||
yarn
|
||||
|
||||
- run:
|
||||
name: Build
|
||||
|
@ -96,20 +102,13 @@ jobs:
|
|||
steps:
|
||||
- checkout
|
||||
|
||||
# - run:
|
||||
# name: Install Node 8
|
||||
# command: |
|
||||
# curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
|
||||
# source ~/.nvm/nvm.sh
|
||||
# nvm install 8
|
||||
|
||||
- restore_cache:
|
||||
key: node-modules-{{ checksum ".circleci/config.yml" }}-{{ checksum "package-lock.json" }}
|
||||
key: node-modules-{{ checksum ".circleci/config.yml" }}-{{ checksum "yarn.lock" }}
|
||||
|
||||
- run:
|
||||
name: Install NPM modules
|
||||
command: |
|
||||
npm install
|
||||
yarn
|
||||
|
||||
- restore_cache:
|
||||
key: android-{{ checksum ".circleci/config.yml" }}-{{ checksum "android/build.gradle" }}-{{ checksum "android/app/build.gradle" }}
|
||||
|
@ -162,7 +161,7 @@ jobs:
|
|||
path: /tmp/build/outputs
|
||||
|
||||
- save_cache:
|
||||
key: node-modules-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}
|
||||
key: node-modules-{{ checksum ".circleci/config.yml" }}-{{ checksum "yarn.lock" }}
|
||||
paths:
|
||||
- ./node_modules
|
||||
|
||||
|
@ -200,8 +199,7 @@ jobs:
|
|||
- run:
|
||||
name: Install NPM modules
|
||||
command: |
|
||||
rm -rf node_modules
|
||||
npm install
|
||||
yarn
|
||||
|
||||
- run:
|
||||
name: Fix known build error
|
||||
|
|
12
README.md
12
README.md
|
@ -27,16 +27,16 @@ Follow the [React Native Getting Started Guide](https://facebook.github.io/react
|
|||
```bash
|
||||
$ git clone git@github.com:RocketChat/Rocket.Chat.ReactNative.git
|
||||
$ cd Rocket.Chat.ReactNative
|
||||
$ npm install -g react-native-cli
|
||||
$ npm install
|
||||
$ yarn global add react-native-cli
|
||||
$ yarn
|
||||
```
|
||||
|
||||
- Run application
|
||||
```bash
|
||||
$ npm run ios
|
||||
$ yarn ios
|
||||
```
|
||||
```bash
|
||||
$ npm run android
|
||||
$ yarn android
|
||||
```
|
||||
|
||||
### Running single server
|
||||
|
@ -221,13 +221,13 @@ $ detox test
|
|||
- General requirements
|
||||
- Install storybook
|
||||
```bash
|
||||
$ npm i -g @storybook/cli
|
||||
$ yarn global add @storybook/cli
|
||||
```
|
||||
|
||||
- Running storybook
|
||||
- Run storybook application
|
||||
```bash
|
||||
$ npm run storybook
|
||||
$ yarn storybook
|
||||
```
|
||||
- Run application in other shell
|
||||
```bash
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export default {
|
||||
getModel: () => '',
|
||||
getReadableVersion: () => ''
|
||||
getReadableVersion: () => '',
|
||||
getBundleId: () => ''
|
||||
};
|
||||
|
|
|
@ -58,7 +58,8 @@ export default class EmojiCategory extends React.Component {
|
|||
testID={`reaction-picker-${ emoji.isCustom ? emoji.content : emoji }`}
|
||||
>
|
||||
{renderEmoji(emoji, size, baseUrl)}
|
||||
</TouchableOpacity>);
|
||||
</TouchableOpacity>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
@ -148,6 +148,7 @@ export default class extends React.PureComponent {
|
|||
/>
|
||||
</BorderlessButton>
|
||||
</View>
|
||||
</SafeAreaView>);
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import database from '../realm';
|
||||
|
||||
const restTypes = {
|
||||
|
@ -9,7 +7,7 @@ const restTypes = {
|
|||
async function open({ type, rid }) {
|
||||
try {
|
||||
// RC 0.61.0
|
||||
await SDK.api.post(`${ restTypes[type] }.open`, { roomId: rid });
|
||||
await this.sdk.post(`${ restTypes[type] }.open`, { roomId: rid });
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (e.data && /is already open/.test(e.data.error)) {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { InteractionManager } from 'react-native';
|
||||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import reduxStore from '../createStore';
|
||||
|
||||
import database from '../realm';
|
||||
import * as actions from '../../actions';
|
||||
import log from '../../utils/log';
|
||||
|
@ -17,7 +15,7 @@ export default async function() {
|
|||
try {
|
||||
const lastMessage = getLastMessage();
|
||||
// RC 0.61.0
|
||||
const result = await SDK.api.get('emoji-custom');
|
||||
const result = await this.sdk.get('emoji-custom');
|
||||
let { emojis } = result;
|
||||
emojis = emojis.filter(emoji => !lastMessage || emoji._updatedAt > lastMessage);
|
||||
emojis = this._prepareEmojis(emojis);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { InteractionManager } from 'react-native';
|
||||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import database from '../realm';
|
||||
import log from '../../utils/log';
|
||||
|
@ -8,7 +7,7 @@ import defaultPermissions from '../../constants/permissions';
|
|||
export default async function() {
|
||||
try {
|
||||
// RC 0.66.0
|
||||
const result = await SDK.api.get('permissions.list');
|
||||
const result = await this.sdk.get('permissions.list');
|
||||
|
||||
if (!result.success) {
|
||||
return;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { InteractionManager } from 'react-native';
|
||||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import mergeSubscriptionsRooms, { merge } from './helpers/mergeSubscriptionsRooms';
|
||||
import mergeSubscriptionsRooms from './helpers/mergeSubscriptionsRooms';
|
||||
import database from '../realm';
|
||||
import log from '../../utils/log';
|
||||
|
||||
|
@ -13,27 +12,22 @@ const lastMessage = () => {
|
|||
};
|
||||
|
||||
export default function() {
|
||||
const { database: db } = database;
|
||||
|
||||
return new Promise(async(resolve, reject) => {
|
||||
try {
|
||||
const updatedSince = lastMessage();
|
||||
// subscriptions.get: Since RC 0.60.0
|
||||
// rooms.get: Since RC 0.62.0
|
||||
const [subscriptionsResult, roomsResult] = await (updatedSince
|
||||
? Promise.all([SDK.api.get('subscriptions.get', { updatedSince }), SDK.api.get('rooms.get', { updatedSince })])
|
||||
: Promise.all([SDK.api.get('subscriptions.get'), SDK.api.get('rooms.get')])
|
||||
? Promise.all([this.sdk.get('subscriptions.get', { updatedSince }), this.sdk.get('rooms.get', { updatedSince })])
|
||||
: Promise.all([this.sdk.get('subscriptions.get'), this.sdk.get('rooms.get')])
|
||||
);
|
||||
const { subscriptions, rooms } = mergeSubscriptionsRooms(subscriptionsResult, roomsResult);
|
||||
|
||||
const data = rooms.map(room => ({ room, sub: database.objects('subscriptions').filtered('rid == $0', room._id) }));
|
||||
const { subscriptions } = mergeSubscriptionsRooms(subscriptionsResult, roomsResult);
|
||||
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
db.write(() => {
|
||||
subscriptions.forEach(subscription => db.create('subscriptions', subscription, true));
|
||||
data.forEach(({ sub, room }) => sub[0] && merge(sub[0], room));
|
||||
database.write(() => {
|
||||
subscriptions.forEach(subscription => database.create('subscriptions', subscription, true));
|
||||
});
|
||||
resolve(data);
|
||||
resolve(subscriptions);
|
||||
});
|
||||
} catch (e) {
|
||||
log('getRooms', e);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { InteractionManager } from 'react-native';
|
||||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import reduxStore from '../createStore';
|
||||
import database from '../realm';
|
||||
|
@ -17,7 +16,7 @@ export default async function() {
|
|||
try {
|
||||
const settingsParams = JSON.stringify(Object.keys(settings));
|
||||
// RC 0.60.0
|
||||
const result = await fetch(`${ SDK.api.url }settings.public?query={"_id":{"$in":${ settingsParams }}}`).then(response => response.json());
|
||||
const result = await fetch(`${ this.sdk.client.host }/api/v1/settings.public?query={"_id":{"$in":${ settingsParams }}}`).then(response => response.json());
|
||||
|
||||
if (!result.success) {
|
||||
return;
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import EJSON from 'ejson';
|
||||
|
||||
import normalizeMessage from './normalizeMessage';
|
||||
// TODO: delete and update
|
||||
|
||||
export const merge = (subscription, room) => {
|
||||
subscription = EJSON.fromJSONValue(subscription);
|
||||
room = EJSON.fromJSONValue(room);
|
||||
|
||||
if (!subscription) {
|
||||
return;
|
||||
}
|
||||
|
@ -28,6 +33,8 @@ export const merge = (subscription, room) => {
|
|||
}
|
||||
if (subscription.roles && subscription.roles.length) {
|
||||
subscription.roles = subscription.roles.map(role => (role.value ? role : { value: role }));
|
||||
} else {
|
||||
subscription.roles = [];
|
||||
}
|
||||
|
||||
if (subscription.mobilePushNotifications === 'nothing') {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { InteractionManager } from 'react-native';
|
||||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import buildMessage from './helpers/buildMessage';
|
||||
import database from '../realm';
|
||||
|
@ -9,7 +8,7 @@ async function load({ rid: roomId, latest, t }) {
|
|||
if (t === 'l') {
|
||||
try {
|
||||
// RC 0.51.0
|
||||
const data = await SDK.driver.asyncCall('loadHistory', roomId, null, 50, latest);
|
||||
const data = await this.sdk.methodCall('loadHistory', roomId, null, 50, latest);
|
||||
if (!data || data.status === 'error') {
|
||||
return [];
|
||||
}
|
||||
|
@ -25,7 +24,7 @@ async function load({ rid: roomId, latest, t }) {
|
|||
params = { ...params, latest: new Date(latest).toISOString() };
|
||||
}
|
||||
// RC 0.48.0
|
||||
const data = await SDK.api.get(`${ this.roomTypeToApiType(t) }.history`, params);
|
||||
const data = await this.sdk.get(`${ this.roomTypeToApiType(t) }.history`, params);
|
||||
if (!data || data.status === 'error') {
|
||||
return [];
|
||||
}
|
||||
|
@ -33,15 +32,14 @@ async function load({ rid: roomId, latest, t }) {
|
|||
}
|
||||
|
||||
export default function loadMessagesForRoom(...args) {
|
||||
const { database: db } = database;
|
||||
return new Promise(async(resolve, reject) => {
|
||||
try {
|
||||
const data = await load.call(this, ...args);
|
||||
|
||||
if (data && data.length) {
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
db.write(() => data.forEach((message) => {
|
||||
db.create('messages', buildMessage(message), true);
|
||||
database.write(() => data.forEach((message) => {
|
||||
database.create('messages', buildMessage(message), true);
|
||||
}));
|
||||
return resolve(data);
|
||||
});
|
||||
|
|
|
@ -1,24 +1,29 @@
|
|||
import { InteractionManager } from 'react-native';
|
||||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import buildMessage from './helpers/buildMessage';
|
||||
import database from '../realm';
|
||||
import log from '../../utils/log';
|
||||
|
||||
const getLastUpdate = (rid) => {
|
||||
const sub = database
|
||||
.objects('subscriptions')
|
||||
.filtered('rid == $0', rid)[0];
|
||||
return sub && new Date(sub.lastOpen).toISOString();
|
||||
};
|
||||
|
||||
async function load({ rid: roomId, lastOpen }) {
|
||||
let lastUpdate;
|
||||
if (lastOpen) {
|
||||
lastUpdate = new Date(lastOpen).toISOString();
|
||||
} else {
|
||||
return [];
|
||||
lastUpdate = getLastUpdate(roomId);
|
||||
}
|
||||
// RC 0.60.0
|
||||
const { result } = await SDK.api.get('chat.syncMessages', { roomId, lastUpdate, count: 50 });
|
||||
const { result } = await this.sdk.get('chat.syncMessages', { roomId, lastUpdate, count: 50 });
|
||||
return result;
|
||||
}
|
||||
|
||||
export default function loadMissedMessages(...args) {
|
||||
const { database: db } = database;
|
||||
return new Promise(async(resolve, reject) => {
|
||||
try {
|
||||
const data = (await load.call(this, ...args));
|
||||
|
@ -28,14 +33,14 @@ export default function loadMissedMessages(...args) {
|
|||
const { updated } = data;
|
||||
updated.forEach(buildMessage);
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
db.write(() => updated.forEach(message => db.create('messages', message, true)));
|
||||
database.write(() => updated.forEach(message => database.create('messages', message, true)));
|
||||
resolve(updated);
|
||||
});
|
||||
}
|
||||
if (data.deleted && data.deleted.length) {
|
||||
const { deleted } = data;
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
db.write(() => {
|
||||
database.write(() => {
|
||||
deleted.forEach((m) => {
|
||||
const message = database.objects('messages').filtered('_id = $0', m._id);
|
||||
database.delete(message);
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import database from '../realm';
|
||||
import log from '../../utils/log';
|
||||
|
||||
|
@ -7,7 +5,7 @@ export default async function readMessages(rid) {
|
|||
const ls = new Date();
|
||||
try {
|
||||
// RC 0.61.0
|
||||
const data = await SDK.api.post('subscriptions.read', { rid });
|
||||
const data = await this.sdk.post('subscriptions.read', { rid });
|
||||
const [subscription] = database.objects('subscriptions').filtered('rid = $0', rid);
|
||||
database.write(() => {
|
||||
subscription.open = true;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import RNFetchBlob from 'rn-fetch-blob';
|
||||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import reduxStore from '../createStore';
|
||||
import database from '../realm';
|
||||
|
@ -7,16 +6,16 @@ import database from '../realm';
|
|||
const promises = {};
|
||||
|
||||
function _ufsCreate(fileInfo) {
|
||||
return SDK.driver.asyncCall('ufsCreate', fileInfo);
|
||||
return this.sdk.methodCall('ufsCreate', fileInfo);
|
||||
}
|
||||
|
||||
function _ufsComplete(fileId, store, token) {
|
||||
return SDK.driver.asyncCall('ufsComplete', fileId, store, token);
|
||||
return this.sdk.methodCall('ufsComplete', fileId, store, token);
|
||||
}
|
||||
|
||||
function _sendFileMessage(rid, data, msg = {}) {
|
||||
// RC 0.22.0
|
||||
return SDK.driver.asyncCall('sendFileMessage', rid, null, data, msg);
|
||||
return this.sdk.methodCall('sendFileMessage', rid, null, data, msg);
|
||||
}
|
||||
|
||||
export function isUploadActive(path) {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import messagesStatus from '../../constants/messagesStatus';
|
||||
import buildMessage from './helpers/buildMessage';
|
||||
import database from '../realm';
|
||||
|
@ -34,25 +32,24 @@ export const getMessage = (rid, msg = {}) => {
|
|||
export async function sendMessageCall(message) {
|
||||
const { _id, rid, msg } = message;
|
||||
// RC 0.60.0
|
||||
const data = await SDK.api.post('chat.sendMessage', { message: { _id, rid, msg } });
|
||||
const data = await this.sdk.post('chat.sendMessage', { message: { _id, rid, msg } });
|
||||
return data;
|
||||
}
|
||||
|
||||
export default async function(rid, msg) {
|
||||
const { database: db } = database;
|
||||
try {
|
||||
const message = getMessage(rid, msg);
|
||||
const room = db.objects('subscriptions').filtered('rid == $0', rid);
|
||||
const room = database.objects('subscriptions').filtered('rid == $0', rid);
|
||||
|
||||
// TODO: do we need this?
|
||||
db.write(() => {
|
||||
database.write(() => {
|
||||
room.lastMessage = message;
|
||||
});
|
||||
|
||||
try {
|
||||
const ret = await sendMessageCall.call(this, message);
|
||||
db.write(() => {
|
||||
db.create('messages', buildMessage({ ...message, ...ret }), true);
|
||||
database.write(() => {
|
||||
database.create('messages', buildMessage({ ...message, ...ret }), true);
|
||||
});
|
||||
} catch (e) {
|
||||
database.write(() => {
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import log from '../../../utils/log';
|
||||
|
||||
const subscribe = rid => Promise.all([
|
||||
SDK.driver.subscribe('stream-room-messages', rid, false),
|
||||
SDK.driver.subscribe('stream-notify-room', `${ rid }/typing`, false),
|
||||
SDK.driver.subscribe('stream-notify-room', `${ rid }/deleteMessage`, false)
|
||||
]);
|
||||
const unsubscribe = subscriptions => subscriptions.forEach(sub => sub.unsubscribe().catch(() => console.log('unsubscribeRoom')));
|
||||
|
||||
let timer = null;
|
||||
let promises;
|
||||
let timer = null;
|
||||
|
||||
const stop = () => {
|
||||
if (promises) {
|
||||
|
@ -21,46 +14,46 @@ const stop = () => {
|
|||
clearTimeout(timer);
|
||||
};
|
||||
|
||||
export default function subscribeRoom({ rid, t }) {
|
||||
export default function subscribeRoom({ rid }) {
|
||||
if (promises) {
|
||||
promises.then(unsubscribe);
|
||||
promises = false;
|
||||
}
|
||||
const loop = (time = new Date()) => {
|
||||
const loop = () => {
|
||||
if (timer) {
|
||||
return;
|
||||
}
|
||||
timer = setTimeout(async() => {
|
||||
try {
|
||||
await this.loadMissedMessages({ rid, t });
|
||||
clearTimeout(timer);
|
||||
timer = false;
|
||||
loop();
|
||||
if (this.sdk.userId) {
|
||||
await this.loadMissedMessages({ rid });
|
||||
loop();
|
||||
}
|
||||
} catch (e) {
|
||||
loop(time);
|
||||
loop();
|
||||
}
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
// if (!this.connected()) {
|
||||
// loop();
|
||||
// } else {
|
||||
SDK.driver.on('logged', () => {
|
||||
this.sdk.onStreamData('connected', () => {
|
||||
if (this.sdk.userId) {
|
||||
this.loadMissedMessages({ rid });
|
||||
}
|
||||
clearTimeout(timer);
|
||||
timer = false;
|
||||
});
|
||||
|
||||
SDK.driver.on('disconnected', () => {
|
||||
if (SDK.driver.userId) {
|
||||
loop();
|
||||
}
|
||||
this.sdk.onStreamData('close', () => {
|
||||
loop();
|
||||
});
|
||||
|
||||
try {
|
||||
promises = subscribe(rid);
|
||||
promises = this.sdk.subscribeRoom(rid);
|
||||
} catch (e) {
|
||||
log('subscribeRoom', e);
|
||||
}
|
||||
// }
|
||||
|
||||
return {
|
||||
stop: () => stop()
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import * as SDK from '@rocket.chat/sdk';
|
||||
|
||||
import database from '../../realm';
|
||||
import { merge } from '../helpers/mergeSubscriptionsRooms';
|
||||
import protectedFunction from '../helpers/protectedFunction';
|
||||
|
@ -7,46 +5,39 @@ import messagesStatus from '../../../constants/messagesStatus';
|
|||
import log from '../../../utils/log';
|
||||
import random from '../../../utils/random';
|
||||
|
||||
export default async function subscribeRooms(id) {
|
||||
const promises = Promise.all([
|
||||
SDK.driver.subscribe('stream-notify-user', `${ id }/subscriptions-changed`, false),
|
||||
SDK.driver.subscribe('stream-notify-user', `${ id }/rooms-changed`, false),
|
||||
SDK.driver.subscribe('stream-notify-user', `${ id }/message`, false)
|
||||
]);
|
||||
|
||||
export default async function subscribeRooms() {
|
||||
let timer = null;
|
||||
const loop = (time = new Date()) => {
|
||||
const loop = () => {
|
||||
if (timer) {
|
||||
return;
|
||||
}
|
||||
timer = setTimeout(async() => {
|
||||
try {
|
||||
await this.getRooms(time);
|
||||
clearTimeout(timer);
|
||||
timer = false;
|
||||
loop();
|
||||
if (this.sdk.userId) {
|
||||
await this.getRooms();
|
||||
loop();
|
||||
}
|
||||
} catch (e) {
|
||||
loop(time);
|
||||
loop();
|
||||
}
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
SDK.driver.on('logged', () => {
|
||||
this.sdk.onStreamData('connected', () => {
|
||||
if (this.sdk.userId) {
|
||||
this.getRooms();
|
||||
}
|
||||
clearTimeout(timer);
|
||||
timer = false;
|
||||
});
|
||||
|
||||
SDK.driver.on('logout', () => {
|
||||
clearTimeout(timer);
|
||||
timer = true;
|
||||
this.sdk.onStreamData('close', () => {
|
||||
loop();
|
||||
});
|
||||
|
||||
SDK.driver.on('disconnected', () => {
|
||||
if (SDK.driver.userId) {
|
||||
loop();
|
||||
}
|
||||
});
|
||||
|
||||
SDK.driver.on('stream-notify-user', protectedFunction((e, ddpMessage) => {
|
||||
this.sdk.onStreamData('stream-notify-user', protectedFunction((ddpMessage) => {
|
||||
if (ddpMessage.msg === 'added') {
|
||||
return;
|
||||
}
|
||||
|
@ -77,7 +68,8 @@ export default async function subscribeRooms(id) {
|
|||
if (type === 'updated') {
|
||||
const [sub] = database.objects('subscriptions').filtered('rid == $0', data._id);
|
||||
database.write(() => {
|
||||
merge(sub, data);
|
||||
const tmp = merge(sub, data);
|
||||
database.create('subscriptions', tmp, true);
|
||||
});
|
||||
} else if (type === 'inserted') {
|
||||
database.write(() => {
|
||||
|
@ -107,7 +99,7 @@ export default async function subscribeRooms(id) {
|
|||
}));
|
||||
|
||||
try {
|
||||
await promises;
|
||||
await this.sdk.subscribeNotifyUser();
|
||||
} catch (e) {
|
||||
log('subscribeRooms', e);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import { AsyncStorage } from 'react-native';
|
||||
import foreach from 'lodash/forEach';
|
||||
import * as SDK from '@rocket.chat/sdk';
|
||||
import semver from 'semver';
|
||||
import { Rocketchat as RocketchatClient } from '@rocket.chat/sdk';
|
||||
|
||||
import reduxStore from './createStore';
|
||||
import defaultSettings from '../constants/settings';
|
||||
import messagesStatus from '../constants/messagesStatus';
|
||||
import database from './realm';
|
||||
import log from '../utils/log';
|
||||
import { isIOS } from '../utils/deviceInfo';
|
||||
import { isIOS, getBundleId } from '../utils/deviceInfo';
|
||||
|
||||
import {
|
||||
setUser, setLoginServices, loginRequest, loginFailure, logout
|
||||
|
@ -42,7 +42,6 @@ import { getDeviceToken } from '../push';
|
|||
|
||||
const TOKEN_KEY = 'reactnativemeteor_usertoken';
|
||||
const SORT_PREFS_KEY = 'RC_SORT_PREFS_KEY';
|
||||
const call = (method, ...params) => SDK.driver.asyncCall(method, ...params);
|
||||
const returnAnArray = obj => obj || [];
|
||||
const MIN_ROCKETCHAT_VERSION = '0.66.0';
|
||||
|
||||
|
@ -55,7 +54,7 @@ const RocketChat = {
|
|||
name, users, type, readOnly, broadcast
|
||||
}) {
|
||||
// RC 0.51.0
|
||||
return call(type ? 'createPrivateGroup' : 'createChannel', name, users, readOnly, {}, { broadcast });
|
||||
return this.sdk.methodCall(type ? 'createPrivateGroup' : 'createChannel', name, users, readOnly, {}, { broadcast });
|
||||
},
|
||||
async createDirectMessageAndWait(username) {
|
||||
const room = await RocketChat.createDirectMessage(username);
|
||||
|
@ -134,67 +133,61 @@ const RocketChat = {
|
|||
}
|
||||
},
|
||||
loginSuccess({ user }) {
|
||||
SDK.driver.login({ resume: user.token });
|
||||
reduxStore.dispatch(setUser(user));
|
||||
this.getRooms().catch(e => console.log(e));
|
||||
this.subscribeRooms();
|
||||
this.sdk.subscribe('activeUsers');
|
||||
this.sdk.subscribe('roles');
|
||||
this.getPermissions();
|
||||
this.getCustomEmoji();
|
||||
this.registerPushToken().then(result => console.log(result)).catch(e => alert(e));
|
||||
this.registerPushToken().then(result => console.log(result)).catch(e => console.log(e));
|
||||
},
|
||||
connect({ server, user }) {
|
||||
database.setActiveDB(server);
|
||||
reduxStore.dispatch(connectRequest());
|
||||
|
||||
if (this.ddp) {
|
||||
RocketChat.disconnect();
|
||||
this.ddp = null;
|
||||
}
|
||||
|
||||
SDK.api.setBaseUrl(server);
|
||||
this.getSettings();
|
||||
|
||||
if (user && user.token) {
|
||||
reduxStore.dispatch(loginRequest({ resume: user.token }));
|
||||
if (this.connectTimeout) {
|
||||
clearTimeout(this.connectTimeout);
|
||||
}
|
||||
|
||||
// Use useSsl: false only if server url starts with http://
|
||||
const useSsl = !/http:\/\//.test(server);
|
||||
|
||||
reduxStore.dispatch(connectRequest());
|
||||
SDK.driver.connect({ host: server, useSsl }, (err, ddp) => {
|
||||
if (err) {
|
||||
return console.warn(err);
|
||||
}
|
||||
this.ddp = ddp;
|
||||
if (user && user.token) {
|
||||
SDK.driver.login({ resume: user.token });
|
||||
}
|
||||
});
|
||||
this.sdk = new RocketchatClient({ host: server, protocol: 'ddp', useSsl });
|
||||
this.getSettings();
|
||||
|
||||
SDK.driver.on('connected', () => {
|
||||
this.sdk.connect()
|
||||
.then(() => {
|
||||
if (user && user.token) {
|
||||
reduxStore.dispatch(loginRequest({ resume: user.token }));
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('connect error', err);
|
||||
|
||||
// when `connect` raises an error, we try again in 10 seconds
|
||||
this.connectTimeout = setTimeout(() => {
|
||||
this.connect({ server, user });
|
||||
}, 10000);
|
||||
});
|
||||
|
||||
this.sdk.onStreamData('connected', () => {
|
||||
reduxStore.dispatch(connectSuccess());
|
||||
});
|
||||
|
||||
SDK.driver.on('disconnected', protectedFunction(() => {
|
||||
this.sdk.onStreamData('close', () => {
|
||||
reduxStore.dispatch(disconnect());
|
||||
}));
|
||||
});
|
||||
|
||||
SDK.driver.on('logged', protectedFunction((error, u) => {
|
||||
this.subscribeRooms(u.id);
|
||||
SDK.driver.subscribe('activeUsers');
|
||||
SDK.driver.subscribe('roles');
|
||||
}));
|
||||
this.sdk.onStreamData('users', protectedFunction(ddpMessage => RocketChat._setUser(ddpMessage)));
|
||||
|
||||
SDK.driver.on('forbidden', protectedFunction(() => reduxStore.dispatch(logout())));
|
||||
|
||||
SDK.driver.on('users', protectedFunction((error, ddpMessage) => RocketChat._setUser(ddpMessage)));
|
||||
|
||||
SDK.driver.on('stream-room-messages', (error, ddpMessage) => {
|
||||
this.sdk.onStreamData('stream-room-messages', (ddpMessage) => {
|
||||
// TODO: debounce
|
||||
const message = _buildMessage(ddpMessage.fields.args[0]);
|
||||
requestAnimationFrame(() => reduxStore.dispatch(roomMessageReceived(message)));
|
||||
});
|
||||
|
||||
SDK.driver.on('stream-notify-room', protectedFunction((error, ddpMessage) => {
|
||||
this.sdk.onStreamData('stream-notify-room', protectedFunction((ddpMessage) => {
|
||||
const [_rid, ev] = ddpMessage.fields.eventName.split('/');
|
||||
if (ev === 'typing') {
|
||||
reduxStore.dispatch(someoneTyping({ _rid, username: ddpMessage.fields.args[0], typing: ddpMessage.fields.args[1] }));
|
||||
|
@ -209,7 +202,7 @@ const RocketChat = {
|
|||
}
|
||||
}));
|
||||
|
||||
SDK.driver.on('rocketchat_snippeted_message', protectedFunction((error, ddpMessage) => {
|
||||
this.sdk.onStreamData('rocketchat_snippeted_message', protectedFunction((ddpMessage) => {
|
||||
if (ddpMessage.msg === 'added') {
|
||||
this.snippetedMessages = this.snippetedMessages || [];
|
||||
|
||||
|
@ -230,7 +223,7 @@ const RocketChat = {
|
|||
}
|
||||
}));
|
||||
|
||||
SDK.driver.on('rocketchat_roles', protectedFunction((error, ddpMessage) => {
|
||||
this.sdk.onStreamData('rocketchat_roles', protectedFunction((ddpMessage) => {
|
||||
this.roles = this.roles || {};
|
||||
|
||||
if (this.roleTimer) {
|
||||
|
@ -255,17 +248,17 @@ const RocketChat = {
|
|||
|
||||
register(credentials) {
|
||||
// RC 0.50.0
|
||||
return SDK.api.post('users.register', credentials, false);
|
||||
return this.sdk.post('users.register', credentials, false);
|
||||
},
|
||||
|
||||
setUsername(username) {
|
||||
// RC 0.51.0
|
||||
return call('setUsername', username);
|
||||
return this.sdk.methodCall('setUsername', username);
|
||||
},
|
||||
|
||||
forgotPassword(email) {
|
||||
// RC 0.64.0
|
||||
return SDK.api.post('users.forgotPassword', { email }, false);
|
||||
return this.sdk.post('users.forgotPassword', { email }, false);
|
||||
},
|
||||
|
||||
async loginWithPassword({ user, password, code }) {
|
||||
|
@ -302,7 +295,7 @@ const RocketChat = {
|
|||
|
||||
async loginOAuth(params) {
|
||||
try {
|
||||
const result = await SDK.driver.login(params);
|
||||
const result = await this.login(params);
|
||||
reduxStore.dispatch(loginRequest({ resume: result.token }));
|
||||
} catch (error) {
|
||||
throw error;
|
||||
|
@ -312,14 +305,29 @@ const RocketChat = {
|
|||
async login(params) {
|
||||
try {
|
||||
// RC 0.64.0
|
||||
return await SDK.api.login(params);
|
||||
await this.sdk.login(params);
|
||||
const { result } = this.sdk.currentLogin;
|
||||
const user = {
|
||||
id: result.userId,
|
||||
token: result.authToken,
|
||||
username: result.me.username,
|
||||
name: result.me.name,
|
||||
language: result.me.language,
|
||||
status: result.me.status,
|
||||
customFields: result.me.customFields,
|
||||
emails: result.me.emails
|
||||
};
|
||||
return user;
|
||||
} catch (e) {
|
||||
reduxStore.dispatch(loginFailure(e));
|
||||
if (e.data && e.data.message && /you've been logged out by the server/i.test(e.data.message)) {
|
||||
reduxStore.dispatch(logout({ server: this.sdk.client.host }));
|
||||
} else {
|
||||
reduxStore.dispatch(loginFailure(e));
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
async logout({ server }) {
|
||||
// this.removePushToken().catch(error => console.log(error));
|
||||
try {
|
||||
await this.removePushToken();
|
||||
} catch (error) {
|
||||
|
@ -327,12 +335,11 @@ const RocketChat = {
|
|||
}
|
||||
try {
|
||||
// RC 0.60.0
|
||||
await SDK.api.logout();
|
||||
await this.sdk.logout();
|
||||
} catch (error) {
|
||||
console.log('logout -> api logout -> catch -> error', error);
|
||||
}
|
||||
SDK.driver.ddp.disconnect();
|
||||
this.ddp = null;
|
||||
this.sdk = null;
|
||||
|
||||
Promise.all([
|
||||
AsyncStorage.removeItem('currentServer'),
|
||||
|
@ -346,18 +353,6 @@ const RocketChat = {
|
|||
console.log(error);
|
||||
}
|
||||
},
|
||||
disconnect() {
|
||||
try {
|
||||
SDK.driver.unsubscribeAll();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
RocketChat.setApiUser({ userId: null, authToken: null });
|
||||
},
|
||||
setApiUser({ userId, authToken }) {
|
||||
SDK.api.setAuth({ userId, authToken });
|
||||
SDK.api.currentLogin = null;
|
||||
},
|
||||
registerPushToken() {
|
||||
return new Promise((resolve) => {
|
||||
const token = getDeviceToken();
|
||||
|
@ -366,10 +361,10 @@ const RocketChat = {
|
|||
const data = {
|
||||
value: token,
|
||||
type,
|
||||
appName: 'chat.rocket.reactnative' // TODO: try to get from config file
|
||||
appName: getBundleId
|
||||
};
|
||||
// RC 0.60.0
|
||||
return SDK.api.post('push.token', data);
|
||||
return this.sdk.post('push.token', data);
|
||||
}
|
||||
return resolve();
|
||||
});
|
||||
|
@ -378,7 +373,7 @@ const RocketChat = {
|
|||
const token = getDeviceToken();
|
||||
if (token) {
|
||||
// RC 0.60.0
|
||||
return SDK.api.del('push.token', { token });
|
||||
return this.sdk.del('push.token', { token });
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
@ -458,17 +453,17 @@ const RocketChat = {
|
|||
|
||||
spotlight(search, usernames, type) {
|
||||
// RC 0.51.0
|
||||
return call('spotlight', search, usernames, type);
|
||||
return this.sdk.methodCall('spotlight', search, usernames, type);
|
||||
},
|
||||
|
||||
createDirectMessage(username) {
|
||||
// RC 0.59.0
|
||||
return SDK.api.post('im.create', { username });
|
||||
return this.sdk.post('im.create', { username });
|
||||
},
|
||||
joinRoom(roomId) {
|
||||
// TODO: join code
|
||||
// RC 0.48.0
|
||||
return SDK.api.post('channels.join', { roomId });
|
||||
return this.sdk.post('channels.join', { roomId });
|
||||
},
|
||||
sendFileMessage,
|
||||
cancelUpload,
|
||||
|
@ -502,28 +497,28 @@ const RocketChat = {
|
|||
deleteMessage(message) {
|
||||
const { _id, rid } = message;
|
||||
// RC 0.48.0
|
||||
return SDK.api.post('chat.delete', { roomId: rid, msgId: _id });
|
||||
return this.sdk.post('chat.delete', { roomId: rid, msgId: _id });
|
||||
},
|
||||
editMessage(message) {
|
||||
const { _id, msg, rid } = message;
|
||||
// RC 0.49.0
|
||||
return SDK.api.post('chat.update', { roomId: rid, msgId: _id, text: msg });
|
||||
return this.sdk.post('chat.update', { roomId: rid, msgId: _id, text: msg });
|
||||
},
|
||||
toggleStarMessage(message) {
|
||||
if (message.starred) {
|
||||
// RC 0.59.0
|
||||
return SDK.api.post('chat.unStarMessage', { messageId: message._id });
|
||||
return this.sdk.post('chat.unStarMessage', { messageId: message._id });
|
||||
}
|
||||
// RC 0.59.0
|
||||
return SDK.api.post('chat.starMessage', { messageId: message._id });
|
||||
return this.sdk.post('chat.starMessage', { messageId: message._id });
|
||||
},
|
||||
togglePinMessage(message) {
|
||||
if (message.pinned) {
|
||||
// RC 0.59.0
|
||||
return SDK.api.post('chat.unPinMessage', { messageId: message._id });
|
||||
return this.sdk.post('chat.unPinMessage', { messageId: message._id });
|
||||
}
|
||||
// RC 0.59.0
|
||||
return SDK.api.post('chat.pinMessage', { messageId: message._id });
|
||||
return this.sdk.post('chat.pinMessage', { messageId: message._id });
|
||||
},
|
||||
getRoom(rid) {
|
||||
const [result] = database.objects('subscriptions').filtered('rid = $0', rid);
|
||||
|
@ -537,7 +532,7 @@ const RocketChat = {
|
|||
try {
|
||||
room = await RocketChat.getRoom(message.rid);
|
||||
} catch (e) {
|
||||
log('SDK.getPermalink', e);
|
||||
log('Rocketchat.getPermalink', e);
|
||||
return null;
|
||||
}
|
||||
const { server } = reduxStore.getState().server;
|
||||
|
@ -549,43 +544,43 @@ const RocketChat = {
|
|||
return `${ server }/${ roomType }/${ room.name }?msg=${ message._id }`;
|
||||
},
|
||||
subscribe(...args) {
|
||||
return SDK.driver.subscribe(...args);
|
||||
return this.sdk.subscribe(...args);
|
||||
},
|
||||
unsubscribe(subscription) {
|
||||
return SDK.driver.unsubscribe(subscription);
|
||||
return this.sdk.unsubscribe(subscription);
|
||||
},
|
||||
emitTyping(room, t = true) {
|
||||
const { login } = reduxStore.getState();
|
||||
return call('stream-notify-room', `${ room }/typing`, login.user.username, t);
|
||||
return this.sdk.methodCall('stream-notify-room', `${ room }/typing`, login.user.username, t);
|
||||
},
|
||||
setUserPresenceAway() {
|
||||
return call('UserPresence:away');
|
||||
return this.sdk.methodCall('UserPresence:away');
|
||||
},
|
||||
setUserPresenceOnline() {
|
||||
return call('UserPresence:online');
|
||||
return this.sdk.methodCall('UserPresence:online');
|
||||
},
|
||||
setUserPresenceDefaultStatus(status) {
|
||||
return call('UserPresence:setDefaultStatus', status);
|
||||
return this.sdk.methodCall('UserPresence:setDefaultStatus', status);
|
||||
},
|
||||
setReaction(emoji, messageId) {
|
||||
// RC 0.62.2
|
||||
return SDK.api.post('chat.react', { emoji, messageId });
|
||||
return this.sdk.post('chat.react', { emoji, messageId });
|
||||
},
|
||||
toggleFavorite(roomId, favorite) {
|
||||
// RC 0.64.0
|
||||
return SDK.api.post('rooms.favorite', { roomId, favorite });
|
||||
return this.sdk.post('rooms.favorite', { roomId, favorite });
|
||||
},
|
||||
getRoomMembers(rid, allUsers) {
|
||||
// RC 0.42.0
|
||||
return call('getUsersOfRoom', rid, allUsers);
|
||||
return this.sdk.methodCall('getUsersOfRoom', rid, allUsers);
|
||||
},
|
||||
getUserRoles() {
|
||||
// RC 0.27.0
|
||||
return call('getUserRoles');
|
||||
return this.sdk.methodCall('getUserRoles');
|
||||
},
|
||||
getRoomCounters(roomId, t) {
|
||||
// RC 0.65.0
|
||||
return SDK.api.get(`${ this.roomTypeToApiType(t) }.counters`, { roomId });
|
||||
return this.sdk.get(`${ this.roomTypeToApiType(t) }.counters`, { roomId });
|
||||
},
|
||||
async getRoomMember(rid, currentUserId) {
|
||||
try {
|
||||
|
@ -601,56 +596,56 @@ const RocketChat = {
|
|||
toggleBlockUser(rid, blocked, block) {
|
||||
if (block) {
|
||||
// RC 0.49.0
|
||||
return call('blockUser', { rid, blocked });
|
||||
return this.sdk.methodCall('blockUser', { rid, blocked });
|
||||
}
|
||||
// RC 0.49.0
|
||||
return call('unblockUser', { rid, blocked });
|
||||
return this.sdk.methodCall('unblockUser', { rid, blocked });
|
||||
},
|
||||
leaveRoom(roomId, t) {
|
||||
// RC 0.48.0
|
||||
return SDK.api.post(`${ this.roomTypeToApiType(t) }.leave`, { roomId });
|
||||
return this.sdk.post(`${ this.roomTypeToApiType(t) }.leave`, { roomId });
|
||||
},
|
||||
eraseRoom(roomId, t) {
|
||||
// RC 0.49.0
|
||||
return SDK.api.post(`${ this.roomTypeToApiType(t) }.delete`, { roomId });
|
||||
return this.sdk.post(`${ this.roomTypeToApiType(t) }.delete`, { roomId });
|
||||
},
|
||||
toggleMuteUserInRoom(rid, username, mute) {
|
||||
if (mute) {
|
||||
// RC 0.51.0
|
||||
return call('muteUserInRoom', { rid, username });
|
||||
return this.sdk.methodCall('muteUserInRoom', { rid, username });
|
||||
}
|
||||
// RC 0.51.0
|
||||
return call('unmuteUserInRoom', { rid, username });
|
||||
return this.sdk.methodCall('unmuteUserInRoom', { rid, username });
|
||||
},
|
||||
toggleArchiveRoom(roomId, t, archive) {
|
||||
if (archive) {
|
||||
// RC 0.48.0
|
||||
return SDK.api.post(`${ this.roomTypeToApiType(t) }.archive`, { roomId });
|
||||
return this.sdk.post(`${ this.roomTypeToApiType(t) }.archive`, { roomId });
|
||||
}
|
||||
// RC 0.48.0
|
||||
return SDK.api.post(`${ this.roomTypeToApiType(t) }.unarchive`, { roomId });
|
||||
return this.sdk.post(`${ this.roomTypeToApiType(t) }.unarchive`, { roomId });
|
||||
},
|
||||
saveRoomSettings(rid, params) {
|
||||
// RC 0.55.0
|
||||
return call('saveRoomSettings', rid, params);
|
||||
return this.sdk.methodCall('saveRoomSettings', rid, params);
|
||||
},
|
||||
saveUserProfile(data) {
|
||||
// RC 0.62.2
|
||||
return SDK.api.post('users.updateOwnBasicInfo', { data });
|
||||
return this.sdk.post('users.updateOwnBasicInfo', { data });
|
||||
},
|
||||
saveUserPreferences(params) {
|
||||
// RC 0.51.0
|
||||
return call('saveUserPreferences', params);
|
||||
return this.sdk.methodCall('saveUserPreferences', params);
|
||||
},
|
||||
saveNotificationSettings(roomId, notifications) {
|
||||
// RC 0.63.0
|
||||
return SDK.api.post('rooms.saveNotification', { roomId, notifications });
|
||||
return this.sdk.post('rooms.saveNotification', { roomId, notifications });
|
||||
},
|
||||
addUsersToRoom(rid) {
|
||||
let { users } = reduxStore.getState().selectedUsers;
|
||||
users = users.map(u => u.name);
|
||||
// RC 0.51.0
|
||||
return call('addUsersToRoom', { rid, users });
|
||||
return this.sdk.methodCall('addUsersToRoom', { rid, users });
|
||||
},
|
||||
hasPermission(permissions, rid) {
|
||||
let roles = [];
|
||||
|
@ -685,15 +680,15 @@ const RocketChat = {
|
|||
},
|
||||
getAvatarSuggestion() {
|
||||
// RC 0.51.0
|
||||
return call('getAvatarSuggestion');
|
||||
return this.sdk.methodCall('getAvatarSuggestion');
|
||||
},
|
||||
resetAvatar(userId) {
|
||||
// RC 0.55.0
|
||||
return SDK.api.post('users.resetAvatar', { userId });
|
||||
return this.sdk.post('users.resetAvatar', { userId });
|
||||
},
|
||||
setAvatarFromService({ data, contentType = '', service = null }) {
|
||||
// RC 0.51.0
|
||||
return call('setAvatarFromService', data, contentType, service);
|
||||
return this.sdk.methodCall('setAvatarFromService', data, contentType, service);
|
||||
},
|
||||
async getSortPreferences() {
|
||||
const prefs = await AsyncStorage.getItem(SORT_PREFS_KEY);
|
||||
|
@ -731,7 +726,7 @@ const RocketChat = {
|
|||
},
|
||||
getUsernameSuggestion() {
|
||||
// RC 0.65.0
|
||||
return SDK.api.get('users.getUsernameSuggestion');
|
||||
return this.sdk.get('users.getUsernameSuggestion');
|
||||
},
|
||||
roomTypeToApiType(t) {
|
||||
const types = {
|
||||
|
@ -741,7 +736,7 @@ const RocketChat = {
|
|||
},
|
||||
getFiles(roomId, type, offset) {
|
||||
// RC 0.59.0
|
||||
return SDK.api.get(`${ this.roomTypeToApiType(type) }.files`, {
|
||||
return this.sdk.get(`${ this.roomTypeToApiType(type) }.files`, {
|
||||
roomId,
|
||||
offset,
|
||||
sort: { uploadedAt: -1 },
|
||||
|
@ -752,7 +747,7 @@ const RocketChat = {
|
|||
},
|
||||
getMessages(roomId, type, query, offset) {
|
||||
// RC 0.59.0
|
||||
return SDK.api.get(`${ this.roomTypeToApiType(type) }.messages`, {
|
||||
return this.sdk.get(`${ this.roomTypeToApiType(type) }.messages`, {
|
||||
roomId,
|
||||
query,
|
||||
offset,
|
||||
|
@ -761,7 +756,7 @@ const RocketChat = {
|
|||
},
|
||||
searchMessages(roomId, searchText) {
|
||||
// RC 0.60.0
|
||||
return SDK.api.get('chat.search', {
|
||||
return this.sdk.get('chat.search', {
|
||||
roomId,
|
||||
searchText
|
||||
});
|
||||
|
|
|
@ -25,19 +25,7 @@ const handleLoginRequest = function* handleLoginRequest({ credentials }) {
|
|||
} else {
|
||||
result = yield call(loginWithPasswordCall, credentials);
|
||||
}
|
||||
if (result.status === 'success') {
|
||||
const { data } = result;
|
||||
const user = {
|
||||
id: data.userId,
|
||||
token: data.authToken,
|
||||
username: data.me.username,
|
||||
name: data.me.name,
|
||||
language: data.me.language,
|
||||
status: data.me.status,
|
||||
customFields: data.me.customFields
|
||||
};
|
||||
return yield put(loginSuccess(user));
|
||||
}
|
||||
return yield put(loginSuccess(result));
|
||||
} catch (error) {
|
||||
yield put(loginFailure(error));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import {
|
|||
put, call, takeLatest, take, select, race, fork, cancel, takeEvery
|
||||
} from 'redux-saga/effects';
|
||||
import { delay } from 'redux-saga';
|
||||
import EJSON from 'ejson';
|
||||
|
||||
import Navigation from '../lib/Navigation';
|
||||
import * as types from '../actions/actionsTypes';
|
||||
|
@ -45,7 +46,7 @@ const handleMessageReceived = function* handleMessageReceived({ message }) {
|
|||
|
||||
if (message.rid === room.rid) {
|
||||
database.write(() => {
|
||||
database.create('messages', message, true);
|
||||
database.create('messages', EJSON.fromJSONValue(message), true);
|
||||
});
|
||||
|
||||
if (room._id) {
|
||||
|
|
|
@ -7,10 +7,12 @@ export const isNotch = NOTCH_DEVICES.includes(DeviceInfo.getModel());
|
|||
export const isIOS = Platform.OS === 'ios';
|
||||
export const isAndroid = !isIOS;
|
||||
export const getReadableVersion = DeviceInfo.getReadableVersion();
|
||||
export const getBundleId = DeviceInfo.getBundleId();
|
||||
|
||||
export default {
|
||||
isNotch,
|
||||
isIOS,
|
||||
isAndroid,
|
||||
getReadableVersion
|
||||
getReadableVersion,
|
||||
getBundleId
|
||||
};
|
||||
|
|
|
@ -48,7 +48,7 @@ const styles = StyleSheet.create({
|
|||
@connect(state => ({
|
||||
isFetching: state.login.isFetching,
|
||||
failure: state.login.failure,
|
||||
error: state.login.error,
|
||||
error: state.login.error && state.login.error.data,
|
||||
Site_Name: state.settings.Site_Name,
|
||||
Accounts_EmailOrUsernamePlaceholder: state.settings.Accounts_EmailOrUsernamePlaceholder,
|
||||
Accounts_PasswordPlaceholder: state.settings.Accounts_PasswordPlaceholder
|
||||
|
@ -200,7 +200,7 @@ export default class LoginView extends LoggedView {
|
|||
return user.trim() && password.trim();
|
||||
}
|
||||
|
||||
submit = async() => {
|
||||
submit = () => {
|
||||
if (!this.valid()) {
|
||||
return;
|
||||
}
|
||||
|
@ -208,23 +208,8 @@ export default class LoginView extends LoggedView {
|
|||
const { user, password, code } = this.state;
|
||||
const { loginRequest } = this.props;
|
||||
Keyboard.dismiss();
|
||||
|
||||
try {
|
||||
await loginRequest({ user, password, code });
|
||||
Answers.logLogin('Email', true);
|
||||
} catch (e) {
|
||||
if (e && e.error === 'totp-required') {
|
||||
LayoutAnimation.easeInEaseOut();
|
||||
this.setState({ showTOTP: true });
|
||||
setTimeout(() => {
|
||||
if (this.codeInput && this.codeInput.focus) {
|
||||
this.codeInput.focus();
|
||||
}
|
||||
}, 300);
|
||||
return;
|
||||
}
|
||||
Alert.alert(I18n.t('Oops'), I18n.t('Login_error'));
|
||||
}
|
||||
loginRequest({ user, password, code });
|
||||
Answers.logLogin('Email', true);
|
||||
}
|
||||
|
||||
register = () => {
|
||||
|
|
|
@ -42,7 +42,8 @@ export default class RegisterView extends LoggedView {
|
|||
|
||||
static propTypes = {
|
||||
componentId: PropTypes.string,
|
||||
loginRequest: PropTypes.func
|
||||
loginRequest: PropTypes.func,
|
||||
Site_Name: PropTypes.string
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
import { connect } from 'react-redux';
|
||||
import { RectButton } from 'react-native-gesture-handler';
|
||||
import SafeAreaView from 'react-native-safe-area-view';
|
||||
import equal from 'deep-equal';
|
||||
|
||||
import Navigation from '../../lib/Navigation';
|
||||
import { openRoom as openRoomAction, closeRoom as closeRoomAction, setLastOpen as setLastOpenAction } from '../../actions/room';
|
||||
|
@ -99,7 +100,6 @@ export default class RoomView extends LoggedView {
|
|||
joined: this.rooms.length > 0,
|
||||
room: {}
|
||||
};
|
||||
this.focused = true;
|
||||
this.onReactionPress = this.onReactionPress.bind(this);
|
||||
Navigation.events().bindComponent(this);
|
||||
}
|
||||
|
@ -142,6 +142,8 @@ export default class RoomView extends LoggedView {
|
|||
return true;
|
||||
} else if (appState !== nextProps.appState) {
|
||||
return true;
|
||||
} else if (!equal(room.muted, nextState.room.muted)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -180,16 +182,6 @@ export default class RoomView extends LoggedView {
|
|||
this.rooms.removeAllListeners();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line
|
||||
componentDidAppear() {
|
||||
this.focused = true;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line
|
||||
componentDidDisappear() {
|
||||
this.focused = false;
|
||||
}
|
||||
|
||||
onMessageLongPress = (message) => {
|
||||
const { actionsShow } = this.props;
|
||||
actionsShow(message);
|
||||
|
@ -243,9 +235,6 @@ export default class RoomView extends LoggedView {
|
|||
updateRoom = () => {
|
||||
const { openRoom, setLastOpen } = this.props;
|
||||
|
||||
if (!this.focused) {
|
||||
return;
|
||||
}
|
||||
if (this.rooms.length > 0) {
|
||||
const { room: prevRoom } = this.state;
|
||||
const room = JSON.parse(JSON.stringify(this.rooms[0] || {}));
|
||||
|
@ -300,12 +289,12 @@ export default class RoomView extends LoggedView {
|
|||
isMuted = () => {
|
||||
const { room } = this.state;
|
||||
const { user } = this.props;
|
||||
return room && room.muted && Array.from(Object.keys(room.muted), i => room.muted[i].value).includes(user.username);
|
||||
return room && room.muted && !!Array.from(Object.keys(room.muted), i => room.muted[i].value).includes(user.username);
|
||||
}
|
||||
|
||||
isReadOnly = () => {
|
||||
const { room } = this.state;
|
||||
return room.ro && this.isMuted() && !this.isOwner();
|
||||
return (room.ro && !room.broadcast) || this.isMuted() || room.archived;
|
||||
}
|
||||
|
||||
isBlocked = () => {
|
||||
|
@ -342,7 +331,7 @@ export default class RoomView extends LoggedView {
|
|||
}
|
||||
|
||||
renderFooter = () => {
|
||||
const { joined, room } = this.state;
|
||||
const { joined } = this.state;
|
||||
|
||||
if (!joined) {
|
||||
return (
|
||||
|
@ -359,7 +348,7 @@ export default class RoomView extends LoggedView {
|
|||
</View>
|
||||
);
|
||||
}
|
||||
if (room.archived || this.isReadOnly()) {
|
||||
if (this.isReadOnly()) {
|
||||
return (
|
||||
<View style={styles.readOnly} key='room-view-read-only'>
|
||||
<Text>{I18n.t('This_room_is_read_only')}</Text>
|
||||
|
|
|
@ -4,7 +4,6 @@ import {
|
|||
} from 'react-native';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
import * as SDK from '@rocket.chat/sdk';
|
||||
import equal from 'deep-equal';
|
||||
|
||||
import Navigation from '../../lib/Navigation';
|
||||
|
@ -139,7 +138,7 @@ export default class ServerDropdown extends Component {
|
|||
if (!token) {
|
||||
appStart();
|
||||
try {
|
||||
SDK.driver.disconnect();
|
||||
this.sdk.disconnect();
|
||||
} catch (error) {
|
||||
console.warn(error);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,8 @@ export default class SetUsernameView extends LoggedView {
|
|||
componentId: PropTypes.string,
|
||||
server: PropTypes.string,
|
||||
userId: PropTypes.string,
|
||||
loginRequest: PropTypes.func
|
||||
loginRequest: PropTypes.func,
|
||||
token: PropTypes.string
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
|
@ -100,7 +101,6 @@ export default class SetUsernameView extends LoggedView {
|
|||
this.setState({ saving: true });
|
||||
try {
|
||||
await RocketChat.setUsername(username);
|
||||
RocketChat.setApiUser({ userId: null, authToken: null });
|
||||
await loginRequest({ resume: token });
|
||||
} catch (e) {
|
||||
console.log('SetUsernameView -> catch -> e', e);
|
||||
|
|
|
@ -5,9 +5,9 @@ const data = {
|
|||
alternateServer: 'https://unstable.rocket.chat',
|
||||
user: `user${ value }`,
|
||||
password: `password${ value }`,
|
||||
alternateUser: 'detox',
|
||||
alternateUser: 'detoxrn',
|
||||
alternateUserPassword: '123',
|
||||
alternateUserTOTPSecret: 'KFJW6SZMH5EUI5LHPJ2XCOKKGRHDA2ZDN5YD4YLBMMSSMVCEPJSQ',
|
||||
alternateUserTOTPSecret: 'KESVIUCQMZWEYNBMJJAUW4LYKRBVWYZ7HBWTIWDPIAZUOURTF4WA',
|
||||
email: `diego.mello+e2e${ value }@rocket.chat`,
|
||||
random: value
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -12,9 +12,7 @@
|
|||
"log-android": "react-native log-android",
|
||||
"android": "react-native run-android",
|
||||
"storybook": "storybook start -p 7007 | react-native start --projectRoot storybook",
|
||||
"snyk-protect": "snyk protect",
|
||||
"fabric-ios": "./scripts/fabric-ios.sh",
|
||||
"fabric-android": "./scripts/fabric-android.sh"
|
||||
"snyk-protect": "snyk protect"
|
||||
},
|
||||
"rnpm": {
|
||||
"assets": [
|
||||
|
@ -23,7 +21,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@remobile/react-native-toast": "^1.0.7",
|
||||
"@rocket.chat/sdk": "git+https://github.com/RocketChat/Rocket.Chat.js.SDK.git#temp-ddp",
|
||||
"@rocket.chat/sdk": "1.0.0-alpha.24",
|
||||
"deep-equal": "^1.0.1",
|
||||
"ejson": "^2.1.2",
|
||||
"js-base64": "^2.5.1",
|
||||
|
@ -52,7 +50,7 @@
|
|||
"react-native-markdown-renderer": "^3.2.8",
|
||||
"react-native-modal": "^7.0.2",
|
||||
"react-native-navigation": "^2.8.0",
|
||||
"react-native-notifications": "^1.1.23",
|
||||
"react-native-notifications": "1.1.23",
|
||||
"react-native-optimized-flatlist": "^1.0.4",
|
||||
"react-native-picker-select": "^5.2.3",
|
||||
"react-native-responsive-ui": "^1.1.1",
|
||||
|
|
Loading…
Reference in New Issue