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

chore: improve error when create message is not allowed #5597

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions app/lib/methods/helpers/emitErrorCreateDirectMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { LISTENER } from '../../../containers/Toast';
import i18n from '../../../i18n';
import EventEmitter from './events';
import log from './log';

export const emitErrorCreateDirectMessage = (e: any): void => {
if (e?.errorType === 'error-not-allowed') {
if (e?.details?.method === 'createDirectMessage')
EventEmitter.emit(LISTENER, {
message: i18n.t('error-action-not-allowed', { action: i18n.t('Create_Direct_Messages') })
});
} else {
log(e);
}
};
5 changes: 3 additions & 2 deletions app/lib/methods/helpers/goRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Navigation from '../../navigation/appNavigation';
import { IOmnichannelRoom, SubscriptionType, IVisitor, TSubscriptionModel, ISubscription } from '../../../definitions';
import { getRoomTitle, getUidDirectMessage } from './helpers';
import { Services } from '../../services';
import { emitErrorCreateDirectMessage } from './emitErrorCreateDirectMessage';

interface IGoRoomItem {
search?: boolean; // comes from spotlight
Expand Down Expand Up @@ -111,8 +112,8 @@ export const goRoom = async ({
...props
});
}
} catch {
// Do nothing
} catch (e: any) {
emitErrorCreateDirectMessage(e?.data);
}
}

Expand Down
13 changes: 5 additions & 8 deletions app/views/RoomInfoView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import UAParser from 'ua-parser-js';
import * as HeaderButton from '../../containers/HeaderButton';
import SafeAreaView from '../../containers/SafeAreaView';
import StatusBar from '../../containers/StatusBar';
import { LISTENER } from '../../containers/Toast';
import { ISubscription, IUser, SubscriptionType } from '../../definitions';
import I18n from '../../i18n';
import { getSubscriptionByRoomId } from '../../lib/database/services/Subscription';
import { useAppSelector } from '../../lib/hooks';
import { getRoomTitle, getUidDirectMessage, hasPermission } from '../../lib/methods/helpers';
import EventEmitter from '../../lib/methods/helpers/events';
import { goRoom } from '../../lib/methods/helpers/goRoom';
import { handleIgnore } from '../../lib/methods/helpers/handleIgnore';
import log, { events, logEvent } from '../../lib/methods/helpers/log';
Expand All @@ -29,6 +27,7 @@ import RoomInfoViewAvatar from './components/RoomInfoViewAvatar';
import RoomInfoViewBody from './components/RoomInfoViewBody';
import RoomInfoViewTitle from './components/RoomInfoViewTitle';
import styles from './styles';
import { emitErrorCreateDirectMessage } from '../../lib/methods/helpers/emitErrorCreateDirectMessage';

type TRoomInfoViewNavigationProp = CompositeNavigationProp<
StackNavigationProp<ChatsStackParamList, 'RoomInfoView'>,
Expand Down Expand Up @@ -215,8 +214,8 @@ const RoomInfoView = (): React.ReactElement => {
try {
const result = await Services.createDirectMessage(roomUser.username);
if (result.success) return resolve({ ...roomUser, rid: result.room.rid });
} catch {
reject();
} catch (e) {
reject(e);
}
});

Expand Down Expand Up @@ -251,10 +250,8 @@ const RoomInfoView = (): React.ReactElement => {
if (direct) r = direct;
}
handleGoRoom(r);
} catch {
EventEmitter.emit(LISTENER, {
message: I18n.t('error-action-not-allowed', { action: I18n.t('Create_Direct_Messages') })
});
} catch (e: any) {
emitErrorCreateDirectMessage(e?.data);
}
};

Expand Down
5 changes: 3 additions & 2 deletions app/views/RoomMembersView/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import appNavigation from '../../lib/navigation/appNavigation';
import { Services } from '../../lib/services';
import database from '../../lib/database';
import { RoomTypes } from '../../lib/methods';
import { emitErrorCreateDirectMessage } from '../../lib/methods/helpers/emitErrorCreateDirectMessage';

export type TRoomType = SubscriptionType.CHANNEL | SubscriptionType.GROUP | SubscriptionType.OMNICHANNEL;

Expand Down Expand Up @@ -89,8 +90,8 @@ export const navToDirectMessage = async (item: IUser, isMasterDetail: boolean):
handleGoRoom({ rid: result.room?._id as string, name: item.username, t: SubscriptionType.DIRECT }, isMasterDetail);
}
}
} catch (e) {
log(e);
} catch (e: any) {
emitErrorCreateDirectMessage(e?.data);
}
};

Expand Down