Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions apps/server/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@
// Scope clipboard delegation to self and the configured Collabora origin only.
// Falls back to self-only when CELLS_PYDIO_URL is not configured.
const collaboraOrigin = this.clientConfig.CELLS_PYDIO_URL;
const clipboardAllowlist = collaboraOrigin ? `(self "${collaboraOrigin}")` : '(self)';
const clipboardAllowlist =
collaboraOrigin !== undefined && collaboraOrigin.length > 0 ? `(self "${collaboraOrigin}")` : '(self)';
this.app.use((_req, res, next) => {
res.setHeader(
'Permissions-Policy',
Expand All @@ -197,7 +198,7 @@
});

this.app.get('/favicon.ico', (_req, res) => res.sendFile(path.join(__dirname, 'static/image/favicon.ico')));
if (!this.config.DEVELOPMENT) {
if (this.config.DEVELOPMENT === false) {
this.app.get('/sw.js', (_req, res) => res.sendFile(path.join(__dirname, 'static/sw.js')));
}
}
Expand Down Expand Up @@ -237,7 +238,7 @@
}

private initSiteMap(config: ServerConfig) {
if (config.APP_BASE) {
if (config.APP_BASE.length > 0) {
const pages = () => [
{
changeFreq: 'weekly',
Expand All @@ -254,9 +255,9 @@

start(): Promise<number> {
return new Promise((resolve, reject) => {
if (this.server) {
if (this.server !== undefined) {
reject('Server is already running.');
} else if (this.config.PORT_HTTP) {
} else if (this.config.PORT_HTTP > 0) {
if (this.config.DEVELOPMENT && this.config.DEVELOPMENT_ENABLE_TLS) {
const options = {
cert: fs.readFileSync(this.config.SSL_CERTIFICATE_PATH),
Expand All @@ -275,7 +276,7 @@
}

async stop(): Promise<void> {
if (this.server) {
if (this.server !== undefined) {

Check warning on line 279 in apps/server/Server.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=wireapp_wire-webapp&issues=AZ4chlLBUudVs6-nGpXi&open=AZ4chlLBUudVs6-nGpXi&pullRequest=21292
this.server.close();
this.server = undefined;
} else {
Expand Down
12 changes: 6 additions & 6 deletions apps/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import path from 'path';
import {generateClientConfig, generateServerConfig, Env} from '@wireapp/config';

const versionData = readFileSync(path.resolve(__dirname, './version.json'), 'utf8');
const version = versionData ? JSON.parse(versionData) : {version: 'unknown', commit: 'unknown'};
const version = versionData.length > 0 ? JSON.parse(versionData) : {version: 'unknown', commit: 'unknown'};
const dotenvConfigurationIndentationSpaces = 2;

// Determine the correct root path based on the directory structure
Expand Down Expand Up @@ -54,13 +54,13 @@ console.info('[Config] dotenv config:', JSON.stringify(dotenvConfig, null, doten

const env = dotenv.load(dotenvConfig) as Env;

console.info('[Config] Environment loaded. APP_BASE:', env.APP_BASE ? 'SET' : 'NOT SET');
console.info('[Config] Environment loaded. APP_BASE:', env.APP_BASE.length > 0 ? 'SET' : 'NOT SET');

function generateUrls() {
const federation = env.FEDERATION;
const federation = env.FEDERATION ?? '';

if (!federation) {
if (!env.APP_BASE || !env.BACKEND_REST || !env.BACKEND_WS) {
if (federation.length === 0) {
if (env.APP_BASE.length === 0 || env.BACKEND_REST.length === 0 || env.BACKEND_WS.length === 0) {
console.error('[Config] Missing required environment variables!');
console.error('[Config] APP_BASE:', env.APP_BASE);
console.error('[Config] BACKEND_REST:', env.BACKEND_REST);
Expand All @@ -86,7 +86,7 @@ function generateUrls() {
const commonConfig = {
commit: version.commit,
version: version.version,
env: env.NODE_ENV || 'production',
env: env.NODE_ENV.length > 0 ? env.NODE_ENV : 'production',
urls: generateUrls(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {Router} from 'express';
import type {ServerConfig} from '@wireapp/config';

export const GoogleWebmasterRoute = (config: ServerConfig) => {
if (config.GOOGLE_WEBMASTER_ID) {
if (config.GOOGLE_WEBMASTER_ID.length > 0) {
return Router().get(`/google${config.GOOGLE_WEBMASTER_ID}.html`, (_req, res) => {
const responseBody = `google-site-verification: google${config.GOOGLE_WEBMASTER_ID}.html`;
res.type('text/html; charset=utf-8').send(responseBody);
Expand Down
2 changes: 1 addition & 1 deletion apps/server/routes/redirectRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const RedirectRoutes = (config: ServerConfig) => [
.join('&');
return res.redirect(
HTTP_STATUS.MOVED_TEMPORARILY,
`/?${queryString ? queryString : 'no_query=true'}#/e2ei-redirect`,
`/?${queryString.length > 0 ? queryString : 'no_query=true'}#/e2ei-redirect`,
);
}),
];
2 changes: 1 addition & 1 deletion apps/server/routes/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function addGeoIP(req: Request) {

const lookup = await maxmind.open<CountryResponse>(countryDatabasePath);
const result = lookup.get(ipAddress);
if (result) {
if (result !== undefined && result !== null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use @sindresorhus/is here?

Suggested change
if (result !== undefined && result !== null) {
if (!is.nullOrUndefined(result)) {

countryCode = result.country?.iso_code ?? '';
}
} catch {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/util/browserUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function parseUserAgent(userAgent?: string): ParsedUserAgent | null {

userAgent = userAgent.toLowerCase();

const getVersion = (app: string): string | undefined => (userAgent.match(new RegExp(`${app}/(.*)`, 'i')) || [])[0];
const getVersion = (app: string): string | undefined => (userAgent.match(new RegExp(`${app}/(.*)`, 'i')) ?? [])[0];

const electronVersion = getVersion('Electron');
const wireVersion = getVersion('Wire');
Expand Down
4 changes: 3 additions & 1 deletion apps/webapp/src/script/components/AppLoader/AppLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import {FC, ReactNode, useEffect, useRef, useState} from 'react';

import is from '@sindresorhus/is';

import {LoadingBar} from 'Components/LoadingBar/LoadingBar';
import {User} from 'Repositories/entity/User';

Expand Down Expand Up @@ -53,7 +55,7 @@ export const AppLoader: FC<AppLoaderProps> = ({init, children}) => {
}).then(user => setSelfUser(user));
}, []);

if (selfUser) {
if (!is.nullOrUndefined(selfUser)) {
return children(selfUser);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let roots: Record<string, Root> = {};
export const useAppNotification = (props?: AppNotificationOptions) => {
const notificationId = useRef<string | number | null>(null);

const activeWindow = props?.activeWindow || window;
const activeWindow = props?.activeWindow ?? window;

useEffect(() => {
setTimeout(() => {
Expand Down Expand Up @@ -135,7 +135,7 @@ const injectToaster = (activeWindow: Window) => {

const container = activeWindow.document.querySelector(APP_NOTIFICATION_SELECTOR);

if (!container) {
if (container === null) {
throw new Error('Notification container not found!');
}

Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/script/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const Avatar = ({
event: ReactMouseEvent<HTMLDivElement, MouseEvent> | ReactKeyBoardEvent<HTMLDivElement>,
) => {
const parentNode = event.currentTarget.parentNode;
if (parentNode) {
if (parentNode !== null) {
if (isKeyboardEvent(event)) {
handleKeyDown({event, callback: () => onAvatarClick?.(participant), keys: [KEY.ENTER, KEY.SPACE]});
return;
Expand Down
6 changes: 4 additions & 2 deletions apps/webapp/src/script/components/Avatar/AvatarBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const AvatarBadge: React.FunctionComponent<AvatarBadgeProps> = ({state, iconSize
const color: Record<string, string> = {
[STATE.BLOCKED]: 'var(--gray-70)',
};
const hasBackgroundColor = Object.hasOwn(backgroundColor, state);
const hasColor = Object.hasOwn(color, state);

return (
<div
Expand All @@ -52,9 +54,9 @@ const AvatarBadge: React.FunctionComponent<AvatarBadgeProps> = ({state, iconSize
'&::before': {
...CSS_ICON(icons[state], iconSize),
},
backgroundColor: backgroundColor[state] || defaultBackgroundColor,
backgroundColor: hasBackgroundColor ? backgroundColor[state] : defaultBackgroundColor,
borderRadius: '50%',
color: color[state] || defaultColor,
color: hasColor ? color[state] : defaultColor,
}}
data-uie-name="element-avatar-user-badge-icon"
data-uie-value={state}
Expand Down
5 changes: 3 additions & 2 deletions apps/webapp/src/script/components/Avatar/AvatarImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import React, {useEffect, useState} from 'react';

import {CSSObject} from '@emotion/serialize';
import is from '@sindresorhus/is';
import {Transition} from 'react-transition-group';
import {container} from 'tsyringe';

Expand Down Expand Up @@ -74,7 +75,7 @@ const AvatarImage: React.FunctionComponent<AvatarImageProps> = ({
setShowTransition(!isCached && !isSmall);
try {
const url = await assetRepository.getObjectUrl(pictureResource);
if (url) {
if (is.nonEmptyString(url)) {
setAvatarImage(url);
}
setAvatarLoadingBlocked(false);
Expand All @@ -95,7 +96,7 @@ const AvatarImage: React.FunctionComponent<AvatarImageProps> = ({

return (
<InViewport onVisible={() => setIsVisible(true)}>
<Transition in={!!avatarImage} timeout={showTransition ? 700 : 0}>
<Transition in={avatarImage.length > 0} timeout={showTransition ? 700 : 0}>
{(state: string) => {
return (
<img
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import {MouseEvent as ReactMouseEvent, KeyboardEvent as ReactKeyBoardEvent} from 'react';

import is from '@sindresorhus/is';
import {container} from 'tsyringe';

import {Availability as AvailabilityType} from '@wireapp/protocol-messaging';
Expand Down Expand Up @@ -99,7 +100,7 @@ export const UserAvatar = ({
'initials',
]);

const avatarImgAlt = avatarAlt ? avatarAlt : `${t('userProfileImageAlt')} ${name}`;
const avatarImgAlt = is.nonEmptyString(avatarAlt) ? avatarAlt : `${t('userProfileImageAlt')} ${name}`;

const hasAvailabilityState = typeof availability === 'number' && availability !== AvailabilityType.Type.NONE;

Expand All @@ -118,7 +119,7 @@ export const UserAvatar = ({
>
<AvatarBackground backgroundColor={backgroundColor} />

{initials && <AvatarInitials avatarSize={avatarSize} initials={initials} />}
{is.nonEmptyString(initials) && <AvatarInitials avatarSize={avatarSize} initials={initials} />}
<AvatarImage
avatarSize={avatarSize}
avatarAlt={avatarImgAlt}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ interface UserStatusBadgesProps {
}

export const UserStatusBadges = ({config}: UserStatusBadgesProps) => {
const badges = Object.entries(config).filter(([_badge, shouldShow]) => shouldShow);
const badges = Object.entries(config).filter(([_badge, shouldShow]) => shouldShow === true);
const badgesCount = badges.length;

if (!badgesCount) {
if (badgesCount === 0) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const useConversationVerificationState = (conversation: Conversation) => {
};

const getMLSStatuses = ({identities, user}: {identities?: WireIdentity[]; user?: User}): MLSStatuses[] | undefined => {
if (!identities || !user) {
if (identities === undefined || user === undefined) {
return undefined;
}

Expand Down Expand Up @@ -116,7 +116,11 @@ export const UserVerificationBadges = ({
});

let status: MLSStatuses | undefined = undefined;
if (mlsStatuses && mlsStatuses.length > 0 && mlsStatuses.every(status => status === MLSStatuses.VALID)) {
if (
mlsStatuses !== undefined &&
mlsStatuses.length > 0 &&
mlsStatuses.every(status => status === MLSStatuses.VALID)
) {
status = MLSStatuses.VALID;
}

Expand Down Expand Up @@ -145,7 +149,7 @@ export const DeviceVerificationBadges = ({
};

async function loadUser() {
if (!identity) {
if (identity === undefined) {
return;
}
const userEntity = await waitFor(() =>
Expand All @@ -161,7 +165,7 @@ export const DeviceVerificationBadges = ({
}, [identity]);

let status: MLSStatuses | undefined = undefined;
if (isE2EIEnabled && identity && user) {
if (isE2EIEnabled && identity !== undefined && user !== undefined) {
const mlsStatuses = getMLSStatuses({identities: [identity], user});
status = mlsStatuses?.[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@

const parseTimeLabel = (value: string | number) => {
const [timePart, periodPart] = `${value}`.trim().split(' ');
const [hourPart, minutePart] = (timePart || '').split(':');
const [hourPart, minutePart] = (timePart ?? '').split(':');
const hour = Number(hourPart);
const minutes = Number(minutePart);
const isPm = (periodPart || '').toUpperCase() === 'PM';
const isPm = (periodPart ?? '').toUpperCase() === 'PM';
const hour24 = Number.isFinite(hour) ? (isPm ? (hour % 12) + 12 : hour % 12) : 0;
const safeMinutes = Number.isFinite(minutes) ? minutes : 0;

Expand Down Expand Up @@ -166,7 +166,7 @@
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), hour24, minutes, 0, 0);
}, [selectedDate, selectedTime]);
const isExpirationInvalid = useMemo(
() => Boolean(selectedDateTime && selectedDateTime.getTime() < Date.now()),
() => selectedDateTime !== null && selectedDateTime.getTime() < Date.now(),
[selectedDateTime],
);
const dateGroupStyles = isExpirationInvalid
Expand Down Expand Up @@ -248,7 +248,7 @@
placement="top start"
shouldFlip={false}
offset={8}
{...(portalContainer ? {portalContainer} : {})}
{...(portalContainer !== undefined ? {portalContainer} : {})}

Check warning on line 251 in apps/webapp/src/script/components/Cells/ShareModal/CellsShareExpirationFields.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=wireapp_wire-webapp&issues=AZ4chlJXUudVs6-nGpXf&open=AZ4chlJXUudVs6-nGpXf&pullRequest=21292
>
<Dialog>
<Calendar>
Expand Down Expand Up @@ -286,9 +286,9 @@
menuCSS={timeSelectMenuStyles}
menuPlacement="top"
maxMenuHeight={menuMaxHeight}
{...(portalContainer && {menuPortalTarget: portalContainer})}
{...(portalContainer !== undefined && {menuPortalTarget: portalContainer})}
onChange={option => {
if (option) {
if (option !== null) {
setSelectedTime(option as Option);
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@
isEditingPassword,
}: ShareModalInput): ShareModalSerializedInput => {
const trimmedPassword = passwordValue.trim();
const hasValidExpiration = !expirationEnabled || (expirationDateTime && !expirationInvalid);
const hasValidExpiration =
expirationEnabled === false || (expirationDateTime !== null && expirationInvalid === false);

const accessEnd = expirationEnabled
? expirationDateTime && !expirationInvalid
? expirationDateTime !== null && expirationInvalid === false
? Math.floor(expirationDateTime.getTime() / 1000).toString()
: undefined

Check warning on line 55 in apps/webapp/src/script/components/Cells/ShareModal/shareModalSerializer.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=wireapp_wire-webapp&issues=AZ4chlJmUudVs6-nGpXg&open=AZ4chlJmUudVs6-nGpXg&pullRequest=21292
: null;

const {isPasswordValid, updatePassword} = getPasswordValidationResult({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface CellsConversationColumnProps {
}

export const CellsConversationColumn = ({conversation, name}: CellsConversationColumnProps) => {
if (!conversation) {
if (conversation === undefined) {
return <span css={textStyles}>{name}</span>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface CellsTableOwnerColumnProps {
}

export const CellsTableOwnerColumn = ({owner, user}: CellsTableOwnerColumnProps) => {
if (!user) {
if (user === null) {
return <span css={textStyles}>{owner}</span>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const showShareModal = ({type, uuid, cellsRepository}: ShareModalParams)
primaryAction: {
action: () => {
const submitHandler = submitHandlers.get(modalId);
if (submitHandler) {
if (submitHandler !== undefined) {
void submitHandler();
}
},
Expand Down Expand Up @@ -114,7 +114,7 @@ const CellsShareModal = ({type, uuid, cellsRepository, modalId}: ShareModalParam

// Initialize toggles and values based on existing link data
useEffect(() => {
if (!isEnabled) {
if (isEnabled === false) {
initializedLinkIdRef.current = null;
return;
}
Expand Down Expand Up @@ -188,7 +188,7 @@ const CellsShareModal = ({type, uuid, cellsRepository, modalId}: ShareModalParam
useEffect(() => {
submitHandlers.set(modalId, async () => {
if (
!isEnabled ||
isEnabled === false ||
status !== 'success' ||
node?.publicLink?.uuid === undefined ||
node.publicLink.uuid.length === 0
Expand Down
Loading
Loading