Conform more of the codebase to strictNullChecks
(#10738)
This commit is contained in:
parent
5e8488c283
commit
52017f62e1
18 changed files with 105 additions and 84 deletions
package.json
src
LegacyCallHandler.tsxNotifier.ts
yarn.lockactions
components
structures
views
hooks
linkify-matrix.tsmodules
notifications
utils
|
@ -62,7 +62,7 @@
|
|||
"@babel/runtime": "^7.12.5",
|
||||
"@matrix-org/analytics-events": "^0.5.0",
|
||||
"@matrix-org/matrix-wysiwyg": "^2.0.0",
|
||||
"@matrix-org/react-sdk-module-api": "^0.0.4",
|
||||
"@matrix-org/react-sdk-module-api": "^0.0.5",
|
||||
"@sentry/browser": "^7.0.0",
|
||||
"@sentry/tracing": "^7.0.0",
|
||||
"@testing-library/react-hooks": "^8.0.1",
|
||||
|
|
|
@ -711,8 +711,8 @@ export default class LegacyCallHandler extends EventEmitter {
|
|||
// Don't show a modal when we got rejected/the call was hung up
|
||||
if (!hangupReason || [CallErrorCode.UserHangup, "user hangup"].includes(hangupReason)) break;
|
||||
|
||||
let title;
|
||||
let description;
|
||||
let title: string;
|
||||
let description: string;
|
||||
// TODO: We should either do away with these or figure out a copy for each code (expect user_hangup...)
|
||||
if (call.hangupReason === CallErrorCode.UserBusy) {
|
||||
title = _t("User Busy");
|
||||
|
@ -1094,16 +1094,17 @@ export default class LegacyCallHandler extends EventEmitter {
|
|||
}
|
||||
|
||||
const roomId = await ensureDMExists(MatrixClientPeg.get(), nativeUserId);
|
||||
|
||||
if (isNotNull(roomId)) {
|
||||
dis.dispatch<ViewRoomPayload>({
|
||||
action: Action.ViewRoom,
|
||||
room_id: roomId,
|
||||
metricsTrigger: "WebDialPad",
|
||||
});
|
||||
|
||||
await this.placeMatrixCall(roomId, CallType.Voice, transferee);
|
||||
if (!roomId) {
|
||||
throw new Error("Failed to ensure DM exists for dialing number");
|
||||
}
|
||||
|
||||
dis.dispatch<ViewRoomPayload>({
|
||||
action: Action.ViewRoom,
|
||||
room_id: roomId,
|
||||
metricsTrigger: "WebDialPad",
|
||||
});
|
||||
|
||||
await this.placeMatrixCall(roomId, CallType.Voice, transferee);
|
||||
}
|
||||
|
||||
public async startTransferToPhoneNumber(
|
||||
|
|
|
@ -197,8 +197,14 @@ class NotifierClass {
|
|||
|
||||
// Ideally in here we could use MSC1310 to detect the type of file, and reject it.
|
||||
|
||||
const url = mediaFromMxc(content.url).srcHttp;
|
||||
if (!url) {
|
||||
logger.warn("Something went wrong when generating src http url for mxc");
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
url: mediaFromMxc(content.url).srcHttp,
|
||||
url,
|
||||
name: content.name,
|
||||
type: content.type,
|
||||
size: content.size,
|
||||
|
|
|
@ -53,7 +53,7 @@ export default class RoomListActions {
|
|||
newTag: TagID | null,
|
||||
newIndex: number,
|
||||
): AsyncActionPayload {
|
||||
let metaData: Parameters<MatrixClient["setRoomTag"]>[2] | null = null;
|
||||
let metaData: Parameters<MatrixClient["setRoomTag"]>[2] | undefined;
|
||||
|
||||
// Is the tag ordered manually?
|
||||
const store = RoomListStore.instance;
|
||||
|
@ -113,10 +113,6 @@ export default class RoomListActions {
|
|||
|
||||
// if we moved lists or the ordering changed, add the new tag
|
||||
if (newTag && newTag !== DefaultTagID.DM && (hasChangedSubLists || metaData)) {
|
||||
// metaData is the body of the PUT to set the tag, so it must
|
||||
// at least be an empty object.
|
||||
metaData = metaData || ({} as typeof metaData);
|
||||
|
||||
const promiseToAdd = matrixClient.setRoomTag(roomId, newTag, metaData).catch(function (err) {
|
||||
logger.error("Failed to add tag " + newTag + " to room: " + err);
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
|
|
|
@ -71,7 +71,7 @@ class FilePanel extends React.Component<IProps, IState> {
|
|||
removed: boolean,
|
||||
data: IRoomTimelineData,
|
||||
): void => {
|
||||
if (room?.roomId !== this.props?.roomId) return;
|
||||
if (room?.roomId !== this.props.roomId) return;
|
||||
if (toStartOfTimeline || !data || !data.liveEvent || ev.isRedacted()) return;
|
||||
|
||||
const client = MatrixClientPeg.get();
|
||||
|
|
|
@ -164,7 +164,7 @@ interface IProps {
|
|||
onNewScreen: (screen: string, replaceLast: boolean) => void;
|
||||
enableGuest?: boolean;
|
||||
// the queryParams extracted from the [real] query-string of the URI
|
||||
realQueryParams?: QueryDict;
|
||||
realQueryParams: QueryDict;
|
||||
// the initial queryParams extracted from the hash-fragment of the URI
|
||||
startingFragmentQueryParams?: QueryDict;
|
||||
// called when we have completed a token login
|
||||
|
|
|
@ -97,7 +97,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
|
|||
|
||||
return {
|
||||
cardState: currentCard?.state,
|
||||
phase: currentCard?.phase,
|
||||
phase: currentCard?.phase ?? undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
|
|||
this.delayedUpdate();
|
||||
} else if (
|
||||
this.state.phase === RightPanelPhases.RoomMemberInfo &&
|
||||
member.userId === this.state.cardState.member?.userId
|
||||
member.userId === this.state.cardState?.member?.userId
|
||||
) {
|
||||
// refresh the member info (e.g. new power level)
|
||||
this.delayedUpdate();
|
||||
|
@ -156,7 +156,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
|
|||
const cardState = this.props.overwriteCard?.state ?? this.state.cardState;
|
||||
switch (phase) {
|
||||
case RightPanelPhases.RoomMemberList:
|
||||
if (roomId) {
|
||||
if (!!roomId) {
|
||||
card = (
|
||||
<MemberList
|
||||
roomId={roomId}
|
||||
|
@ -199,7 +199,9 @@ export default class RightPanel extends React.Component<IProps, IState> {
|
|||
}
|
||||
case RightPanelPhases.Room3pidMemberInfo:
|
||||
case RightPanelPhases.Space3pidMemberInfo:
|
||||
card = <ThirdPartyMemberInfo event={cardState?.memberInfoEvent} key={roomId} />;
|
||||
if (!!cardState?.memberInfoEvent) {
|
||||
card = <ThirdPartyMemberInfo event={cardState.memberInfoEvent} key={roomId} />;
|
||||
}
|
||||
break;
|
||||
|
||||
case RightPanelPhases.NotificationPanel:
|
||||
|
@ -207,7 +209,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
|
|||
break;
|
||||
|
||||
case RightPanelPhases.PinnedMessages:
|
||||
if (this.props.room && SettingsStore.getValue("feature_pinning")) {
|
||||
if (!!this.props.room && SettingsStore.getValue("feature_pinning")) {
|
||||
card = (
|
||||
<PinnedMessagesCard
|
||||
room={this.props.room}
|
||||
|
@ -218,7 +220,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
|
|||
}
|
||||
break;
|
||||
case RightPanelPhases.Timeline:
|
||||
if (this.props.room) {
|
||||
if (!!this.props.room) {
|
||||
card = (
|
||||
<TimelineCard
|
||||
classNames="mx_ThreadPanel mx_TimelineCard"
|
||||
|
@ -233,20 +235,24 @@ export default class RightPanel extends React.Component<IProps, IState> {
|
|||
}
|
||||
break;
|
||||
case RightPanelPhases.FilePanel:
|
||||
card = <FilePanel roomId={roomId} resizeNotifier={this.props.resizeNotifier} onClose={this.onClose} />;
|
||||
if (!!roomId) {
|
||||
card = (
|
||||
<FilePanel roomId={roomId} resizeNotifier={this.props.resizeNotifier} onClose={this.onClose} />
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case RightPanelPhases.ThreadView:
|
||||
if (this.props.room) {
|
||||
if (!!this.props.room && !!cardState?.threadHeadEvent) {
|
||||
card = (
|
||||
<ThreadView
|
||||
room={this.props.room}
|
||||
resizeNotifier={this.props.resizeNotifier}
|
||||
onClose={this.onClose}
|
||||
mxEvent={cardState?.threadHeadEvent}
|
||||
initialEvent={cardState?.initialEvent}
|
||||
isInitialEventHighlighted={cardState?.isInitialEventHighlighted}
|
||||
initialEventScrollIntoView={cardState?.initialEventScrollIntoView}
|
||||
mxEvent={cardState.threadHeadEvent}
|
||||
initialEvent={cardState.initialEvent}
|
||||
isInitialEventHighlighted={cardState.isInitialEventHighlighted}
|
||||
initialEventScrollIntoView={cardState.initialEventScrollIntoView}
|
||||
permalinkCreator={this.props.permalinkCreator}
|
||||
e2eStatus={this.props.e2eStatus}
|
||||
/>
|
||||
|
@ -255,18 +261,20 @@ export default class RightPanel extends React.Component<IProps, IState> {
|
|||
break;
|
||||
|
||||
case RightPanelPhases.ThreadPanel:
|
||||
card = (
|
||||
<ThreadPanel
|
||||
roomId={roomId}
|
||||
resizeNotifier={this.props.resizeNotifier}
|
||||
onClose={this.onClose}
|
||||
permalinkCreator={this.props.permalinkCreator}
|
||||
/>
|
||||
);
|
||||
if (!!roomId) {
|
||||
card = (
|
||||
<ThreadPanel
|
||||
roomId={roomId}
|
||||
resizeNotifier={this.props.resizeNotifier}
|
||||
onClose={this.onClose}
|
||||
permalinkCreator={this.props.permalinkCreator}
|
||||
/>
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case RightPanelPhases.RoomSummary:
|
||||
if (this.props.room) {
|
||||
if (!!this.props.room) {
|
||||
card = (
|
||||
<RoomSummaryCard
|
||||
room={this.props.room}
|
||||
|
@ -279,8 +287,8 @@ export default class RightPanel extends React.Component<IProps, IState> {
|
|||
break;
|
||||
|
||||
case RightPanelPhases.Widget:
|
||||
if (this.props.room) {
|
||||
card = <WidgetCard room={this.props.room} widgetId={cardState?.widgetId} onClose={this.onClose} />;
|
||||
if (!!this.props.room && !!cardState?.widgetId) {
|
||||
card = <WidgetCard room={this.props.room} widgetId={cardState.widgetId} onClose={this.onClose} />;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -626,7 +626,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
wasContextSwitch: this.context.roomViewStore.getWasContextSwitch(),
|
||||
mainSplitContentType: room ? this.getMainSplitContentType(room) : undefined,
|
||||
initialEventId: undefined, // default to clearing this, will get set later in the method if needed
|
||||
showRightPanel: this.context.rightPanelStore.isOpenForRoom(roomId),
|
||||
showRightPanel: roomId ? this.context.rightPanelStore.isOpenForRoom(roomId) : false,
|
||||
activeCall: roomId ? CallStore.instance.getActiveCall(roomId) : null,
|
||||
};
|
||||
|
||||
|
@ -662,7 +662,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
newState.initialEventPixelOffset = undefined;
|
||||
|
||||
const thread = initialEvent?.getThread();
|
||||
if (thread && !initialEvent?.isThreadRoot) {
|
||||
if (thread?.rootEvent && !initialEvent?.isThreadRoot) {
|
||||
dis.dispatch<ShowThreadPayload>({
|
||||
action: Action.ShowThread,
|
||||
rootEvent: thread.rootEvent,
|
||||
|
@ -675,7 +675,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
newState.isInitialEventHighlighted = this.context.roomViewStore.isInitialEventHighlighted();
|
||||
newState.initialEventScrollIntoView = this.context.roomViewStore.initialEventScrollIntoView();
|
||||
|
||||
if (thread && initialEvent?.isThreadRoot) {
|
||||
if (thread?.rootEvent && initialEvent?.isThreadRoot) {
|
||||
dis.dispatch<ShowThreadPayload>({
|
||||
action: Action.ShowThread,
|
||||
rootEvent: thread.rootEvent,
|
||||
|
@ -1016,7 +1016,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
|
||||
private onRightPanelStoreUpdate = (): void => {
|
||||
this.setState({
|
||||
showRightPanel: this.context.rightPanelStore.isOpenForRoom(this.state.roomId),
|
||||
showRightPanel: this.state.roomId ? this.context.rightPanelStore.isOpenForRoom(this.state.roomId) : false,
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1087,7 +1087,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
case "picture_snapshot":
|
||||
ContentMessages.sharedInstance().sendContentListToRoom(
|
||||
[payload.file],
|
||||
this.state.room.roomId,
|
||||
this.getRoomId(),
|
||||
undefined,
|
||||
this.context.client,
|
||||
);
|
||||
|
@ -1496,6 +1496,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
);
|
||||
|
||||
private checkDesktopNotifications(): void {
|
||||
if (!this.state.room) return;
|
||||
const memberCount = this.state.room.getJoinedMemberCount() + this.state.room.getInvitedMemberCount();
|
||||
// if they are not alone prompt the user about notifications so they don't miss replies
|
||||
if (memberCount > 1 && Notifier.shouldShowPrompt()) {
|
||||
|
@ -1518,7 +1519,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
// open the room inviter
|
||||
dis.dispatch({
|
||||
action: "view_invite",
|
||||
roomId: this.state.room.roomId,
|
||||
roomId: this.getRoomId(),
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1588,7 +1589,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
debuglog("Removing scroll_into_view flag from initial event");
|
||||
dis.dispatch<ViewRoomPayload>({
|
||||
action: Action.ViewRoom,
|
||||
room_id: this.state.room.roomId,
|
||||
room_id: this.getRoomId(),
|
||||
event_id: this.state.initialEventId,
|
||||
highlighted: this.state.isInitialEventHighlighted,
|
||||
scroll_into_view: false,
|
||||
|
@ -1606,7 +1607,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
}
|
||||
|
||||
ContentMessages.sharedInstance()
|
||||
.sendStickerContentToRoom(url, this.state.room.roomId, threadId, info, text, this.context.client)
|
||||
.sendStickerContentToRoom(url, this.getRoomId(), threadId, info, text, this.context.client)
|
||||
.then(undefined, (error) => {
|
||||
if (error.name === "UnknownDeviceError") {
|
||||
// Let the staus bar handle this
|
||||
|
@ -1616,7 +1617,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
}
|
||||
|
||||
private onSearch = (term: string, scope: SearchScope): void => {
|
||||
const roomId = scope === SearchScope.Room ? this.state.room.roomId : undefined;
|
||||
const roomId = scope === SearchScope.Room ? this.getRoomId() : undefined;
|
||||
debuglog("sending search request");
|
||||
const abortController = new AbortController();
|
||||
const promise = eventSearch(term, roomId, abortController.signal);
|
||||
|
@ -1655,7 +1656,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
private onForgetClick = (): void => {
|
||||
dis.dispatch({
|
||||
action: "forget_room",
|
||||
room_id: this.state.room.roomId,
|
||||
room_id: this.getRoomId(),
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1663,7 +1664,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
this.setState({
|
||||
rejecting: true,
|
||||
});
|
||||
this.context.client?.leave(this.state.roomId).then(
|
||||
this.context.client?.leave(this.getRoomId()).then(
|
||||
() => {
|
||||
dis.dispatch({ action: Action.ViewHomePage });
|
||||
this.setState({
|
||||
|
@ -1757,7 +1758,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
// jumping to the bottom
|
||||
dis.dispatch<ViewRoomPayload>({
|
||||
action: Action.ViewRoom,
|
||||
room_id: this.state.room.roomId,
|
||||
room_id: this.getRoomId(),
|
||||
metricsTrigger: undefined, // room doesn't change
|
||||
});
|
||||
} else {
|
||||
|
@ -1903,7 +1904,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
private onFileDrop = (dataTransfer: DataTransfer): Promise<void> =>
|
||||
ContentMessages.sharedInstance().sendContentListToRoom(
|
||||
Array.from(dataTransfer.files),
|
||||
this.state.room?.roomId ?? this.state.roomId,
|
||||
this.getRoomId(),
|
||||
null,
|
||||
this.context.client,
|
||||
TimelineRenderingType.Room,
|
||||
|
@ -1921,7 +1922,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
return this.getPermalinkCreatorForRoom(this.state.room);
|
||||
}
|
||||
|
||||
private renderLocalRoomCreateLoader(localRoom: LocalRoom): ReactElement {
|
||||
private renderLocalRoomCreateLoader(localRoom: LocalRoom): ReactNode {
|
||||
if (!this.state.room || !this.context?.client) return null;
|
||||
const names = this.state.room.getDefaultRoomName(this.context.client.getSafeUserId());
|
||||
return (
|
||||
<RoomContext.Provider value={this.state}>
|
||||
|
@ -1930,7 +1932,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
);
|
||||
}
|
||||
|
||||
private renderLocalRoomView(localRoom: LocalRoom): ReactElement {
|
||||
private renderLocalRoomView(localRoom: LocalRoom): ReactNode {
|
||||
return (
|
||||
<RoomContext.Provider value={this.state}>
|
||||
<LocalRoomView
|
||||
|
@ -1944,7 +1946,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
);
|
||||
}
|
||||
|
||||
private renderWaitingForThirdPartyRoomView(inviteEvent: MatrixEvent): ReactElement {
|
||||
private renderWaitingForThirdPartyRoomView(inviteEvent: MatrixEvent): ReactNode {
|
||||
return (
|
||||
<RoomContext.Provider value={this.state}>
|
||||
<WaitingForThirdPartyRoomView
|
||||
|
@ -1956,7 +1958,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
);
|
||||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
public render(): ReactNode {
|
||||
if (!this.context.client) return null;
|
||||
|
||||
if (this.state.room instanceof LocalRoom) {
|
||||
|
|
|
@ -1023,7 +1023,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
|||
shouldSendRR &&
|
||||
// Only send a RR if the last read event is ahead in the timeline relative to
|
||||
// the current RR event.
|
||||
lastReadEventIndex > currentRREventIndex &&
|
||||
lastReadEventIndex! > currentRREventIndex! &&
|
||||
// Only send a RR if the last RR set != the one we would send
|
||||
this.lastRRSentEventId !== lastReadEvent?.getId();
|
||||
|
||||
|
@ -1307,7 +1307,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
|||
const pos = this.getReadMarkerPosition();
|
||||
const ret =
|
||||
this.state.readMarkerEventId !== null && // 1.
|
||||
(pos < 0 || pos === null); // 3., 4.
|
||||
(pos === null || pos < 0); // 3., 4.
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
@ -1351,7 +1351,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
|||
"TimelinePanel scrolling to eventId " +
|
||||
eventId +
|
||||
" at position " +
|
||||
offsetBase * 100 +
|
||||
offsetBase! * 100 +
|
||||
"% + " +
|
||||
pixelOffset,
|
||||
);
|
||||
|
|
|
@ -64,7 +64,7 @@ interface IOptionsButtonProps {
|
|||
// TODO: Types
|
||||
getTile: () => any | null;
|
||||
getReplyChain: () => ReplyChain | null;
|
||||
permalinkCreator: RoomPermalinkCreator;
|
||||
permalinkCreator?: RoomPermalinkCreator;
|
||||
onFocusChange: (menuDisplayed: boolean) => void;
|
||||
getRelationsForEvent?: GetRelationsForEvent;
|
||||
}
|
||||
|
@ -208,10 +208,11 @@ const ReplyInThreadButton: React.FC<IReplyInThreadButton> = ({ mxEvent }) => {
|
|||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
if (mxEvent.getThread() && !mxEvent.isThreadRoot) {
|
||||
const thread = mxEvent.getThread();
|
||||
if (thread?.rootEvent && !mxEvent.isThreadRoot) {
|
||||
defaultDispatcher.dispatch<ShowThreadPayload>({
|
||||
action: Action.ShowThread,
|
||||
rootEvent: mxEvent.getThread()!.rootEvent,
|
||||
rootEvent: thread.rootEvent,
|
||||
initialEvent: mxEvent,
|
||||
scroll_into_view: true,
|
||||
highlighted: true,
|
||||
|
|
|
@ -576,6 +576,12 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
|
|||
|
||||
const encryptionInfo = MatrixClientPeg.get().getEventEncryptionInfo(mxEvent);
|
||||
const senderId = mxEvent.getSender();
|
||||
if (!senderId) {
|
||||
// something definitely wrong is going on here
|
||||
this.setState({ verified: E2EState.Warning });
|
||||
return;
|
||||
}
|
||||
|
||||
const userTrust = MatrixClientPeg.get().checkUserTrust(senderId);
|
||||
|
||||
if (encryptionInfo.mismatchedSender) {
|
||||
|
|
|
@ -55,7 +55,7 @@ const SpacePublicShare: React.FC<IProps> = ({ space, onFinished }) => {
|
|||
{_t("Share invite link")}
|
||||
<span>{copiedText}</span>
|
||||
</AccessibleButton>
|
||||
{space.canInvite(MatrixClientPeg.get()?.getUserId()) && shouldShowComponent(UIComponent.InviteUsers) ? (
|
||||
{space.canInvite(MatrixClientPeg.get()?.getSafeUserId()) && shouldShowComponent(UIComponent.InviteUsers) ? (
|
||||
<AccessibleButton
|
||||
className="mx_SpacePublicShare_inviteButton"
|
||||
onClick={() => {
|
||||
|
|
|
@ -23,11 +23,13 @@ import { PROPERTY_UPDATED } from "../stores/local-echo/GenericEchoChamber";
|
|||
import { CachedRoomKey } from "../stores/local-echo/RoomEchoChamber";
|
||||
import { useEventEmitter } from "./useEventEmitter";
|
||||
|
||||
export const useNotificationState = (room: Room): [RoomNotifState, (state: RoomNotifState) => void] => {
|
||||
export const useNotificationState = (room: Room): [RoomNotifState | undefined, (state: RoomNotifState) => void] => {
|
||||
const echoChamber = useMemo(() => EchoChamber.forRoom(room), [room]);
|
||||
const [notificationState, setNotificationState] = useState<RoomNotifState>(echoChamber.notificationVolume);
|
||||
const [notificationState, setNotificationState] = useState<RoomNotifState | undefined>(
|
||||
echoChamber.notificationVolume,
|
||||
);
|
||||
useEventEmitter(echoChamber, PROPERTY_UPDATED, (key: CachedRoomKey) => {
|
||||
if (key === CachedRoomKey.NotificationVolume) {
|
||||
if (key === CachedRoomKey.NotificationVolume && echoChamber.notificationVolume !== undefined) {
|
||||
setNotificationState(echoChamber.notificationVolume);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -191,12 +191,12 @@ export const options: Opts = {
|
|||
return {};
|
||||
},
|
||||
|
||||
formatHref: function (href: string, type: Type | string): string | null {
|
||||
formatHref: function (href: string, type: Type | string): string {
|
||||
switch (type) {
|
||||
case Type.RoomAlias:
|
||||
case Type.UserId:
|
||||
default: {
|
||||
return tryTransformEntityToPermalink(href);
|
||||
return tryTransformEntityToPermalink(href) ?? "";
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -209,7 +209,7 @@ export const options: Opts = {
|
|||
|
||||
className: "linkified",
|
||||
|
||||
target: function (href: string, type: Type | string): string | null {
|
||||
target: function (href: string, type: Type | string): string {
|
||||
if (type === Type.URL) {
|
||||
try {
|
||||
const transformed = tryTransformPermalinkToLocalHref(href);
|
||||
|
@ -217,7 +217,7 @@ export const options: Opts = {
|
|||
transformed !== href || // if it could be converted to handle locally for matrix symbols e.g. @user:server.tdl and matrix.to
|
||||
decodeURIComponent(href).match(ELEMENT_URL_PATTERN) // for https links to Element domains
|
||||
) {
|
||||
return null;
|
||||
return "";
|
||||
} else {
|
||||
return "_blank";
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ export const options: Opts = {
|
|||
// malformed URI
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return "";
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ export class ProxiedModuleApi implements ModuleApi {
|
|||
/**
|
||||
* @override
|
||||
*/
|
||||
public getConfigValue<T>(namespace: string, key: string): T {
|
||||
public getConfigValue<T>(namespace: string, key: string): T | undefined {
|
||||
// Force cast to `any` because the namespace won't be known to the SdkConfig types
|
||||
const maybeObj = SdkConfig.get(namespace as any);
|
||||
if (!maybeObj || !(typeof maybeObj === "object")) return undefined;
|
||||
|
|
|
@ -47,7 +47,7 @@ export class PushRuleVectorState {
|
|||
*
|
||||
* @return [object] list of push-rule actions
|
||||
*/
|
||||
public static actionsFor(pushRuleVectorState: VectorState): PushRuleAction[] {
|
||||
public static actionsFor(pushRuleVectorState?: VectorState): PushRuleAction[] {
|
||||
if (pushRuleVectorState === VectorState.On) {
|
||||
return StandardActions.ACTION_NOTIFY;
|
||||
} else if (pushRuleVectorState === VectorState.Loud) {
|
||||
|
|
|
@ -77,12 +77,11 @@ export function formatCryptoKey(key: string): string {
|
|||
*/
|
||||
export function hashCode(str: string): number {
|
||||
let hash = 0;
|
||||
let i;
|
||||
let chr;
|
||||
let chr: number;
|
||||
if (str.length === 0) {
|
||||
return hash;
|
||||
}
|
||||
for (i = 0; i < str.length; i++) {
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
chr = str.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + chr;
|
||||
hash |= 0;
|
||||
|
|
|
@ -1595,10 +1595,10 @@
|
|||
version "3.2.14"
|
||||
resolved "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz#acd96c00a881d0f462e1f97a56c73742c8dbc984"
|
||||
|
||||
"@matrix-org/react-sdk-module-api@^0.0.4":
|
||||
version "0.0.4"
|
||||
resolved "https://registry.yarnpkg.com/@matrix-org/react-sdk-module-api/-/react-sdk-module-api-0.0.4.tgz#da71fc2e4c8143e87b5c2bc067ccbc0c146816fe"
|
||||
integrity sha512-4gcgef3Ne9+Ae0bAErK1Swo9FxTZBDEogX/Iu2kcLWWROOKMjmeWL2PkM83ylsxZ32YY6a6ndRqV/SwRmDeJxg==
|
||||
"@matrix-org/react-sdk-module-api@^0.0.5":
|
||||
version "0.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@matrix-org/react-sdk-module-api/-/react-sdk-module-api-0.0.5.tgz#78bd80f42b918394978965ef3e08496e97948c7a"
|
||||
integrity sha512-QhH1T1E6Q6csCUitQzm32SRnX49Ox73TF5BZ4p5TOGFpPD3QuYc5/dDC1Yh3xUljgqOS2C6H24qaskw6olCtfQ==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.17.9"
|
||||
|
||||
|
|
Loading…
Reference in a new issue