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

feat: create notification in room view #5250

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/lib/constants/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const colors = {
badgeBackgroundLevel3: '#F38C39',
statusFontOnDanger: '#9B1325',
statusFontOnSuccess: '#148660',
fontDanger: '#D40C26',
...mentions,
...callButtons
},
Expand Down Expand Up @@ -193,6 +194,7 @@ export const colors = {
badgeBackgroundLevel3: '#F38C39',
statusFontOnDanger: '#9B1325',
statusFontOnSuccess: '#148660',
fontDanger: '#D40C26',
...mentions,
...callButtons
},
Expand Down Expand Up @@ -278,6 +280,7 @@ export const colors = {
badgeBackgroundLevel3: '#F38C39',
statusFontOnDanger: '#9B1325',
statusFontOnSuccess: '#148660',
fontDanger: '#D40C26',
...mentions,
...callButtons
}
Expand Down
48 changes: 44 additions & 4 deletions app/views/RoomView/RightButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { getUserSelector } from '../../selectors/login';
import { TNavigation } from '../../stacks/stackType';
import { ChatsStackParamList } from '../../stacks/types';
import HeaderCallButton from './components/HeaderCallButton';
import { TSupportedThemes } from '../../theme';
import { themes } from '../../lib/constants';

interface IRightButtonsProps extends Pick<ISubscription, 't'> {
userId?: string;
Expand All @@ -43,6 +45,7 @@ interface IRightButtonsProps extends Pick<ISubscription, 't'> {
showActionSheet: Function;
departmentId?: string;
rid?: string;
theme: TSupportedThemes;
}

interface IRigthButtonsState {
Expand All @@ -52,9 +55,12 @@ interface IRigthButtonsState {
tunreadGroup: string[];
}

const notificationIsEnabled = true;
reinaldonetof marked this conversation as resolved.
Show resolved Hide resolved

class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsState> {
private threadSubscription?: Subscription;
private subSubscription?: Subscription;
private room?: TSubscriptionModel;

constructor(props: IRightButtonsProps) {
super(props);
Expand All @@ -80,8 +86,8 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
if (rid) {
try {
const subCollection = db.get('subscriptions');
const subRecord = await subCollection.find(rid);
this.observeSubscription(subRecord);
this.room = await subCollection.find(rid);
this.observeSubscription(this.room);
} catch (e) {
console.log("Can't find subscription to observe.");
}
Expand All @@ -90,7 +96,7 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS

shouldComponentUpdate(nextProps: IRightButtonsProps, nextState: IRigthButtonsState) {
const { isFollowingThread, tunread, tunreadUser, tunreadGroup } = this.state;
const { teamId, status, joined, omnichannelPermissions } = this.props;
const { teamId, status, joined, omnichannelPermissions, theme } = this.props;
if (nextProps.teamId !== teamId) {
return true;
}
Expand All @@ -100,6 +106,9 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
if (nextProps.joined !== joined) {
return true;
}
if (nextProps.theme !== theme) {
return true;
}
if (nextState.isFollowingThread !== isFollowingThread) {
return true;
}
Expand Down Expand Up @@ -288,6 +297,31 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
showActionSheet({ options });
};

goToNotification = () => {
const { room } = this;
const { rid, navigation, isMasterDetail } = this.props;

if (!rid || !room) {
return;
}
if (notificationIsEnabled && room) {
if (isMasterDetail) {
navigation.navigate('ModalStackNavigator', {
screen: 'NotificationPrefView',
params: { rid, room }
reinaldonetof marked this conversation as resolved.
Show resolved Hide resolved
});
} else {
navigation.navigate('NotificationPrefView', { rid, room });
}
} else if (isMasterDetail) {
navigation.navigate('ModalStackNavigator', {
screen: 'PushTroubleshootView'
});
} else {
navigation.navigate('PushTroubleshootView');
}
};

goSearchView = () => {
logEvent(events.ROOM_GO_SEARCH);
const { rid, t, navigation, isMasterDetail, encrypted } = this.props;
Expand Down Expand Up @@ -321,7 +355,7 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS

render() {
const { isFollowingThread, tunread, tunreadUser, tunreadGroup } = this.state;
const { t, tmid, threadsEnabled, rid } = this.props;
const { t, tmid, threadsEnabled, rid, theme } = this.props;

if (t === 'l') {
if (!this.isOmnichannelPreview()) {
Expand All @@ -346,6 +380,12 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
}
return (
<HeaderButton.Container>
<HeaderButton.Item
color={notificationIsEnabled ? themes[theme].headerTintColor : themes[theme].fontDanger}
reinaldonetof marked this conversation as resolved.
Show resolved Hide resolved
iconName='notification-disabled'
onPress={this.goToNotification}
testID='room-view-push-troubleshoot'
/>
{rid ? <HeaderCallButton rid={rid} /> : null}
{threadsEnabled ? (
<HeaderButton.Item
Expand Down
1 change: 1 addition & 0 deletions app/views/RoomView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
toggleFollowThread={this.toggleFollowThread}
showActionSheet={this.showActionSheet}
departmentId={departmentId}
theme={theme}
/>
)
});
Expand Down