aboutsummaryrefslogtreecommitdiff
path: root/src/components/messages
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-04-23 16:35:57 -0400
committerGitHub <noreply@github.com>2021-04-23 16:35:57 -0400
commit5acc51f2d74ee536aeb4d7dcf94aba4ab63b4ed7 (patch)
tree9ec51d37a648690333b7832c73b2fa4eca16f254 /src/components/messages
parent0b18b88f2b1e141a8b8372b08c0ce8e7eaecbc1c (diff)
parent1c225f0dd7caaffa9501f9a86a1e1f9937b36f56 (diff)
Merge pull request #381 from IvanIFChen/tma804-chat-delete-channel
[TMA-804] Mute/unmute chat channel
Diffstat (limited to 'src/components/messages')
-rw-r--r--src/components/messages/ChannelPreview.tsx139
1 files changed, 104 insertions, 35 deletions
diff --git a/src/components/messages/ChannelPreview.tsx b/src/components/messages/ChannelPreview.tsx
index 4c3eb9d8..3d31d42a 100644
--- a/src/components/messages/ChannelPreview.tsx
+++ b/src/components/messages/ChannelPreview.tsx
@@ -1,10 +1,15 @@
import {useNavigation} from '@react-navigation/core';
-import React, {useContext} from 'react';
+import React, {useContext, useState} from 'react';
import {Image, StyleSheet, Text, View} from 'react-native';
-import {TouchableOpacity} from 'react-native-gesture-handler';
+import {
+ RectButton,
+ Swipeable,
+ TouchableOpacity,
+} from 'react-native-gesture-handler';
import {useStore} from 'react-redux';
import {ChannelPreviewMessengerProps} from 'stream-chat-react-native';
import {ChatContext} from '../../App';
+import Trash from '../../assets/ionicons/trash-outline.svg';
import {TAGG_LIGHT_BLUE_2} from '../../constants';
import {
LocalAttachmentType,
@@ -36,6 +41,10 @@ const ChannelPreview: React.FC<
const member = getMember(channel, state);
const online = isOnline(member?.user?.last_active);
const unread = channel.state.unreadCount > 0;
+ const [isMuted, setIsMuted] = useState(channel.muteStatus().muted);
+ const mutedImage = isMuted
+ ? require('../../assets/images/unmute.png')
+ : require('../../assets/images/mute.png');
// Hide channel if no message was exchanged
if (channel.state.messages.length === 0) {
@@ -43,39 +52,68 @@ const ChannelPreview: React.FC<
}
return (
- <TouchableOpacity
- style={styles.container}
- onPress={() => {
- setChannel(channel);
- navigation.navigate('Chat');
- }}>
- <View>
- <Image
- style={styles.avatar}
- source={
- member
- ? {uri: member.user?.thumbnail_url}
- : require('../../assets/images/avatar-placeholder.png')
- }
- />
- {online && <View style={styles.online} />}
- </View>
- <View style={styles.content}>
- <Text
- style={[styles.name, unread ? styles.unread : {}]}
- numberOfLines={1}>
- {member?.user?.first_name} {member?.user?.last_name}
- </Text>
- <Text
- style={[styles.lastMessage, unread ? styles.unread : {}]}
- numberOfLines={1}>
- {channel.state.messages.length > 0
- ? channel.state.messages[channel.state.messages.length - 1].text
- : ''}
- </Text>
- </View>
- {unread && <View style={styles.purpleDot} />}
- </TouchableOpacity>
+ <Swipeable
+ overshootLeft={false}
+ overshootRight={false}
+ renderRightActions={() => (
+ <View style={styles.swipeableContainer}>
+ <RectButton
+ style={styles.muteButton}
+ onPress={() => {
+ if (isMuted) {
+ channel.unmute();
+ } else {
+ channel.mute();
+ }
+ setIsMuted(!isMuted);
+ }}>
+ <Image source={mutedImage} style={styles.icon} />
+ <Text style={styles.actionText}>{isMuted ? 'Unmute' : 'Mute'}</Text>
+ </RectButton>
+ <RectButton
+ style={styles.deleteButton}
+ onPress={() => {
+ channel.hide();
+ }}>
+ <Trash style={styles.icon} color={'white'} />
+ <Text style={styles.actionText}>Delete</Text>
+ </RectButton>
+ </View>
+ )}>
+ <TouchableOpacity
+ style={styles.container}
+ onPress={() => {
+ setChannel(channel);
+ navigation.navigate('Chat');
+ }}>
+ <View>
+ <Image
+ style={styles.avatar}
+ source={
+ member
+ ? {uri: member.user?.thumbnail_url}
+ : require('../../assets/images/avatar-placeholder.png')
+ }
+ />
+ {online && <View style={styles.online} />}
+ </View>
+ <View style={styles.content}>
+ <Text
+ style={[styles.name, unread ? styles.unread : {}]}
+ numberOfLines={1}>
+ {member?.user?.first_name} {member?.user?.last_name}
+ </Text>
+ <Text
+ style={[styles.lastMessage, unread ? styles.unread : {}]}
+ numberOfLines={1}>
+ {channel.state.messages.length > 0
+ ? channel.state.messages[channel.state.messages.length - 1].text
+ : ''}
+ </Text>
+ </View>
+ {unread && <View style={styles.purpleDot} />}
+ </TouchableOpacity>
+ </Swipeable>
);
};
@@ -133,6 +171,37 @@ const styles = StyleSheet.create({
borderRadius: normalize(10) / 2,
marginLeft: '5%',
},
+ swipeableContainer: {
+ alignItems: 'center',
+ justifyContent: 'center',
+ flexDirection: 'row',
+ },
+ muteButton: {
+ width: 72,
+ height: '100%',
+ justifyContent: 'center',
+ alignItems: 'center',
+ backgroundColor: '#C4C4C4',
+ },
+ deleteButton: {
+ width: 72,
+ height: '100%',
+ justifyContent: 'center',
+ alignItems: 'center',
+ backgroundColor: '#C42634',
+ },
+ actionText: {
+ color: 'white',
+ fontSize: normalize(12),
+ fontWeight: '500',
+ backgroundColor: 'transparent',
+ paddingHorizontal: '5%',
+ marginTop: '5%',
+ },
+ icon: {
+ width: normalize(25),
+ height: normalize(25),
+ },
});
export default ChannelPreview;