Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Apply strictNullChecks to src/utils/pillify.tsx (#10456)
Browse files Browse the repository at this point in the history
* apply strictNullChecks to src/utils/pillify.tsx

* include change to utility

* apply strictNullChecks to src/utils/permalinks
  • Loading branch information
Kerry authored Mar 27, 2023
1 parent cd700e2 commit ae50eee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/components/views/elements/Pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export enum PillType {
EventInOtherRoom = "TYPE_EVENT_IN_OTHER_ROOM",
}

export const pillRoomNotifPos = (text: string): number => {
return text.indexOf("@room");
export const pillRoomNotifPos = (text: string | null): number => {
return text?.indexOf("@room") ?? -1;
};

export const pillRoomNotifLen = (): number => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/permalinks/Permalinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ const ANY_REGEX = /.*/;
export class RoomPermalinkCreator {
private roomId: string;
private highestPlUserId: string | null = null;
private populationMap: { [serverName: string]: number } | null = null;
private bannedHostsRegexps: RegExp[] | null = null;
private allowedHostsRegexps: RegExp[] | null = null;
private populationMap: { [serverName: string]: number } = {};
private bannedHostsRegexps: RegExp[] = [];
private allowedHostsRegexps: RegExp[] = [];
private _serverCandidates?: string[];
private started = false;

Expand Down
10 changes: 5 additions & 5 deletions src/utils/pillify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
);

ReactDOM.render(pill, pillContainer);
node.parentNode.replaceChild(pillContainer, node);
node.parentNode?.replaceChild(pillContainer, node);
pills.push(pillContainer);
// Pills within pills aren't going to go well, so move on
pillified = true;
Expand All @@ -95,10 +95,10 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
// as applying pills happens outside of react, make sure we're not doubly
// applying @room pills here, as a rerender with the same content won't touch the DOM
// to clear the pills from the last run of pillifyLinks
!node.parentElement.classList.contains("mx_AtRoomPill")
!node.parentElement?.classList.contains("mx_AtRoomPill")
) {
let currentTextNode = node as Node as Text | null;
const roomNotifTextNodes = [];
const roomNotifTextNodes: Text[] = [];

// Take a textNode and break it up to make all the instances of @room their
// own textNode, adding those nodes to roomNotifTextNodes
Expand All @@ -109,7 +109,7 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
let roomTextNode = currentTextNode;

if (roomNotifPos > 0) roomTextNode = roomTextNode.splitText(roomNotifPos);
if (roomTextNode.textContent.length > pillRoomNotifLen()) {
if (roomTextNode.textContent && roomTextNode.textContent.length > pillRoomNotifLen()) {
nextTextNode = roomTextNode.splitText(pillRoomNotifLen());
}
roomNotifTextNodes.push(roomTextNode);
Expand Down Expand Up @@ -140,7 +140,7 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
);

ReactDOM.render(pill, pillContainer);
roomNotifTextNode.parentNode.replaceChild(pillContainer, roomNotifTextNode);
roomNotifTextNode.parentNode?.replaceChild(pillContainer, roomNotifTextNode);
pills.push(pillContainer);
}
// Nothing else to do for a text node (and we don't need to advance
Expand Down

0 comments on commit ae50eee

Please sign in to comment.