minimal working version of user preview
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {TemplateView} from "../utils/TemplateView.js";
|
||||
|
||||
export class PreviewView extends TemplateView {
|
||||
render(t, vm) {
|
||||
return t.div({className: "PreviewView"}, [
|
||||
t.p(t.img({src: vm => vm.avatarUrl})),
|
||||
t.p(vm => vm.name),
|
||||
t.p(["loading: ", vm => vm.loading])
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -19,21 +19,22 @@ import {ViewModel} from "../ViewModel.js";
|
||||
import {resolveServer} from "./HomeServer.js";
|
||||
|
||||
export class PreviewViewModel extends ViewModel {
|
||||
constructor(request, link) {
|
||||
super();
|
||||
constructor(options) {
|
||||
super(options);
|
||||
const {link, consentedServers} = options;
|
||||
this._link = link;
|
||||
this._request = request;
|
||||
this._consentedServers = consentedServers;
|
||||
this.loading = false;
|
||||
this.name = null;
|
||||
this.avatarURL = null;
|
||||
this.avatarUrl = null;
|
||||
}
|
||||
|
||||
async load() {
|
||||
this.loading = true;
|
||||
this.emitChange();
|
||||
for (const server of this._link.servers) {
|
||||
for (const server of this._consentedServers) {
|
||||
try {
|
||||
const homeserver = await resolveServer(this._request, server);
|
||||
const homeserver = await resolveServer(this.request, server);
|
||||
switch (this._link.kind) {
|
||||
case LinkKind.User:
|
||||
await this._loadUserPreview(homeserver, this._link.identifier);
|
||||
@@ -51,7 +52,7 @@ export class PreviewViewModel extends ViewModel {
|
||||
async _loadUserPreview(homeserver, userId) {
|
||||
const profile = await homeserver.getUserProfile(userId);
|
||||
this.name = profile.displayname || userId;
|
||||
this.avatarURL = profile.avatar_url ?
|
||||
this.avatarUrl = profile.avatar_url ?
|
||||
homeserver.mxcUrlThumbnail(profile.avatar_url, 64, 64, "crop") :
|
||||
null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user