Reuse code from timeline view

This commit is contained in:
RMidhunSuresh 2021-12-17 12:46:26 +05:30
parent 89d6968139
commit f01d5d95d9

View file

@ -17,11 +17,7 @@ limitations under the License.
import {renderStaticAvatar} from "../../../avatar"; import {renderStaticAvatar} from "../../../avatar";
import {tag} from "../../../general/html"; import {tag} from "../../../general/html";
import {TemplateView} from "../../../general/TemplateView"; import {TemplateView} from "../../../general/TemplateView";
import {FileView} from "./FileView"; import {viewClassForEntry} from "../TimelineView";
import {ImageView} from "./ImageView";
import {RedactedView} from "./RedactedView";
import {TextMessageView} from "./TextMessageView.js";
import {VideoView} from "./VideoView";
export class ReplyPreviewView extends TemplateView { export class ReplyPreviewView extends TemplateView {
render(t, vm) { render(t, vm) {
@ -29,7 +25,9 @@ export class ReplyPreviewView extends TemplateView {
} }
_renderReplyPreview(t, vm) { _renderReplyPreview(t, vm) {
const view = this._viewFromViewModel(vm); // todo: this should probably be called viewClassForTile instead
const viewClass = viewClassForEntry(vm);
const view = new viewClass(vm)
const rendered = this._renderContent(t, vm, view); const rendered = this._renderContent(t, vm, view);
return this._renderReplyHeader(vm, [rendered]); return this._renderReplyHeader(vm, [rendered]);
} }
@ -44,24 +42,6 @@ export class ReplyPreviewView extends TemplateView {
} }
} }
_viewFromViewModel(vm) {
if (vm.isRedacted) {
return new RedactedView(vm);
}
const shape = vm.shape;
switch (shape) {
case "image":
return new ImageView(vm);
case "video":
return new VideoView(vm);
case "file":
return new FileView(vm);
case "message":
case "message-status":
return new TextMessageView(vm);
}
}
_renderReplyHeader(vm, children = []) { _renderReplyHeader(vm, children = []) {
return tag.blockquote( return tag.blockquote(
[ [