Render non-text messages as well

This commit is contained in:
RMidhunSuresh 2021-12-16 17:35:19 +05:30
parent df22db256b
commit bb45d0eae9
3 changed files with 55 additions and 20 deletions

View File

@ -24,6 +24,7 @@ export class BaseMessageTile extends SimpleTile {
this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null; this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null;
this._isContinuation = false; this._isContinuation = false;
this._reactions = null; this._reactions = null;
this._replyTextTile = null;
if (this._entry.annotations || this._entry.pendingAnnotations) { if (this._entry.annotations || this._entry.pendingAnnotations) {
this._updateReactions(); this._updateReactions();
} }
@ -210,4 +211,17 @@ export class BaseMessageTile extends SimpleTile {
this._reactions.update(annotations, pendingAnnotations); this._reactions.update(annotations, pendingAnnotations);
} }
} }
get replyTextTile() {
if (!this._entry.contextEventId) {
return null;
}
if (!this._replyTextTile) {
const entry = this._entry.contextEntry;
if (entry) {
this._replyTextTile = this._tileCreator(entry);
}
}
return this._replyTextTile;
}
} }

View File

@ -22,7 +22,6 @@ export class TextTile extends BaseTextTile {
constructor(options) { constructor(options) {
super(options); super(options);
this._replyTextTile = null;
} }
_getContentString(key) { _getContentString(key) {
@ -66,16 +65,4 @@ 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 = this._tileCreator(entry);
}
}
return this._replyTextTile;
}
} }

View File

@ -17,7 +17,10 @@ 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 {renderPart} from "./TextMessageView.js"; import {FileView} from "./FileView";
import {ImageView} from "./ImageView";
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) {
@ -26,7 +29,7 @@ export class ReplyPreviewView extends TemplateView {
while (replyContainer.lastChild) { while (replyContainer.lastChild) {
replyContainer.removeChild(replyContainer.lastChild); replyContainer.removeChild(replyContainer.lastChild);
} }
replyContainer.appendChild(vm.isRedacted? this._renderRedaction(vm) : this._renderReplyPreview(vm)); replyContainer.appendChild(vm.isRedacted? this._renderRedaction(vm) : this._renderReplyPreview(t, vm));
}) })
return replyContainer; return replyContainer;
} }
@ -37,15 +40,46 @@ export class ReplyPreviewView extends TemplateView {
return reply; return reply;
} }
_renderReplyPreview(vm) { _renderReplyPreview(t, vm) {
const reply = this._renderReplyHeader(vm); let reply;
const body = vm.body; switch (vm.shape) {
for (const part of body.parts) { case "image":
reply.appendChild(renderPart(part)); case "video":
reply = this._renderMediaPreview(t, vm);
break;
default:
reply = this._renderPreview(t, vm);
break;
} }
return reply; return reply;
} }
_renderPreview(t, vm) {
const view = this._viewFromShape(vm);
const rendered = view.renderMessageBody(t, vm);
return this._renderReplyHeader(vm, [rendered]);
}
_renderMediaPreview(t, vm) {
const view = this._viewFromShape(vm);
const rendered = view.renderMedia(t, vm);
return this._renderReplyHeader(vm, [rendered]);
}
_viewFromShape(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":
return new TextMessageView(vm);
}
}
_renderReplyHeader(vm, children = []) { _renderReplyHeader(vm, children = []) {
return tag.blockquote( return tag.blockquote(
[ [