mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 03:36:07 +03:00
Apply strictNullChecks
to src/utils/pillify.tsx
(#10456)
* apply strictNullChecks to src/utils/pillify.tsx * include change to utility * apply strictNullChecks to src/utils/permalinks
This commit is contained in:
parent
cd700e20fc
commit
ae50eee135
3 changed files with 10 additions and 10 deletions
|
@ -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 => {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue