Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Feb 22, 2023
2 parents 3617218 + 2d4e916 commit 28832d0
Show file tree
Hide file tree
Showing 136 changed files with 3,075 additions and 2,343 deletions.
4 changes: 2 additions & 2 deletions .github/actions/build-docker-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ runs:
echo "Build ${{ inputs.release }} Docker image"
docker build -t $IMAGE_NAME .
echo "::set-output name=image-name-base::${IMAGE_NAME_BASE}"
echo "::set-output name=image-name::${IMAGE_NAME}"
echo "image-name-base=${IMAGE_NAME_BASE}" >> $GITHUB_OUTPUT
echo "image-name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'release' || github.ref == 'refs/heads/develop'
Expand Down
183 changes: 46 additions & 137 deletions .github/workflows/build_and_test.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .kodiak.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ automerge_label = ["stat: ready to merge", "automerge"]
block_on_neutral_required_check_runs = true
blocking_labels = ["stat: needs QA", "Invalid PR Title"]
prioritize_ready_to_merge = true
merge.do_not_merge=true

[merge.message]
title = "pull_request_title"
Expand All @@ -16,4 +17,3 @@ include_coauthors=true
[merge.automerge_dependencies]
versions = ["minor", "patch"]
usernames = ["dependabot"]

2 changes: 1 addition & 1 deletion apps/meteor/app/2fa/server/code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function isAuthorizedForToken(connection: IMethodConnection, user: IUser,
return false;
}

if (tokenObject.bypassTwoFactor === true) {
if ('bypassTwoFactor' in tokenObject && tokenObject.bypassTwoFactor === true) {
return true;
}

Expand Down
35 changes: 22 additions & 13 deletions apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { Match, check } from 'meteor/check';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import type { IExportOperation, IPersonalAccessToken, IUser } from '@rocket.chat/core-typings';
import type { IExportOperation, ILoginToken, IPersonalAccessToken, IUser } from '@rocket.chat/core-typings';
import { Users as UsersRaw } from '@rocket.chat/models';
import type { Filter } from 'mongodb';
import { Team, api } from '@rocket.chat/core-services';
Expand Down Expand Up @@ -439,7 +439,15 @@ API.v1.addRoute(
throw new Meteor.Error('error-invalid-query', isValidQuery.errors.join('\n'));
}

const actualSort = sort?.name ? { nameInsensitive: sort.name, ...sort } : sort || { username: 1 };
const actualSort = sort || { username: 1 };

if (sort?.status) {
actualSort.active = sort.status;
}

if (sort?.name) {
actualSort.nameInsensitive = sort.name;
}

const limit =
count !== 0
Expand Down Expand Up @@ -673,16 +681,17 @@ API.v1.addRoute(

const user = Users.getLoginTokensByUserId(this.userId).fetch()[0] as IUser | undefined;

const isPersonalAccessToken = (loginToken: ILoginToken | IPersonalAccessToken): loginToken is IPersonalAccessToken =>
'type' in loginToken && loginToken.type === 'personalAccessToken';

return API.v1.success({
tokens:
user?.services?.resume?.loginTokens
?.filter((loginToken: any) => loginToken.type === 'personalAccessToken')
.map((loginToken: IPersonalAccessToken) => ({
name: loginToken.name,
createdAt: loginToken.createdAt.toISOString(),
lastTokenPart: loginToken.lastTokenPart,
bypassTwoFactor: Boolean(loginToken.bypassTwoFactor),
})) || [],
user?.services?.resume?.loginTokens?.filter(isPersonalAccessToken).map((loginToken) => ({
name: loginToken.name,
createdAt: loginToken.createdAt.toISOString(),
lastTokenPart: loginToken.lastTokenPart,
bypassTwoFactor: Boolean(loginToken.bypassTwoFactor),
})) || [],
});
},
},
Expand Down Expand Up @@ -862,12 +871,12 @@ API.v1.addRoute(

const token = me.services?.resume?.loginTokens?.find((token) => token.hashedToken === hashedToken);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const tokenExpires = new Date(token!.when.getTime() + settings.get<number>('Accounts_LoginExpiration') * 1000);
const tokenExpires =
(token && 'when' in token && new Date(token.when.getTime() + settings.get<number>('Accounts_LoginExpiration') * 1000)) || undefined;

return API.v1.success({
token: xAuthToken,
tokenExpires: tokenExpires.toISOString() || '',
tokenExpires: tokenExpires?.toISOString() || '',
});
},
},
Expand Down
12 changes: 1 addition & 11 deletions apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class RoomHistoryManagerClass extends Emitter {
}

public async getSurroundingMessages(message?: Pick<IMessage, '_id' | 'rid'> & { ts?: Date }, atBottomRef?: MutableRefObject<boolean>) {
if (!message || !message.rid) {
if (!message?.rid) {
return;
}

Expand All @@ -295,13 +295,8 @@ class RoomHistoryManagerClass extends Emitter {
500,
);

msgElement.addClass('highlight');
setHighlightMessage(message._id);

setTimeout(() => {
msgElement.removeClass('highlight');
}, 500);

setTimeout(() => {
clearHighlightMessage();
}, 1000);
Expand Down Expand Up @@ -342,17 +337,12 @@ class RoomHistoryManagerClass extends Emitter {
500,
);

msgElement.addClass('highlight');
setHighlightMessage(message._id);

room.isLoading.set(false);
const messages = wrapper[0];
if (atBottomRef) atBottomRef.current = !result.moreAfter && messages.scrollTop >= messages.scrollHeight - messages.clientHeight;

setTimeout(() => {
msgElement.removeClass('highlight');
}, 500);

setTimeout(() => {
clearHighlightMessage();
}, 1000);
Expand Down
27 changes: 14 additions & 13 deletions apps/meteor/app/ui-utils/client/lib/openRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ export async function openRoom(type: RoomType, name: string, render = true) {
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);
FlowRouter.go('direct', { rid: room._id }, FlowRouter.current().queryParams);
return;
}

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

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

const messageId = FlowRouter.getQueryParam('msg');

if (room._id === Session.get('openedRoom') && !messageId) {
return;
}

Expand Down Expand Up @@ -72,31 +76,27 @@ export async function openRoom(type: RoomType, name: string, render = true) {
await callWithErrorHandling('openRoom', room._id);
}

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

const message = Messages.findOne({ _id: msg._id }) || (await callWithErrorHandling('getMessages', [msg._id]))[0];

if (message && (message.tmid || message.tcount)) {
return FlowRouter.setParams({ tab: 'thread', context: message.tmid || message._id });
FlowRouter.withReplaceState(() => {
FlowRouter.setParams({ tab: 'thread', context: message.tmid || message._id });
});
return;
}

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

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

if (FlowRouter.getQueryParam('msg')) {
FlowRouter.setQueryParams({
msg: null,
});
}
FlowRouter.setQueryParams({ msg: null });

if (type === 'd') {
try {
Expand All @@ -107,6 +107,7 @@ export async function openRoom(type: RoomType, name: string, render = true) {
console.error(error);
}
}

appLayout.render(
<MainLayout>
<RoomNotFound />
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/lib/userData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export const synchronizeUserData = async (uid: Meteor.User['_id']): Promise<RawU
...(resume.loginTokens && {
loginTokens: resume.loginTokens.map((token) => ({
...token,
when: new Date(token.when),
createdAt: (token.createdAt ? new Date(token.createdAt) : undefined) as Date,
when: new Date('when' in token ? token.when : ''),
createdAt: ('createdAt' in token ? new Date(token.createdAt) : undefined) as Date,
twoFactorAuthorizedUntil: token.twoFactorAuthorizedUntil ? new Date(token.twoFactorAuthorizedUntil) : undefined,
})),
}),
Expand Down
14 changes: 8 additions & 6 deletions apps/meteor/client/lib/utils/jumpToMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { isThreadMessage } from '@rocket.chat/core-typings';
import { FlowRouter } from 'meteor/kadira:flow-router';

import { ChatRoom } from '../../../app/models/client';
Expand All @@ -10,21 +11,22 @@ export const jumpToMessage = async (message: IMessage) => {
(Template.instance() as any)?.tabBar?.close();
}

if (message.tmid) {
return FlowRouter.go(
FlowRouter.getRouteName(),
if (isThreadMessage(message)) {
const { route, queryParams } = FlowRouter.current();
FlowRouter.go(
route?.name ?? '/',
{
tab: 'thread',
context: message.tmid,
rid: message.rid,
jump: message._id,
name: ChatRoom.findOne({ _id: message.rid })?.name ?? '',
},
{
...FlowRouter.current().queryParams,
jump: message._id,
...queryParams,
msg: message._id,
},
);
return;
}

if (Session.get('openedRoom') === message.rid) {
Expand Down
17 changes: 11 additions & 6 deletions apps/meteor/client/lib/utils/waitForElement.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export const waitForElement = async (
export const waitForElement = async <TElement extends Element>(
selector: string,
{ parent = document.documentElement }: { parent?: HTMLElement } = {},
): Promise<Element> => {
const element = parent.querySelector(selector);
return new Promise((resolve) => {
{ parent = document.documentElement, signal }: { parent?: Element; signal?: AbortSignal } = {},
): Promise<TElement> => {
const element = parent.querySelector<TElement>(selector);
return new Promise((resolve, reject) => {
if (element) {
return resolve(element);
}
const observer = new MutationObserver((_, obs) => {
const element = parent.querySelector(selector);
const element = parent.querySelector<TElement>(selector);
if (element) {
obs.disconnect(); // stop observing
return resolve(element);
Expand All @@ -18,5 +18,10 @@ export const waitForElement = async (
childList: true,
subtree: true,
});

signal?.addEventListener('abort', () => {
observer.disconnect();
reject(new DOMException('Aborted', 'AbortError'));
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const VideoMessageRecorder = ({ rid, tmid, chatContext, reference }: VideoMessag
const videoRef = useRef<HTMLVideoElement>(null);
const dispatchToastMessage = useToastMessageDispatch();

const [time, setTime] = useState('');
const [time, setTime] = useState<string | undefined>();
const [recordingState, setRecordingState] = useState<'idle' | 'loading' | 'recording'>('idle');
const [recordingInterval, setRecordingInterval] = useState<ReturnType<typeof setInterval> | null>(null);
const isRecording = recordingState === 'recording';
Expand Down Expand Up @@ -81,14 +81,14 @@ const VideoMessageRecorder = ({ rid, tmid, chatContext, reference }: VideoMessag
};

VideoRecorder.stop(cb);
setTime('');
setTime(undefined);
stopVideoRecording(rid, tmid);
};

const handleCancel = () => {
VideoRecorder.stop();
chat?.composer?.setRecordingVideo(false);
setTime('');
setTime(undefined);
stopVideoRecording(rid, tmid);
};

Expand All @@ -106,15 +106,15 @@ const VideoMessageRecorder = ({ rid, tmid, chatContext, reference }: VideoMessag

return (
<PositionAnimated visible='visible' anchor={reference} placement='top-end'>
<Box bg='light' padding='x4' borderRadius='x4' elevation='2'>
<Box className={videoContainerClass} overflow='hidden' height='240px' borderRadius='x4'>
<video ref={videoRef} width='320' height='240'></video>
<Box bg='light' padding={4} borderRadius={4} elevation='2'>
<Box className={videoContainerClass} overflow='hidden' height={240} borderRadius={4}>
<video ref={videoRef} width={320} height={240} />
</Box>
<Box mbs='x4' display='flex' justifyContent='space-between'>
<Box mbs={4} display='flex' justifyContent='space-between'>
<Button small onClick={handleRecord}>
<Box display='flex' alignItems='center'>
<Icon size='x16' mie='x4' name={isRecording ? 'stop-unfilled' : 'rec'} />
<span>{time}</span>
<Box is='span' display='flex' alignItems='center'>
<Icon size={16} mie={time ? 4 : undefined} name={isRecording ? 'stop-unfilled' : 'rec'} />
{time && <span>{time}</span>}
</Box>
</Button>
<ButtonGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ const AgentEditWithData = ({ uid, reload }: AgentEditWithDataProps): ReactElemen

const getAgentDepartments = useEndpoint('GET', '/v1/livechat/agents/:agentId/departments', { agentId: uid });

const { data, isLoading: state, error } = useQuery(['getAgent'], async () => getAgent());
const { data, isInitialLoading: isLoading, error } = useQuery(['getAgent'], async () => getAgent());
const {
data: userDepartments,
isLoading: userDepartmentsState,
isLoading: isUserDepartmentsLoading,
error: userDepartmentsError,
} = useQuery(['getAgentDepartments'], async () => getAgentDepartments());
} = useQuery({ queryKey: ['getAgentDepartments'], queryFn: async () => getAgentDepartments(), cacheTime: 0 });

const {
data: availableDepartments,
isLoading: availableDepartmentsState,
isLoading: isAvailableDepartmentsLoading,
error: availableDepartmentsError,
} = useQuery(['getDepartments'], async () => getDepartments({ showArchived: 'true' }));

if (state || availableDepartmentsState || userDepartmentsState || !userDepartments || !availableDepartments) {
if (isLoading || isAvailableDepartmentsLoading || isUserDepartmentsLoading || !userDepartments || !availableDepartments) {
return <FormSkeleton />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ function EditDepartmentWithAllowedForwardData({ data, ...props }) {
} = useEndpointData('/v1/livechat/department.listByIds', {
params: useMemo(
() => ({
ids: data && data.department && data.department.departmentsAllowedToForward ? data.department.departmentsAllowedToForward : [],
ids:
data && data.department && data.department.departmentsAllowedToForward
? data.department.departmentsAllowedToForward.split(',')
: [],
}),
[data],
),
Expand Down
Loading

0 comments on commit 28832d0

Please sign in to comment.