2021-09-13 20:41:05 +00:00
|
|
|
import { call, put, select, take, takeLatest } from 'redux-saga/effects';
|
2020-02-21 15:59:13 +00:00
|
|
|
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
2018-07-10 13:40:32 +00:00
|
|
|
|
2017-09-01 19:42:50 +00:00
|
|
|
import { CREATE_CHANNEL, LOGIN } from '../actions/actionsTypes';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { createChannelFailure, createChannelSuccess } from '../actions/createChannel';
|
2020-04-01 12:28:54 +00:00
|
|
|
import { showErrorAlert } from '../utils/info';
|
2022-04-07 13:22:19 +00:00
|
|
|
import Navigation from '../lib/navigation/appNavigation';
|
2020-02-21 15:59:13 +00:00
|
|
|
import database from '../lib/database';
|
2020-04-01 12:28:54 +00:00
|
|
|
import I18n from '../i18n';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { events, logEvent } from '../utils/log';
|
2020-06-15 14:00:46 +00:00
|
|
|
import { goRoom } from '../utils/goRoom';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../lib/services';
|
2021-05-12 19:01:29 +00:00
|
|
|
|
2018-04-10 13:03:54 +00:00
|
|
|
const handleRequest = function* handleRequest({ data }) {
|
2017-09-21 17:08:00 +00:00
|
|
|
try {
|
|
|
|
const auth = yield select(state => state.login.isAuthenticated);
|
|
|
|
if (!auth) {
|
|
|
|
yield take(LOGIN.SUCCESS);
|
2017-09-01 19:42:50 +00:00
|
|
|
}
|
2020-04-01 12:28:54 +00:00
|
|
|
|
|
|
|
let sub;
|
2021-05-12 19:01:29 +00:00
|
|
|
if (data.isTeam) {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { type, readOnly, broadcast, encrypted } = data;
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
logEvent(events.CT_CREATE, {
|
2021-09-13 20:41:05 +00:00
|
|
|
type: `${type}`,
|
|
|
|
readOnly: `${readOnly}`,
|
|
|
|
broadcast: `${broadcast}`,
|
|
|
|
encrypted: `${encrypted}`
|
2021-05-12 19:01:29 +00:00
|
|
|
});
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = yield Services.createTeam(data);
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
sub = {
|
|
|
|
rid: result?.team?.roomId,
|
|
|
|
...result.team,
|
|
|
|
t: result.team.type ? 'p' : 'c'
|
|
|
|
};
|
2021-05-12 19:01:29 +00:00
|
|
|
} else if (data.group) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.SELECTED_USERS_CREATE_GROUP);
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = yield Services.createGroupChat();
|
2020-04-03 18:02:10 +00:00
|
|
|
if (result.success) {
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
sub = {
|
|
|
|
rid: result.room?._id,
|
|
|
|
...result.room
|
|
|
|
};
|
2020-04-03 18:02:10 +00:00
|
|
|
}
|
2020-04-01 12:28:54 +00:00
|
|
|
} else {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { type, readOnly, broadcast, encrypted } = data;
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events.CR_CREATE, {
|
2020-09-11 14:31:38 +00:00
|
|
|
type: type ? 'private' : 'public',
|
|
|
|
readOnly,
|
|
|
|
broadcast,
|
|
|
|
encrypted
|
|
|
|
});
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = yield Services.createChannel(data);
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
sub = {
|
|
|
|
rid: result?.channel?._id || result?.group?._id,
|
|
|
|
...result?.channel,
|
|
|
|
...result?.group
|
|
|
|
};
|
2020-04-01 12:28:54 +00:00
|
|
|
}
|
2020-02-21 15:59:13 +00:00
|
|
|
try {
|
|
|
|
const db = database.active;
|
2021-02-26 16:25:51 +00:00
|
|
|
const subCollection = db.get('subscriptions');
|
2021-09-13 20:41:05 +00:00
|
|
|
yield db.action(async () => {
|
|
|
|
await subCollection.create(s => {
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
s._raw = sanitizedRaw({ id: sub.rid }, subCollection.schema);
|
2020-02-21 15:59:13 +00:00
|
|
|
Object.assign(s, sub);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
yield put(createChannelSuccess(sub));
|
2017-09-21 17:08:00 +00:00
|
|
|
} catch (err) {
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events[data.group ? 'SELECTED_USERS_CREATE_GROUP_F' : 'CR_CREATE_F']);
|
2021-05-27 17:27:24 +00:00
|
|
|
yield put(createChannelFailure(err, data.isTeam));
|
2017-09-01 19:42:50 +00:00
|
|
|
}
|
|
|
|
};
|
2017-09-25 13:15:28 +00:00
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
const handleSuccess = function* handleSuccess({ data }) {
|
|
|
|
const isMasterDetail = yield select(state => state.app.isMasterDetail);
|
|
|
|
if (isMasterDetail) {
|
|
|
|
Navigation.navigate('DrawerNavigator');
|
|
|
|
}
|
|
|
|
goRoom({ item: data, isMasterDetail });
|
2020-04-01 12:28:54 +00:00
|
|
|
};
|
|
|
|
|
2021-05-27 17:27:24 +00:00
|
|
|
const handleFailure = function handleFailure({ err, isTeam }) {
|
2021-08-27 16:34:38 +00:00
|
|
|
const errorArray = [
|
|
|
|
'room-name-already-exists',
|
|
|
|
'error-team-creation',
|
|
|
|
'unauthorized',
|
|
|
|
'error-duplicate-channel-name',
|
|
|
|
'error-invalid-room-name',
|
|
|
|
'team-name-already-exists'
|
|
|
|
];
|
|
|
|
|
2020-04-01 12:28:54 +00:00
|
|
|
setTimeout(() => {
|
2021-08-27 16:34:38 +00:00
|
|
|
let msg = '';
|
2021-09-13 20:41:05 +00:00
|
|
|
const actionError = I18n.t('There_was_an_error_while_action', {
|
|
|
|
action: isTeam ? I18n.t('creating_team') : I18n.t('creating_channel')
|
|
|
|
});
|
2021-08-27 16:34:38 +00:00
|
|
|
if (err?.data?.errorType && err?.data?.details?.channel_name) {
|
2021-09-13 20:41:05 +00:00
|
|
|
msg = errorArray.includes(err.data.errorType)
|
|
|
|
? I18n.t(err.data.errorType, { room_name: err.data.details.channel_name })
|
|
|
|
: actionError;
|
2021-08-27 16:34:38 +00:00
|
|
|
} else {
|
2021-10-26 13:40:46 +00:00
|
|
|
msg = err?.reason || (errorArray.includes(err?.data?.error) ? I18n.t(err.data.error) : err?.data?.error || actionError);
|
2021-08-27 16:34:38 +00:00
|
|
|
}
|
2021-05-27 17:27:24 +00:00
|
|
|
showErrorAlert(msg, isTeam ? I18n.t('Create_Team') : I18n.t('Create_Channel'));
|
2020-04-01 12:28:54 +00:00
|
|
|
}, 300);
|
|
|
|
};
|
|
|
|
|
2018-04-10 13:03:54 +00:00
|
|
|
const root = function* root() {
|
|
|
|
yield takeLatest(CREATE_CHANNEL.REQUEST, handleRequest);
|
2020-04-01 12:28:54 +00:00
|
|
|
yield takeLatest(CREATE_CHANNEL.SUCCESS, handleSuccess);
|
|
|
|
yield takeLatest(CREATE_CHANNEL.FAILURE, handleFailure);
|
2017-09-01 19:42:50 +00:00
|
|
|
};
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2018-04-10 13:03:54 +00:00
|
|
|
export default root;
|