[FIX] Deeplinking without RoomId (#1925)

* [FIX] Deeplinking without rid

* [FIX] Join channel

* [FIX] Deep linking without rid

* Update app/lib/methods/canOpenRoom.js

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Djorkaeff Alexandre 2020-04-01 16:39:30 -03:00 committed by GitHub
parent 9f830c7f0a
commit 18afdd843e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 24 deletions

View File

@ -4,15 +4,51 @@ const restTypes = {
channel: 'channels', direct: 'im', group: 'groups'
};
async function open({ type, rid }) {
async function open({ type, rid, name }) {
try {
// RC 0.61.0
await this.sdk.post(`${ restTypes[type] }.open`, { roomId: rid });
return true;
} catch (e) {
if (e.data && /is already open/.test(e.data.error)) {
return true;
const params = rid ? { roomId: rid } : { roomName: name };
// if it's a direct link without rid we'll create a new dm
// if the dm already exists it'll return the existent
if (type === 'direct' && !rid) {
const result = await this.createDirectMessage(name);
if (result.success) {
const { room } = result;
room.rid = room._id;
return room;
}
}
// if it's a group we need to check if you can open
if (type === 'group') {
try {
// RC 0.61.0
await this.sdk.post(`${ restTypes[type] }.open`, params);
} catch (e) {
if (!(e.data && /is already open/.test(e.data.error))) {
return false;
}
}
}
// if it's a channel or group and the link don't have rid
// we'll get info from the room
if ((type === 'channel' || type === 'group') && !rid) {
// RC 0.72.0
const result = await this.sdk.get(`${ restTypes[type] }.info`, params);
if (result.success) {
const room = result[type];
room.rid = room._id;
return room;
}
}
// if rid was sent by link
if (rid) {
return { rid };
}
return false;
} catch (e) {
return false;
}
}
@ -21,20 +57,19 @@ export default async function canOpenRoom({ rid, path }) {
try {
const db = database.active;
const subsCollection = db.collections.get('subscriptions');
const [type] = path.split('/');
if (type === 'channel') {
return true;
const [type, name] = path.split('/');
if (rid) {
try {
await subsCollection.find(rid);
return { rid };
} catch (e) {
// Do nothing
}
}
try {
await subsCollection.find(rid);
return true;
} catch (error) {
// Do nothing
}
try {
return await open.call(this, { type, rid });
return await open.call(this, { type, rid, name });
} catch (e) {
return false;
}

View File

@ -29,12 +29,12 @@ const handleInviteLink = function* handleInviteLink({ params, requireLogin = fal
const navigate = function* navigate({ params }) {
yield put(appStart('inside'));
if (params.rid) {
const canOpenRoom = yield RocketChat.canOpenRoom(params);
if (canOpenRoom) {
const [type, name] = params.path.split('/');
if (params.path) {
const room = yield RocketChat.canOpenRoom(params);
const [type, name] = params.path.split('/');
if (room) {
yield Navigation.navigate('RoomsListView');
Navigation.navigate('RoomView', { rid: params.rid, name, t: roomTypes[type] });
Navigation.navigate('RoomView', { name, t: roomTypes[type], ...room });
}
} else {
yield handleInviteLink({ params });

View File

@ -164,10 +164,11 @@ class RoomView extends React.Component {
const selectedMessage = props.navigation.getParam('message');
const name = props.navigation.getParam('name');
const fname = props.navigation.getParam('fname');
const prid = props.navigation.getParam('prid');
this.state = {
joined: true,
room: room || {
rid: this.rid, t: this.t, name, fname
rid: this.rid, t: this.t, name, fname, prid
},
roomUpdate: {},
member: {},