feat: enable navigate to my own profile from messages (#5293)
* enable navigation to my own profile * fix block user logic * fix types * enable navigation to my own profile * update snapshot
This commit is contained in:
parent
5db7088251
commit
fd7c9176b1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -9,17 +9,19 @@ import { SubscriptionType } from '../../definitions';
|
||||||
const MessageAvatar = React.memo(({ isHeader, avatar, author, small, navToRoomInfo, emoji, getCustomEmoji }: IMessageAvatar) => {
|
const MessageAvatar = React.memo(({ isHeader, avatar, author, small, navToRoomInfo, emoji, getCustomEmoji }: IMessageAvatar) => {
|
||||||
const { user } = useContext(MessageContext);
|
const { user } = useContext(MessageContext);
|
||||||
if (isHeader && author) {
|
if (isHeader && author) {
|
||||||
const navParam = {
|
const onPress = () =>
|
||||||
t: SubscriptionType.DIRECT,
|
navToRoomInfo({
|
||||||
rid: author._id
|
t: SubscriptionType.DIRECT,
|
||||||
};
|
rid: author._id,
|
||||||
|
itsMe: author._id === user.id
|
||||||
|
});
|
||||||
return (
|
return (
|
||||||
<Avatar
|
<Avatar
|
||||||
style={small ? styles.avatarSmall : styles.avatar}
|
style={small ? styles.avatarSmall : styles.avatar}
|
||||||
text={avatar ? '' : author.username}
|
text={avatar ? '' : author.username}
|
||||||
size={small ? 20 : 36}
|
size={small ? 20 : 36}
|
||||||
borderRadius={4}
|
borderRadius={4}
|
||||||
onPress={author._id === user.id ? undefined : () => navToRoomInfo(navParam)}
|
onPress={onPress}
|
||||||
getCustomEmoji={getCustomEmoji}
|
getCustomEmoji={getCustomEmoji}
|
||||||
avatar={avatar}
|
avatar={avatar}
|
||||||
emoji={emoji}
|
emoji={emoji}
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
|
import moment from 'moment';
|
||||||
import React, { useContext } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
||||||
import moment from 'moment';
|
|
||||||
|
|
||||||
import { themes } from '../../lib/constants';
|
|
||||||
import { useTheme } from '../../theme';
|
|
||||||
import sharedStyles from '../../views/Styles';
|
|
||||||
import messageStyles from './styles';
|
|
||||||
import MessageContext from './Context';
|
|
||||||
import { messageHaveAuthorName } from './utils';
|
|
||||||
import { MessageType, MessageTypesValues, SubscriptionType } from '../../definitions';
|
import { MessageType, MessageTypesValues, SubscriptionType } from '../../definitions';
|
||||||
|
import { useTheme } from '../../theme';
|
||||||
import { IRoomInfoParam } from '../../views/SearchMessagesView';
|
import { IRoomInfoParam } from '../../views/SearchMessagesView';
|
||||||
|
import sharedStyles from '../../views/Styles';
|
||||||
import RightIcons from './Components/RightIcons';
|
import RightIcons from './Components/RightIcons';
|
||||||
|
import MessageContext from './Context';
|
||||||
|
import messageStyles from './styles';
|
||||||
|
import { messageHaveAuthorName } from './utils';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
|
@ -66,21 +65,21 @@ interface IMessageUser {
|
||||||
const User = React.memo(
|
const User = React.memo(
|
||||||
({ isHeader, useRealName, author, alias, ts, timeFormat, hasError, navToRoomInfo, type, isEdited, ...props }: IMessageUser) => {
|
({ isHeader, useRealName, author, alias, ts, timeFormat, hasError, navToRoomInfo, type, isEdited, ...props }: IMessageUser) => {
|
||||||
const { user } = useContext(MessageContext);
|
const { user } = useContext(MessageContext);
|
||||||
const { theme } = useTheme();
|
const { colors } = useTheme();
|
||||||
|
|
||||||
if (isHeader) {
|
if (isHeader) {
|
||||||
const username = (useRealName && author?.name) || author?.username;
|
const username = (useRealName && author?.name) || author?.username;
|
||||||
const aliasUsername = alias ? (
|
const aliasUsername = alias ? <Text style={[styles.alias, { color: colors.auxiliaryText }]}> @{username}</Text> : null;
|
||||||
<Text style={[styles.alias, { color: themes[theme].auxiliaryText }]}> @{username}</Text>
|
|
||||||
) : null;
|
|
||||||
const time = moment(ts).format(timeFormat);
|
const time = moment(ts).format(timeFormat);
|
||||||
|
const itsMe = author?._id === user.id;
|
||||||
|
|
||||||
const onUserPress = () => {
|
const onUserPress = () => {
|
||||||
navToRoomInfo?.({
|
navToRoomInfo?.({
|
||||||
t: SubscriptionType.DIRECT,
|
t: SubscriptionType.DIRECT,
|
||||||
rid: author?._id || ''
|
rid: author?._id || '',
|
||||||
|
itsMe
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const isDisabled = author?._id === user.id;
|
|
||||||
|
|
||||||
const textContent = (
|
const textContent = (
|
||||||
<>
|
<>
|
||||||
|
@ -88,14 +87,10 @@ const User = React.memo(
|
||||||
{aliasUsername}
|
{aliasUsername}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (messageHaveAuthorName(type as MessageTypesValues)) {
|
if (messageHaveAuthorName(type as MessageTypesValues)) {
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text style={[styles.usernameInfoMessage, { color: colors.titleText }]} onPress={onUserPress}>
|
||||||
style={[styles.usernameInfoMessage, { color: themes[theme].titleText }]}
|
|
||||||
onPress={onUserPress}
|
|
||||||
// @ts-ignore // TODO - check this prop
|
|
||||||
disabled={isDisabled}
|
|
||||||
>
|
|
||||||
{textContent}
|
{textContent}
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
|
@ -103,11 +98,11 @@ const User = React.memo(
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<TouchableOpacity style={styles.titleContainer} onPress={onUserPress} disabled={isDisabled}>
|
<TouchableOpacity style={styles.titleContainer} onPress={onUserPress}>
|
||||||
<Text style={[styles.username, { color: themes[theme].titleText }]} numberOfLines={1}>
|
<Text style={[styles.username, { color: colors.titleText }]} numberOfLines={1}>
|
||||||
{textContent}
|
{textContent}
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={[messageStyles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
|
<Text style={[messageStyles.time, { color: colors.auxiliaryText }]}>{time}</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<RightIcons
|
<RightIcons
|
||||||
type={type}
|
type={type}
|
||||||
|
|
|
@ -21,6 +21,10 @@ export function getUidDirectMessage(room) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (room.itsMe) {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
// legacy method
|
// legacy method
|
||||||
if (!room?.uids && room.rid && room.t === 'd' && userId) {
|
if (!room?.uids && room.rid && room.t === 'd' && userId) {
|
||||||
return room.rid.replace(userId, '').trim();
|
return room.rid.replace(userId, '').trim();
|
||||||
|
|
|
@ -69,6 +69,7 @@ export type ChatsStackParamList = {
|
||||||
t: SubscriptionType;
|
t: SubscriptionType;
|
||||||
showCloseModal?: boolean;
|
showCloseModal?: boolean;
|
||||||
fromRid?: string;
|
fromRid?: string;
|
||||||
|
itsMe?: boolean;
|
||||||
};
|
};
|
||||||
RoomInfoEditView: {
|
RoomInfoEditView: {
|
||||||
rid: string;
|
rid: string;
|
||||||
|
|
|
@ -126,10 +126,7 @@ class MessagesView extends React.Component<IMessagesViewProps, IMessagesViewStat
|
||||||
};
|
};
|
||||||
|
|
||||||
navToRoomInfo = (navParam: IRoomInfoParam) => {
|
navToRoomInfo = (navParam: IRoomInfoParam) => {
|
||||||
const { navigation, user } = this.props;
|
const { navigation } = this.props;
|
||||||
if (navParam.rid === user.id) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
navigation.navigate('RoomInfoView', navParam);
|
navigation.navigate('RoomInfoView', navParam);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -75,15 +75,14 @@ export const RoomInfoButtons = ({
|
||||||
}: IRoomInfoButtons): React.ReactElement => {
|
}: IRoomInfoButtons): React.ReactElement => {
|
||||||
const room = roomFromRid || roomFromProps;
|
const room = roomFromRid || roomFromProps;
|
||||||
// Following the web behavior, when is a DM with myself, shouldn't appear block or ignore option
|
// Following the web behavior, when is a DM with myself, shouldn't appear block or ignore option
|
||||||
const isDmWithMyself = room?.uids && room.uids?.filter((uid: string) => uid !== roomUserId).length === 0;
|
const isDmWithMyself = room?.uids?.filter((uid: string) => uid !== roomUserId).length === 0;
|
||||||
|
|
||||||
const isFromDm = room?.t === SubscriptionType.DIRECT;
|
const isFromDm = room?.t === SubscriptionType.DIRECT;
|
||||||
const isDirectFromSaved = isDirect && fromRid && room;
|
const isDirectFromSaved = isDirect && fromRid && room;
|
||||||
const isIgnored = room?.ignored?.includes?.(roomUserId || '');
|
const isIgnored = room?.ignored?.includes?.(roomUserId || '');
|
||||||
const isBlocked = room?.blocker;
|
const isBlocked = room?.blocker;
|
||||||
|
|
||||||
const renderIgnoreUser = isDirectFromSaved && !isFromDm && !isDmWithMyself;
|
const renderIgnoreUser = isDirectFromSaved && !isFromDm && !isDmWithMyself;
|
||||||
const renderBlockUser = isDirectFromSaved && isFromDm;
|
const renderBlockUser = isDirectFromSaved && isFromDm && !isDmWithMyself;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.roomButtonsContainer}>
|
<View style={styles.roomButtonsContainer}>
|
||||||
|
|
|
@ -39,7 +39,7 @@ type TRoomInfoViewRouteProp = RouteProp<ChatsStackParamList, 'RoomInfoView'>;
|
||||||
|
|
||||||
const RoomInfoView = (): React.ReactElement => {
|
const RoomInfoView = (): React.ReactElement => {
|
||||||
const {
|
const {
|
||||||
params: { rid, t, fromRid, member, room: roomParam, showCloseModal }
|
params: { rid, t, fromRid, member, room: roomParam, showCloseModal, itsMe }
|
||||||
} = useRoute<TRoomInfoViewRouteProp>();
|
} = useRoute<TRoomInfoViewRouteProp>();
|
||||||
const { addListener, setOptions, navigate, goBack } = useNavigation<TRoomInfoViewNavigationProp>();
|
const { addListener, setOptions, navigate, goBack } = useNavigation<TRoomInfoViewNavigationProp>();
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ const RoomInfoView = (): React.ReactElement => {
|
||||||
const loadUser = async () => {
|
const loadUser = async () => {
|
||||||
if (isEmpty(roomUser)) {
|
if (isEmpty(roomUser)) {
|
||||||
try {
|
try {
|
||||||
const roomUserId = getUidDirectMessage(room || { rid, t });
|
const roomUserId = getUidDirectMessage(room || { rid, t, itsMe });
|
||||||
const result = await Services.getUserInfo(roomUserId);
|
const result = await Services.getUserInfo(roomUserId);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const { user } = result;
|
const { user } = result;
|
||||||
|
|
|
@ -1133,13 +1133,9 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
navToRoomInfo = (navParam: any) => {
|
navToRoomInfo = (navParam: any) => {
|
||||||
const { navigation, user, isMasterDetail } = this.props;
|
const { navigation, isMasterDetail } = this.props;
|
||||||
const { room } = this.state;
|
const { room } = this.state;
|
||||||
|
|
||||||
logEvent(events[`ROOM_GO_${navParam.t === 'd' ? 'USER' : 'ROOM'}_INFO`]);
|
logEvent(events[`ROOM_GO_${navParam.t === 'd' ? 'USER' : 'ROOM'}_INFO`]);
|
||||||
if (navParam.rid === user.id) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
navParam.fromRid = room.rid;
|
navParam.fromRid = room.rid;
|
||||||
if (isMasterDetail) {
|
if (isMasterDetail) {
|
||||||
navParam.showCloseModal = true;
|
navParam.showCloseModal = true;
|
||||||
|
|
|
@ -55,6 +55,7 @@ export interface IRoomInfoParam {
|
||||||
rid: string;
|
rid: string;
|
||||||
t: SubscriptionType;
|
t: SubscriptionType;
|
||||||
joined?: boolean;
|
joined?: boolean;
|
||||||
|
itsMe?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface INavigationOption {
|
interface INavigationOption {
|
||||||
|
|
Loading…
Reference in New Issue