Skip to content

Commit

Permalink
Merge branch 'develop' into chore/more-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Aug 26, 2022
2 parents 13587fc + 74ea125 commit 173c87f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 80 deletions.
6 changes: 3 additions & 3 deletions apps/meteor/app/ui-utils/client/lib/RoomManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const openedRooms: Record<
template?: Blaze.View;
streamActive?: boolean;
unreadSince: ReactiveVar<Date | undefined>;
lastSeen?: Date;
lastSeen: Date;
unreadFirstId?: string;
}
> = {};
Expand Down Expand Up @@ -105,9 +105,8 @@ function closeOlderRooms() {
if (Object.keys(openedRooms).length <= maxRoomsOpen) {
return;
}

const roomsToClose = Object.values(openedRooms)
.sort((a, b) => (a.lastSeen?.getTime() ?? 0) - (b.lastSeen?.getTime() ?? 0))
.sort((a, b) => b.lastSeen.getTime() - a.lastSeen.getTime())
.slice(maxRoomsOpen);
return Array.from(roomsToClose).map((roomToClose) => close(roomToClose.typeName));
}
Expand Down Expand Up @@ -225,6 +224,7 @@ function open({ typeName, rid }: { typeName: string; rid: IRoom['_id'] }) {
active: false,
ready: false,
unreadSince: new ReactiveVar(undefined),
lastSeen: new Date(),
};
}

Expand Down
150 changes: 76 additions & 74 deletions apps/meteor/app/ui-utils/client/lib/openRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,98 +21,100 @@ import MainLayout from '../../../../client/views/root/MainLayout';
import BlazeTemplate from '../../../../client/views/root/BlazeTemplate';

export async function openRoom(type: RoomType, name: string, render = true) {
RoomManager.currentTracker?.stop();
RoomManager.currentTracker = Tracker.autorun(async function (c) {
const user = Meteor.user();
if ((user && user.username == null) || (user == null && settings.get('Accounts_AllowAnonymousRead') === false)) {
appLayout.render(<MainLayout />);
return;
}

try {
const room = roomCoordinator.getRoomDirectives(type)?.findRoom(name) || (await call('getRoomByTypeAndName', type, name));
Rooms.upsert({ _id: room._id }, _.omit(room, '_id'));

if (room._id !== name && type === 'd') {
// Redirect old url using username to rid
RoomManager.close(type + name);
return FlowRouter.go('direct', { rid: room._id }, FlowRouter.current().queryParams);
}

if (room._id === Session.get('openedRoom') && !FlowRouter.getQueryParam('msg')) {
setTimeout(() => {
RoomManager.currentTracker?.stop();
RoomManager.currentTracker = Tracker.autorun(async function (c) {
const user = Meteor.user();
if ((user && user.username == null) || (user == null && settings.get('Accounts_AllowAnonymousRead') === false)) {
appLayout.render(<MainLayout />);
return;
}

RoomManager.open({ typeName: type + name, rid: room._id });
try {
const room = roomCoordinator.getRoomDirectives(type)?.findRoom(name) || (await call('getRoomByTypeAndName', type, name));
Rooms.upsert({ _id: room._id }, _.omit(room, '_id'));

if (render) {
appLayout.render(
<MainLayout>
<BlazeTemplate template='room' />
</MainLayout>,
);
}
if (room._id !== name && type === 'd') {
// Redirect old url using username to rid
RoomManager.close(type + name);
return FlowRouter.go('direct', { rid: room._id }, FlowRouter.current().queryParams);
}

c.stop();
if (room._id === Session.get('openedRoom') && !FlowRouter.getQueryParam('msg')) {
return;
}

if (RoomManager.currentTracker) {
RoomManager.currentTracker = undefined;
}
RoomManager.open({ typeName: type + name, rid: room._id });

NewRoomManager.open(room._id);
Session.set('openedRoom', room._id);
if (render) {
appLayout.render(
<MainLayout>
<BlazeTemplate template='room' />
</MainLayout>,
);
}

fireGlobalEvent('room-opened', _.omit(room, 'usernames'));
c.stop();

Session.set('editRoomTitle', false);
// KonchatNotification.removeRoomNotification(params._id)
// update user's room subscription
const sub = ChatSubscription.findOne({ rid: room._id });
if (sub && sub.open === false) {
await callWithErrorHandling('openRoom', room._id);
}
if (RoomManager.currentTracker) {
RoomManager.currentTracker = undefined;
}

if (FlowRouter.getQueryParam('msg')) {
const messageId = FlowRouter.getQueryParam('msg');
const msg = { _id: messageId, rid: room._id };
NewRoomManager.open(room._id);
Session.set('openedRoom', room._id);

const message = Messages.findOne({ _id: msg._id }) || (await callWithErrorHandling('getMessages', [msg._id]))[0];
fireGlobalEvent('room-opened', _.omit(room, 'usernames'));

if (message && (message.tmid || message.tcount)) {
return FlowRouter.setParams({ tab: 'thread', context: message.tmid || message._id });
Session.set('editRoomTitle', false);
// KonchatNotification.removeRoomNotification(params._id)
// update user's room subscription
const sub = ChatSubscription.findOne({ rid: room._id });
if (sub && sub.open === false) {
await callWithErrorHandling('openRoom', room._id);
}

RoomHistoryManager.getSurroundingMessages(msg);
FlowRouter.setQueryParams({
msg: null,
});
}
if (FlowRouter.getQueryParam('msg')) {
const messageId = FlowRouter.getQueryParam('msg');
const msg = { _id: messageId, rid: room._id };

return callbacks.run('enter-room', sub);
} catch (error) {
c.stop();
const message = Messages.findOne({ _id: msg._id }) || (await callWithErrorHandling('getMessages', [msg._id]))[0];

if (FlowRouter.getQueryParam('msg')) {
FlowRouter.setQueryParams({
msg: null,
});
}
if (message && (message.tmid || message.tcount)) {
return FlowRouter.setParams({ tab: 'thread', context: message.tmid || message._id });
}

RoomHistoryManager.getSurroundingMessages(msg);
FlowRouter.setQueryParams({
msg: null,
});
}

return callbacks.run('enter-room', sub);
} catch (error) {
c.stop();

if (type === 'd') {
try {
const { rid } = await call('createDirectMessage', ...name.split(', '));
await waitUntilFind(() => Subscriptions.findOne({ rid }));
return FlowRouter.go('direct', { rid }, FlowRouter.current().queryParams);
} catch (error) {
console.error(error);
if (FlowRouter.getQueryParam('msg')) {
FlowRouter.setQueryParams({
msg: null,
});
}

if (type === 'd') {
try {
const { rid } = await call('createDirectMessage', ...name.split(', '));
await waitUntilFind(() => Subscriptions.findOne({ rid }));
return FlowRouter.go('direct', { rid }, FlowRouter.current().queryParams);
} catch (error) {
console.error(error);
}
}
Session.set('roomNotFound', { type, name, error });
appLayout.render(
<MainLayout>
<BlazeTemplate template='roomNotFound' />
</MainLayout>,
);
}
Session.set('roomNotFound', { type, name, error });
appLayout.render(
<MainLayout>
<BlazeTemplate template='roomNotFound' />
</MainLayout>,
);
}
});
});
}
20 changes: 17 additions & 3 deletions apps/meteor/client/startup/banners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,26 @@ Meteor.startup(() => {
return;
}

FlowRouter.watchPathChange();

if (FlowRouter.getRouteName() === 'setup-wizard') {
if (Tracker.nonreactive(() => FlowRouter.getRouteName()) === 'setup-wizard') {
Tracker.autorun((c) => {
if (FlowRouter.getRouteName() !== 'setup-wizard') {
unwatchBanners = Tracker.nonreactive(watchBanners);
c.stop();
}
});
return;
}

unwatchBanners = Tracker.nonreactive(watchBanners);
});
});

Meteor.startup(() => {
Tracker.autorun(() => {
if (!Meteor.userId()) {
return;
}

console.log(FlowRouter.getRouteName());
});
});

0 comments on commit 173c87f

Please sign in to comment.