[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) => { getPermalink = async(message) => {
try { try {
return await RocketChat.getPermalink(message); return await RocketChat.getPermalinkMessage(message);
} catch (error) { } catch (error) {
return null; return null;
} }

View File

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

View File

@ -527,7 +527,7 @@ const RocketChat = {
} }
return Promise.resolve(result); return Promise.resolve(result);
}, },
async getPermalink(message) { async getPermalinkMessage(message) {
let room; let room;
try { try {
room = await RocketChat.getRoom(message.rid); room = await RocketChat.getRoom(message.rid);
@ -543,6 +543,15 @@ const RocketChat = {
}[room.t]; }[room.t];
return `${ server }/${ roomType }/${ room.name }?msg=${ message._id }`; 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) { subscribe(...args) {
return this.sdk.subscribe(...args); return this.sdk.subscribe(...args);
}, },

View File

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

View File

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