[IMPROVEMENT] Share channel (#908)

* Generate and share permalink to rooms

* Create constant to share type

* Fix unnecessary await

* Remove unnecessary test

* Revert delete e2e test
This commit is contained in:
Djorkaeff Alexandre 2019-05-29 18:19:12 -03:00 committed by Diego Mello
parent b1eb18351f
commit 29286e98a8
5 changed files with 29 additions and 11 deletions

View File

@ -155,7 +155,7 @@ export default class MessageActions extends React.Component {
getPermalink = async(message) => {
try {
return await RocketChat.getPermalink(message);
return await RocketChat.getPermalinkMessage(message);
} catch (error) {
return null;
}

View File

@ -245,7 +245,7 @@ class MessageBox extends Component {
getPermalink = async(message) => {
try {
return await RocketChat.getPermalink(message);
return await RocketChat.getPermalinkMessage(message);
} catch (error) {
return null;
}

View File

@ -527,7 +527,7 @@ const RocketChat = {
}
return Promise.resolve(result);
},
async getPermalink(message) {
async getPermalinkMessage(message) {
let room;
try {
room = await RocketChat.getRoom(message.rid);
@ -543,6 +543,15 @@ const RocketChat = {
}[room.t];
return `${ server }/${ roomType }/${ room.name }?msg=${ message._id }`;
},
getPermalinkChannel(channel) {
const { server } = reduxStore.getState().server;
const roomType = {
p: 'group',
c: 'channel',
d: 'direct'
}[channel.t];
return `${ server }/${ roomType }/${ channel.name }`;
},
subscribe(...args) {
return this.sdk.subscribe(...args);
},

View File

@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
View, SectionList, Text, Alert
View, SectionList, Text, Alert, Share
} from 'react-native';
import { connect } from 'react-redux';
import { SafeAreaView } from 'react-navigation';
@ -241,7 +241,7 @@ export default class RoomActionsView extends React.Component {
{
icon: 'share',
name: I18n.t('Share'),
disabled: true,
event: this.handleShare,
testID: 'room-actions-share'
},
{
@ -351,6 +351,14 @@ export default class RoomActionsView extends React.Component {
}
}
handleShare = () => {
const { room } = this.state;
const permalink = RocketChat.getPermalinkChannel(room);
Share.share({
message: permalink
});
};
leaveChannel = () => {
const { room } = this.state;
const { leaveRoom } = this.props;

View File

@ -187,12 +187,13 @@ describe('Room actions screen', () => {
await expect(element(by.id('room-actions-view'))).toBeVisible();
});
it('should NOT navigate to share messages', async() => {
await waitFor(element(by.id('room-actions-share'))).toBeVisible().whileElement(by.id('room-actions-list')).scroll(scrollDown, 'down');
await element(by.id('room-actions-share')).tap();
await waitFor(element(by.id('room-actions-view'))).toBeVisible().withTimeout(2000);
await expect(element(by.id('room-actions-view'))).toBeVisible();
});
// TODO: test share room link
// it('should NOT navigate to share room', async() => {
// await waitFor(element(by.id('room-actions-share'))).toBeVisible().whileElement(by.id('room-actions-list')).scroll(scrollDown, 'down');
// await element(by.id('room-actions-share')).tap();
// await waitFor(element(by.id('room-actions-view'))).toBeVisible().withTimeout(2000);
// await expect(element(by.id('room-actions-view'))).toBeVisible();
// });
after(async() => {
takeScreenshot();