[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' channel: 'channels', direct: 'im', group: 'groups'
}; };
async function open({ type, rid }) { async function open({ type, rid, name }) {
try { try {
// RC 0.61.0 const params = rid ? { roomId: rid } : { roomName: name };
await this.sdk.post(`${ restTypes[type] }.open`, { roomId: rid });
return true; // if it's a direct link without rid we'll create a new dm
} catch (e) { // if the dm already exists it'll return the existent
if (e.data && /is already open/.test(e.data.error)) { if (type === 'direct' && !rid) {
return true; 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; return false;
} }
} }
@ -21,20 +57,19 @@ export default async function canOpenRoom({ rid, path }) {
try { try {
const db = database.active; const db = database.active;
const subsCollection = db.collections.get('subscriptions'); const subsCollection = db.collections.get('subscriptions');
const [type] = path.split('/'); const [type, name] = path.split('/');
if (type === 'channel') {
return true; if (rid) {
try {
await subsCollection.find(rid);
return { rid };
} catch (e) {
// Do nothing
}
} }
try { try {
await subsCollection.find(rid); return await open.call(this, { type, rid, name });
return true;
} catch (error) {
// Do nothing
}
try {
return await open.call(this, { type, rid });
} catch (e) { } catch (e) {
return false; return false;
} }

View File

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

View File

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