Skip to content

Commit

Permalink
feat: redirect to main channel when channel can't be found
Browse files Browse the repository at this point in the history
  • Loading branch information
raaymax committed Mar 23, 2024
1 parent 9d714dc commit eaf1b09
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
12 changes: 9 additions & 3 deletions packages/app/src/js/services/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ const initApp = () => async (dispatch, getState) => {
const config = await methods.config.load();
actions.stream.setMain(config.mainChannelId);
await initNotifications(config);
methods.users.load();
methods.channels.load();
await methods.users.load();
await methods.channels.load();
await methods.emojis.load();
await methods.progress.loadBadges();
if (!getState().stream.main.channelId) {
const channelId = getState().stream.main.channelId;
if (!channelId) {
actions.stream.open({id: 'main', value: {type: 'live'}});
}else if( !getState().channels[channelId] ){
const c = await methods.channels.find(channelId);
if(!c || c.length === 0) {
actions.stream.open({id: 'main', value: {type: 'live'}});
}
}
};

Expand Down
1 change: 1 addition & 0 deletions packages/app/src/js/store/modules/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default createModule({
find: (id) => async ({actions}, getState, {client}) => {
const res = await client.req({ type: 'channel:get', id });
actions.channels.add(res.data);
return res.data;
},
},
});
18 changes: 11 additions & 7 deletions packages/app/src/js/store/modules/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ export default createModule({
},

loadProgress: (stream) => async ({actions}, getState, {client}) => {
if (!stream.channelId) return;
const { data } = await client.req({
type: 'readReceipt:getChannel',
channelId: stream.channelId,
parentId: stream.parentId,
});
actions.progress.add(data);
try{
if (!stream.channelId) return;
const { data } = await client.req({
type: 'readReceipt:getChannel',
channelId: stream.channelId,
parentId: stream.parentId,
});
actions.progress.add(data);
}catch(err){
console.log(err)
}
},

update: (messageId) => async ({actions}, getState, {client}) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/app/actions/message/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
handler: async (req, res) => {
const msg = req.body;
const channel = await repo.channel.get({ id: msg.channelId });
if (!await channelHelper.haveAccess(req.userId, channel.id)) {
if (!await channelHelper.haveAccess(req.userId, channel?.id)) {
throw AccessDenied();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/app/actions/message/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
const message = await repo.message.get({ id });
if (!message) throw MessageNotExist();
// TODO: test if permissions work in tests
if (!await ChannelHelper.haveAccess(req.userId, message.channelId)) {
if (!await ChannelHelper.haveAccess(req.userId, message?.channelId)) {
throw AccessDenied();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/app/actions/readReceipt/getChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
if (!msg.channelId) throw MissingChannel();
const channel = await repo.channel.get({ id: msg.channelId });

if (!await ChannelHelper.haveAccess(req.userId, channel.id)) {
if (!await ChannelHelper.haveAccess(req.userId, channel?.id)) {
throw AccessDenied();
}
const badges = await repo.badge.getAll({ channelId: channel.id, parentId: msg.parentId });
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/app/commands/join.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
const { channelId } = req.body.context;

const channel = await repo.channel.get({ id: channelId });
if (!await channelHelper.haveAccess(req.userId, channel.id)) {
if (!await channelHelper.haveAccess(req.userId, channel?.id)) {
throw AccessDenied();
}
if (!channel) throw ChannelNotExist();
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/app/common/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const repo = require('../../infra/repositories');

module.exports = {
haveAccess: async (userId, id) => {
if (!id) return false;
const channel = await repo.channel.get({ id });

if (channel?.private
Expand Down

0 comments on commit eaf1b09

Please sign in to comment.