Unverified Commit 25850381 authored by Diego Mello's avatar Diego Mello Committed by GitHub
Browse files

Update JS SDK version (#602)

parent d26f14d1
......@@ -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
......
......@@ -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
......
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>
);
}
}
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)) {
......
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);
......
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;
......
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);
......
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;
......
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') {
......
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);
});
......
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);
......
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;
......
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) {
......
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(() => {
......
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()
......
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;
});
SDK.driver.on('disconnected', () => {
if (SDK.driver.userId) {
loop();
}
this.sdk.onStreamData('close', () => {
loop();