Skip to content

Commit

Permalink
Remove some assertions to any
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Mar 10, 2023
1 parent a666876 commit 63cd390
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
9 changes: 5 additions & 4 deletions apps/meteor/app/autotranslate/client/lib/autotranslate.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import mem from 'mem';
import { isTranslatedMessageAttachment } from '@rocket.chat/core-typings';
import type {
IMessage,
IRoom,
ISubscription,
ISupportedLanguage,
ITranslatedMessage,
IUser,
MessageAttachmentDefault,
} from '@rocket.chat/core-typings';
import { isTranslatedMessageAttachment } from '@rocket.chat/core-typings';

import { Subscriptions, Messages } from '../../../models/client';
import { hasPermission } from '../../../authorization/client';
Expand All @@ -34,7 +35,7 @@ const getUsername = () =>
export const AutoTranslate = {
initialized: false,
providersMetadata: {} as { [providerNamer: string]: { name: string; displayName: string } },
messageIdsToWait: {} as { [messageId: string]: string },
messageIdsToWait: new Set<IMessage['_id']>(),
supportedLanguages: [] as ISupportedLanguage[] | undefined,

findSubscriptionByRid: mem((rid) => Subscriptions.findOne({ rid })),
Expand Down Expand Up @@ -177,9 +178,9 @@ export const createAutoTranslateMessageStreamHandler = (): ((message: ITranslate
) {
// || (message.attachments && !_.find(message.attachments, attachment => { return attachment.translations && attachment.translations[language]; }))
Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
} else if (AutoTranslate.messageIdsToWait[message._id] !== undefined && subscription && subscription.autoTranslate !== true) {
} else if (AutoTranslate.messageIdsToWait.has(message._id) !== undefined && subscription && subscription.autoTranslate !== true) {
Messages.update({ _id: message._id }, { $set: { autoTranslateShowInverse: true }, $unset: { autoTranslateFetching: true } });
delete AutoTranslate.messageIdsToWait[message._id];
AutoTranslate.messageIdsToWait.delete(message._id);
} else if (message.autoTranslateFetching === true) {
Messages.update({ _id: message._id }, { $unset: { autoTranslateFetching: true } });
}
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/startup/actionButtons/autotranslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Meteor.startup(() => {
const { message = messageArgs(this).msg } = props;
const language = AutoTranslate.getLanguage(message.rid);
if (!hasTranslationLanguageInMessage(message, language) && !hasTranslationLanguageInAttachments(message.attachments, language)) {
(AutoTranslate.messageIdsToWait as any)[message._id] = true;
AutoTranslate.messageIdsToWait.add(message._id);
Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
Meteor.call('autoTranslate.translateMessage', message, language);
}
Expand Down Expand Up @@ -58,7 +58,7 @@ Meteor.startup(() => {
const { message = messageArgs(this).msg } = props;
const language = AutoTranslate.getLanguage(message.rid);
if (!hasTranslationLanguageInMessage(message, language) && !hasTranslationLanguageInAttachments(message.attachments, language)) {
(AutoTranslate.messageIdsToWait as any)[message._id] = true;
AutoTranslate.messageIdsToWait.add(message._id);
Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
Meteor.call('autoTranslate.translateMessage', message, language);
}
Expand Down
11 changes: 10 additions & 1 deletion apps/meteor/client/startup/appRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import AppRoot from '../views/root/AppRoot';
import PageLoading from '../views/root/PageLoading';

const Root = lazy(() => import('../components/root/ErrorBoundary'));

declare global {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface Window {
__BUGSNAG_KEY__: string;
}
}

const createContainer = (): Element => {
const container = document.getElementById('react-root');

Expand All @@ -18,8 +26,9 @@ const createContainer = (): Element => {
};

const container = createContainer();

render(
(window as any).__BUGSNAG_KEY__ ? (
window.__BUGSNAG_KEY__ ? (
<Suspense fallback={<PageLoading />}>
<Root>
<AppRoot />
Expand Down
9 changes: 8 additions & 1 deletion apps/meteor/client/startup/ldap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';

(Meteor as any).loginWithLDAP = function (username: string, password: string, callback?: (err?: any) => void): void {
declare module 'meteor/meteor' {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Meteor {
function loginWithLDAP(username: string, password: string, callback?: (err?: any) => void): void;
}
}

Meteor.loginWithLDAP = function (username: string, password: string, callback?: (err?: any) => void): void {
Accounts.callLoginMethod({
methodArguments: [
{
Expand Down
9 changes: 8 additions & 1 deletion apps/meteor/client/startup/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ const OmnichannelQueueList = lazy(() => import('../views/omnichannel/queueList')
const OAuthAuthorizationPage = lazy(() => import('../views/oauth/OAuthAuthorizationPage'));
const OAuthErrorPage = lazy(() => import('../views/oauth/OAuthErrorPage'));

declare module 'meteor/meteor' {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Meteor {
function loginWithSamlToken(token: string, callback?: (error?: unknown) => void): void;
}
}

FlowRouter.wait();

FlowRouter.route('/', {
Expand Down Expand Up @@ -108,7 +115,7 @@ FlowRouter.route('/home', {
FlowRouter.setQueryParams({
saml_idp_credentialToken: null,
});
(Meteor as any).loginWithSamlToken(token, (error?: unknown) => {
Meteor.loginWithSamlToken(token, (error?: unknown) => {
if (error) {
dispatchToastMessage({ type: 'error', message: error });
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/startup/settingsOnLoadSiteUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Meteor.startup(() => {
if (value == null || value.trim() === '') {
return;
}
(window as any).__meteor_runtime_config__.ROOT_URL = value;
window.__meteor_runtime_config__.ROOT_URL = value;
});
});
4 changes: 3 additions & 1 deletion apps/meteor/client/startup/usersObserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import type { IUser } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';

import type { MinimongoCollection } from '../definitions/MinimongoCollection';

Meteor.startup(() => {
// TODO: find correct typing for meteor collection
(Meteor.users as any)
(Meteor.users as unknown as MinimongoCollection<IUser>)
.find(
{},
{
Expand Down
6 changes: 0 additions & 6 deletions apps/meteor/definition/externals/meteor/meteor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ declare module 'meteor/meteor' {
function _relativeToSiteRootUrl(path: string): string;
const _localStorage: Window['localStorage'];

function loginWithLDAP(
username: string | object,
password: string,
cb: (error?: Error | Meteor.Error | Meteor.TypedError) => void,
): void;

function loginWithCrowd(
username: string | object,
password: string,
Expand Down

0 comments on commit 63cd390

Please sign in to comment.