Skip to content
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

Update JS SDK version #602

Merged
merged 18 commits into from
Feb 7, 2019
38 changes: 18 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" }}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -200,8 +199,7 @@ jobs:
- run:
name: Install NPM modules
command: |
rm -rf node_modules
npm install
yarn

- run:
name: Fix known build error
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion __mocks__/react-native-device-info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
getModel: () => '',
getReadableVersion: () => ''
getReadableVersion: () => '',
getBundleId: () => ''
};
3 changes: 2 additions & 1 deletion app/containers/EmojiPicker/EmojiCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion app/containers/MessageBox/Recording.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export default class extends React.PureComponent {
/>
</BorderlessButton>
</View>
</SafeAreaView>);
</SafeAreaView>
);
}
}
4 changes: 1 addition & 3 deletions app/lib/methods/canOpenRoom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as SDK from '@rocket.chat/sdk';

import database from '../realm';

const restTypes = {
Expand All @@ -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)) {
Expand Down
4 changes: 1 addition & 3 deletions app/lib/methods/getCustomEmojis.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions app/lib/methods/getPermissions.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down
20 changes: 7 additions & 13 deletions app/lib/methods/getRooms.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions app/lib/methods/getSettings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InteractionManager } from 'react-native';
import * as SDK from '@rocket.chat/sdk';

import reduxStore from '../createStore';
import database from '../realm';
Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions app/lib/methods/helpers/mergeSubscriptionsRooms.js
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -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') {
Expand Down
10 changes: 4 additions & 6 deletions app/lib/methods/loadMessagesForRoom.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 [];
}
Expand All @@ -25,23 +24,22 @@ 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 [];
}
return data.messages;
}

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);
});
Expand Down
17 changes: 11 additions & 6 deletions app/lib/methods/loadMissedMessages.js
Original file line number Diff line number Diff line change
@@ -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));
Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions app/lib/methods/readMessages.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as SDK from '@rocket.chat/sdk';

import database from '../realm';
import log from '../../utils/log';

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;
Expand Down
Loading