Integrate into update mechanism

This commit is contained in:
RMidhunSuresh 2021-12-15 17:46:14 +05:30
parent aa3bb9c6ef
commit 54004eef4d
5 changed files with 18 additions and 24 deletions

View file

@ -150,7 +150,7 @@ export class TilesCollection extends BaseObservableList {
const tileIdx = this._findTileIdx(entry); const tileIdx = this._findTileIdx(entry);
const tile = this._findTileAtIdx(entry, tileIdx); const tile = this._findTileAtIdx(entry, tileIdx);
if (tile) { if (tile) {
const action = tile.updateEntry(entry, params); const action = tile.updateEntry(entry, params, this._tileCreator);
if (action.shouldReplace) { if (action.shouldReplace) {
const newTile = this._tileCreator(entry); const newTile = this._tileCreator(entry);
if (newTile) { if (newTile) {

View file

@ -102,8 +102,8 @@ export class BaseMessageTile extends SimpleTile {
} }
} }
updateEntry(entry, param) { updateEntry(entry, param, tileCreator) {
const action = super.updateEntry(entry, param); const action = super.updateEntry(entry, param, tileCreator);
if (action.shouldUpdate) { if (action.shouldUpdate) {
this._updateReactions(); this._updateReactions();
} }

View file

@ -52,6 +52,10 @@ export class SimpleTile extends ViewModel {
return this._entry.isPending && this._entry.pendingEvent.status !== SendStatus.Sent; return this._entry.isPending && this._entry.pendingEvent.status !== SendStatus.Sent;
} }
get isRedacted() {
return this._entry.isRedacted;
}
get canAbortSending() { get canAbortSending() {
return this._entry.isPending && return this._entry.isPending &&
!this._entry.pendingEvent.hasStartedSending; !this._entry.pendingEvent.hasStartedSending;
@ -92,7 +96,15 @@ export class SimpleTile extends ViewModel {
} }
// update received for already included (falls within sort keys) entry // update received for already included (falls within sort keys) entry
updateEntry(entry, param) { updateEntry(entry, param, tileCreator) {
const replyEntry = param?.reply ?? entry.contextEntry;
if (replyEntry) {
// this is an update to contextEntry used for replyPreview
const action = this._replyTextTile?.updateEntry(replyEntry);
if (action?.shouldReplace) {
this._replyTextTile = tileCreator(replyEntry);
}
}
const renderedAsRedacted = this.shape === "redacted"; const renderedAsRedacted = this.shape === "redacted";
if (!entry.isGap && entry.isRedacted !== renderedAsRedacted) { if (!entry.isGap && entry.isRedacted !== renderedAsRedacted) {
// recreate the tile if the entry becomes redacted // recreate the tile if the entry becomes redacted

View file

@ -73,27 +73,9 @@ export class TextTile extends BaseTextTile {
if (!this._replyTextTile) { if (!this._replyTextTile) {
const entry = this._entry.contextEntry; const entry = this._entry.contextEntry;
if (entry) { if (entry) {
this._replyTextTile = new ReplyPreviewTile(this.childOptions({entry, roomVM: this._roomVM, timeline: this._timeline})); this._replyTextTile = new TextTile(this.childOptions({entry, roomVM: this._roomVM, timeline: this._timeline}));
} }
} }
return this._replyTextTile; return this._replyTextTile;
} }
} }
class ReplyPreviewTile extends TextTile {
constructor(options) {
super(options);
}
get isRedacted() {
return this._entry.isRedacted;
}
get decryptionError() {
return this._entry.decryptionError;
}
get hasError() {
return this.isRedacted || !!this.decryptionError;
}
}

View file

@ -26,7 +26,7 @@ export class ReplyPreviewView extends TemplateView {
while (replyContainer.lastChild) { while (replyContainer.lastChild) {
replyContainer.removeChild(replyContainer.lastChild); replyContainer.removeChild(replyContainer.lastChild);
} }
replyContainer.appendChild(vm.hasError? this._renderError(vm) : this._renderReplyPreview(vm)); replyContainer.appendChild(vm.isRedacted? this._renderError(vm) : this._renderReplyPreview(vm));
}) })
return replyContainer; return replyContainer;
} }