Use MatrixClientPeg::safeGet in src/components/views/* (#10987)
This commit is contained in:
parent
4243847f4f
commit
280f6a9d93
81 changed files with 265 additions and 250 deletions
|
@ -270,7 +270,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
}
|
||||
|
||||
private async refreshFromAccountData(): Promise<void> {
|
||||
const cli = MatrixClientPeg.get();
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
const settingsEvent = cli.getAccountData(getLocalNotificationAccountDataEventType(cli.deviceId));
|
||||
if (settingsEvent) {
|
||||
const notificationsEnabled = !(settingsEvent.getContent() as LocalNotificationSettings).is_silenced;
|
||||
|
@ -279,14 +279,14 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
}
|
||||
|
||||
private persistLocalNotificationSettings(enabled: boolean): Promise<{}> {
|
||||
const cli = MatrixClientPeg.get();
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
return cli.setAccountData(getLocalNotificationAccountDataEventType(cli.deviceId), {
|
||||
is_silenced: !enabled,
|
||||
});
|
||||
}
|
||||
|
||||
private async refreshRules(): Promise<Partial<IState>> {
|
||||
const ruleSets = await MatrixClientPeg.get().getPushRules()!;
|
||||
const ruleSets = await MatrixClientPeg.safeGet().getPushRules()!;
|
||||
const categories: Record<string, RuleClass> = {
|
||||
[RuleId.Master]: RuleClass.Master,
|
||||
|
||||
|
@ -384,11 +384,11 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
}
|
||||
|
||||
private refreshPushers(): Promise<Partial<IState>> {
|
||||
return MatrixClientPeg.get().getPushers();
|
||||
return MatrixClientPeg.safeGet().getPushers();
|
||||
}
|
||||
|
||||
private refreshThreepids(): Promise<Partial<IState>> {
|
||||
return MatrixClientPeg.get().getThreePids();
|
||||
return MatrixClientPeg.safeGet().getThreePids();
|
||||
}
|
||||
|
||||
private showSaveError(): void {
|
||||
|
@ -403,7 +403,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
|
||||
const masterRule = this.state.masterPushRule!;
|
||||
try {
|
||||
await MatrixClientPeg.get().setPushRuleEnabled("global", masterRule.kind, masterRule.rule_id, !checked);
|
||||
await MatrixClientPeg.safeGet().setPushRuleEnabled("global", masterRule.kind, masterRule.rule_id, !checked);
|
||||
await this.refreshFromServer();
|
||||
} catch (e) {
|
||||
this.setState({ phase: Phase.Error });
|
||||
|
@ -428,7 +428,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
|
||||
try {
|
||||
if (checked) {
|
||||
await MatrixClientPeg.get().setPusher({
|
||||
await MatrixClientPeg.safeGet().setPusher({
|
||||
kind: "email",
|
||||
app_id: "m.email",
|
||||
pushkey: email,
|
||||
|
@ -446,7 +446,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
} else {
|
||||
const pusher = this.state.pushers?.find((p) => p.kind === "email" && p.pushkey === email);
|
||||
if (pusher) {
|
||||
await MatrixClientPeg.get().removePusher(pusher.pushkey, pusher.app_id);
|
||||
await MatrixClientPeg.safeGet().removePusher(pusher.pushkey, pusher.app_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
}));
|
||||
|
||||
try {
|
||||
const cli = MatrixClientPeg.get();
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
if (rule.ruleId === KEYWORD_RULE_ID) {
|
||||
// should not encounter this
|
||||
if (!this.state.vectorKeywordRuleInfo) {
|
||||
|
@ -536,7 +536,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
private onClearNotificationsClicked = async (): Promise<void> => {
|
||||
try {
|
||||
this.setState({ clearingNotifications: true });
|
||||
const client = MatrixClientPeg.get();
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
await clearAllNotifications(client);
|
||||
} finally {
|
||||
this.setState({ clearingNotifications: false });
|
||||
|
@ -560,7 +560,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
|
||||
for (const word of diff.removed) {
|
||||
for (const rule of originalRules.filter((r) => r.pattern === word)) {
|
||||
await MatrixClientPeg.get().deletePushRule("global", rule.kind, rule.rule_id);
|
||||
await MatrixClientPeg.safeGet().deletePushRule("global", rule.kind, rule.rule_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -577,12 +577,12 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
}
|
||||
const kind = PushRuleKind.ContentSpecific;
|
||||
for (const word of diff.added) {
|
||||
await MatrixClientPeg.get().addPushRule("global", kind, word, {
|
||||
await MatrixClientPeg.safeGet().addPushRule("global", kind, word, {
|
||||
actions: PushRuleVectorState.actionsFor(ruleVectorState),
|
||||
pattern: word,
|
||||
});
|
||||
if (ruleVectorState === VectorState.Off) {
|
||||
await MatrixClientPeg.get().setPushRuleEnabled("global", kind, word, false);
|
||||
await MatrixClientPeg.safeGet().setPushRuleEnabled("global", kind, word, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -730,7 +730,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
let clearNotifsButton: JSX.Element | undefined;
|
||||
if (
|
||||
category === RuleClass.VectorOther &&
|
||||
MatrixClientPeg.get()
|
||||
MatrixClientPeg.safeGet()
|
||||
.getRooms()
|
||||
.some((r) => r.getUnreadNotificationCount() > 0)
|
||||
) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue