Try requesting the user's identity when the stickerpick fails to auth

Fixes https://github.com/turt2live/matrix-dimension/issues/259
This commit is contained in:
Travis Ralston 2019-03-24 15:07:03 -06:00
parent 5e50e9641c
commit 2a5351404f
2 changed files with 38 additions and 7 deletions

View File

@ -17,15 +17,12 @@
.loading-badge {
text-align: center;
font-size: 20px;
position: relative;
top: calc(50% - 10px);
}
.auth-error {
text-align: center;
position: relative;
height: 300px;
top: calc(50% - 150px);
padding: 20px;
color: themed(stickerPickerErrorColor);
}

View File

@ -1,6 +1,6 @@
import { Component, OnDestroy, OnInit } from "@angular/core";
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { CapableWidget } from "../capable-widget";
import { CapableWidget, WIDGET_API_VERSION_OPENID } from "../capable-widget";
import { Subscription } from "rxjs/Subscription";
import { ScalarWidgetApi } from "../../shared/services/scalar/scalar-widget.api";
import { StickerApiService } from "../../shared/services/integrations/sticker-api.service";
@ -26,7 +26,8 @@ export class StickerPickerWidgetWrapperComponent extends CapableWidget implement
constructor(activatedRoute: ActivatedRoute,
private media: MediaService,
private scalarApi: ScalarServerApiService,
private stickerApi: StickerApiService) {
private stickerApi: StickerApiService,
private changeDetector: ChangeDetectorRef) {
super();
this.supportsStickers = true;
@ -67,6 +68,39 @@ export class StickerPickerWidgetWrapperComponent extends CapableWidget implement
if (this.stickerWidgetApiSubscription) this.stickerWidgetApiSubscription.unsubscribe();
}
protected onSupportedVersionsFound(): void {
super.onSupportedVersionsFound();
if (this.authError && this.doesSupportAtLeastVersion(WIDGET_API_VERSION_OPENID)) {
this.isLoading = true;
this.changeDetector.detectChanges();
this.getOpenIdInfo().then(async response => {
if (response.blocked) {
this.isLoading = false;
this.authError = true;
this.changeDetector.detectChanges();
return;
}
try {
const registerResponse = await this.scalarApi.register(response.openId);
localStorage.setItem("dim-scalar-token", registerResponse.scalar_token);
SessionStorage.scalarToken = registerResponse.scalar_token;
this.authError = !SessionStorage.scalarToken;
this.isLoading = false;
this.loadStickers();
} catch (e) {
console.error(e);
this.isLoading = false;
this.authError = true;
}
this.changeDetector.detectChanges();
});
}
}
public getThumbnailUrl(mxc: string, width: number, height: number, method: "crop" | "scale" = "scale"): string {
return this.media.getThumbnailUrl(mxc, width, height, method, true);
}