This commit is contained in:
RMidhunSuresh 2021-12-14 11:33:54 +05:30
parent 3aa29cfc65
commit 545aae31d9
3 changed files with 39 additions and 9 deletions

View File

@ -19,6 +19,12 @@ import {parsePlainBody} from "../MessageBody.js";
import {parseHTMLBody} from "../deserialize.js"; import {parseHTMLBody} from "../deserialize.js";
export class TextTile extends BaseTextTile { export class TextTile extends BaseTextTile {
constructor(options) {
super(options);
this._replyTextTile = null;
}
_getContentString(key) { _getContentString(key) {
return this._getContent()?.[key] || ""; return this._getContent()?.[key] || "";
} }
@ -59,4 +65,17 @@ export class TextTile extends BaseTextTile {
} }
return messageBody; return messageBody;
} }
get replyTextTile() {
if (!this._entry.contextEventId) {
return null;
}
if (!this._replyTextTile) {
const entry = this._entry.contextEntry;
if (entry) {
this._replyTextTile = new TextTile(this.childOptions({entry, roomVM: this._roomVM, timeline: this._timeline}));
}
}
return this._replyTextTile;
}
} }

View File

@ -21,7 +21,13 @@ import {renderPart} from "./TextMessageView.js";
export class ReplyPreviewView extends TemplateView { export class ReplyPreviewView extends TemplateView {
render(t, vm) { render(t, vm) {
const replyContainer = vm.error? this._renderError(vm) : this._renderReplyPreview(vm); const replyContainer = t.div({className: "ReplyPreviewView"});
t.mapSideEffect(vm => vm.body, () => {
while (replyContainer.lastChild) {
replyContainer.removeChild(replyContainer.lastChild);
}
replyContainer.appendChild(vm.error? this._renderError(vm) : this._renderReplyPreview(vm));
})
return replyContainer; return replyContainer;
} }
@ -29,7 +35,7 @@ export class ReplyPreviewView extends TemplateView {
const errorMessage = this._getErrorMessage(error); const errorMessage = this._getErrorMessage(error);
const children = [tag.span({ className: "statusMessage" }, errorMessage), tag.br()]; const children = [tag.span({ className: "statusMessage" }, errorMessage), tag.br()];
const reply = avatar && senderName ? this._renderReplyHeader(avatar, senderName, children) : const reply = avatar && senderName ? this._renderReplyHeader(avatar, senderName, children) :
tag.blockquote({ className: "ReplyPreviewView" }, children); tag.blockquote(children);
return reply; return reply;
} }
@ -45,19 +51,20 @@ export class ReplyPreviewView extends TemplateView {
} }
} }
_renderReplyPreview({ body, avatar, senderName }) { _renderReplyPreview(vm) {
const reply = this._renderReplyHeader(avatar, senderName); const reply = this._renderReplyHeader(vm);
const body = vm.body;
for (const part of body.parts) { for (const part of body.parts) {
reply.appendChild(renderPart(part)); reply.appendChild(renderPart(part));
} }
return reply; return reply;
} }
_renderReplyHeader(avatar, displayName, children = []) { _renderReplyHeader(vm, children = []) {
return tag.blockquote({ className: "ReplyPreviewView" }, return tag.blockquote(
[ [
tag.a({ className: "link", href: "#" }, "In reply to"), tag.a({ className: "link", href: "#" }, "In reply to"),
tag.a({ className: "pill", href: "#" }, [renderStaticAvatar(avatar, 12), displayName]), tag.a({ className: "pill", href: "#" }, [renderStaticAvatar(vm, 12, undefined, true), vm.displayName]),
tag.br(), tag.br(),
...children ...children
]); ]);

View File

@ -26,10 +26,10 @@ export class TextMessageView extends BaseMessageView {
"Timeline_messageBody": true, "Timeline_messageBody": true,
statusMessage: vm => vm.shape === "message-status", statusMessage: vm => vm.shape === "message-status",
} }
}, t.mapView(vm => vm.replyPreviewBody, reply => reply ? new ReplyPreviewView(reply): null)); }, t.mapView(vm => vm.replyTextTile, replyTextTile => replyTextTile ? new ReplyPreviewView(replyTextTile) : null));
t.mapSideEffect(vm => vm.body, body => { t.mapSideEffect(vm => vm.body, body => {
while (container.lastChild && container.lastChild.className !== "ReplyPreviewView") { while (this._shouldRemove(container.lastChild)) {
container.removeChild(container.lastChild); container.removeChild(container.lastChild);
} }
for (const part of body.parts) { for (const part of body.parts) {
@ -41,6 +41,10 @@ export class TextMessageView extends BaseMessageView {
return container; return container;
} }
_shouldRemove(element) {
return element && element.className !== "ReplyPreviewView" && element.nodeName !== "#comment";
}
} }
function renderList(listBlock) { function renderList(listBlock) {