forked from mystiq/hydrogen-web
add UI in settings for push notifs status/enable/disable
This commit is contained in:
parent
630e61a674
commit
7b9904e423
2 changed files with 76 additions and 16 deletions
|
@ -17,6 +17,14 @@ limitations under the License.
|
||||||
import {ViewModel} from "../../ViewModel.js";
|
import {ViewModel} from "../../ViewModel.js";
|
||||||
import {SessionBackupViewModel} from "./SessionBackupViewModel.js";
|
import {SessionBackupViewModel} from "./SessionBackupViewModel.js";
|
||||||
|
|
||||||
|
class PushNotificationStatus {
|
||||||
|
constructor() {
|
||||||
|
this.supported = null;
|
||||||
|
this.enabled = false;
|
||||||
|
this.updating = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function formatKey(key) {
|
function formatKey(key) {
|
||||||
const partLength = 4;
|
const partLength = 4;
|
||||||
const partCount = Math.ceil(key.length / partLength);
|
const partCount = Math.ceil(key.length / partLength);
|
||||||
|
@ -40,6 +48,7 @@ export class SettingsViewModel extends ViewModel {
|
||||||
this.sentImageSizeLimit = null;
|
this.sentImageSizeLimit = null;
|
||||||
this.minSentImageSizeLimit = 400;
|
this.minSentImageSizeLimit = 400;
|
||||||
this.maxSentImageSizeLimit = 4000;
|
this.maxSentImageSizeLimit = 4000;
|
||||||
|
this.pushNotifications = new PushNotificationStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
setSentImageSizeLimit(size) {
|
setSentImageSizeLimit(size) {
|
||||||
|
@ -56,6 +65,8 @@ export class SettingsViewModel extends ViewModel {
|
||||||
async load() {
|
async load() {
|
||||||
this._estimate = await this.platform.estimateStorageUsage();
|
this._estimate = await this.platform.estimateStorageUsage();
|
||||||
this.sentImageSizeLimit = await this.platform.settingsStorage.getInt("sentImageSizeLimit");
|
this.sentImageSizeLimit = await this.platform.settingsStorage.getInt("sentImageSizeLimit");
|
||||||
|
this.pushNotifications.supported = await this.platform.notificationService.supportsPush();
|
||||||
|
this.pushNotifications.enabled = await this._session.arePushNotificationsEnabled();
|
||||||
this.emitChange("");
|
this.emitChange("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,5 +126,21 @@ export class SettingsViewModel extends ViewModel {
|
||||||
const logExport = await this.logger.export();
|
const logExport = await this.logger.export();
|
||||||
this.platform.saveFileAs(logExport.asBlob(), `hydrogen-logs-${this.platform.clock.now()}.json`);
|
this.platform.saveFileAs(logExport.asBlob(), `hydrogen-logs-${this.platform.clock.now()}.json`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async togglePushNotifications() {
|
||||||
|
this.pushNotifications.updating = true;
|
||||||
|
this.emitChange("pushNotifications.updating");
|
||||||
|
try {
|
||||||
|
if (await this._session.enablePushNotifications(!this.pushNotifications.enabled)) {
|
||||||
|
this.pushNotifications.enabled = !this.pushNotifications.enabled;
|
||||||
|
if (this.pushNotifications.enabled) {
|
||||||
|
this.platform.notificationService.showNotification(this.i18n`Push notifications are now enabled`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.pushNotifications.updating = false;
|
||||||
|
this.emitChange("pushNotifications.updating");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,27 +34,60 @@ export class SettingsView extends TemplateView {
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
return t.main({className: "Settings middle"}, [
|
const settingNodes = [];
|
||||||
t.div({className: "middle-header"}, [
|
|
||||||
t.a({className: "button-utility close-middle", href: vm.closeUrl, title: vm.i18n`Close settings`}),
|
settingNodes.push(
|
||||||
t.h2("Settings")
|
|
||||||
]),
|
|
||||||
t.div({className: "SettingsBody"}, [
|
|
||||||
t.h3("Session"),
|
t.h3("Session"),
|
||||||
row(vm.i18n`User ID`, vm.userId),
|
row(vm.i18n`User ID`, vm.userId),
|
||||||
row(vm.i18n`Session ID`, vm.deviceId, "code"),
|
row(vm.i18n`Session ID`, vm.deviceId, "code"),
|
||||||
row(vm.i18n`Session key`, vm.fingerprintKey, "code"),
|
row(vm.i18n`Session key`, vm.fingerprintKey, "code")
|
||||||
|
);
|
||||||
|
settingNodes.push(
|
||||||
t.h3("Session Backup"),
|
t.h3("Session Backup"),
|
||||||
t.view(new SessionBackupSettingsView(vm.sessionBackupViewModel)),
|
t.view(new SessionBackupSettingsView(vm.sessionBackupViewModel))
|
||||||
|
);
|
||||||
|
|
||||||
|
settingNodes.push(
|
||||||
|
t.h3("Notifications"),
|
||||||
|
t.map(vm => vm.pushNotifications.supported, (supported, t) => {
|
||||||
|
if (supported === null) {
|
||||||
|
return t.p(vm.i18n`Loading…`);
|
||||||
|
} else if (supported) {
|
||||||
|
const label = vm => vm.pushNotifications.enabled ?
|
||||||
|
vm.i18n`Push notifications are enabled`:
|
||||||
|
vm.i18n`Push notifications are disabled`;
|
||||||
|
const buttonLabel = vm => vm.pushNotifications.enabled ?
|
||||||
|
vm.i18n`Disable`:
|
||||||
|
vm.i18n`Enable`;
|
||||||
|
return row(label, t.button({
|
||||||
|
onClick: () => vm.togglePushNotifications(),
|
||||||
|
disabled: vm => vm.pushNotifications.updating
|
||||||
|
}, buttonLabel));
|
||||||
|
} else {
|
||||||
|
return t.p(vm.i18n`Push notifications are not supported on this browser`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
settingNodes.push(
|
||||||
t.h3("Preferences"),
|
t.h3("Preferences"),
|
||||||
row(vm.i18n`Scale down images when sending`, this._imageCompressionRange(t, vm)),
|
row(vm.i18n`Scale down images when sending`, this._imageCompressionRange(t, vm)),
|
||||||
|
);
|
||||||
|
settingNodes.push(
|
||||||
t.h3("Application"),
|
t.h3("Application"),
|
||||||
row(vm.i18n`Version`, version),
|
row(vm.i18n`Version`, version),
|
||||||
row(vm.i18n`Storage usage`, vm => `${vm.storageUsage} / ${vm.storageQuota}`),
|
row(vm.i18n`Storage usage`, vm => `${vm.storageUsage} / ${vm.storageQuota}`),
|
||||||
row(vm.i18n`Debug logs`, t.button({onClick: () => vm.exportLogs()}, "Export")),
|
row(vm.i18n`Debug logs`, t.button({onClick: () => vm.exportLogs()}, "Export")),
|
||||||
t.p(["Debug logs contain application usage data including your username, the IDs or aliases of the rooms or groups you have visited, the usernames of other users and the names of files you send. They do not contain messages. For more information, review our ",
|
t.p(["Debug logs contain application usage data including your username, the IDs or aliases of the rooms or groups you have visited, the usernames of other users and the names of files you send. They do not contain messages. For more information, review our ",
|
||||||
t.a({href: "https://element.io/privacy", target: "_blank", rel: "noopener"}, "privacy policy"), "."]),
|
t.a({href: "https://element.io/privacy", target: "_blank", rel: "noopener"}, "privacy policy"), "."]),
|
||||||
])
|
);
|
||||||
|
|
||||||
|
return t.main({className: "Settings middle"}, [
|
||||||
|
t.div({className: "middle-header"}, [
|
||||||
|
t.a({className: "button-utility close-middle", href: vm.closeUrl, title: vm.i18n`Close settings`}),
|
||||||
|
t.h2("Settings")
|
||||||
|
]),
|
||||||
|
t.div({className: "SettingsBody"}, settingNodes)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue