Bugfix: Message attachments should be observable or else KnockoutJS is not updating

This commit is contained in:
djmaze 2020-09-17 22:14:51 +02:00
parent 0f56c7d28f
commit 9241726ffe
2 changed files with 8 additions and 8 deletions

View file

@ -74,7 +74,7 @@ class MessageModel extends AbstractModel {
this.isHtml = ko.observable(false);
this.hasImages = ko.observable(false);
this.attachments = new AttachmentCollectionModel;
this.attachments = ko.observable(new AttachmentCollectionModel);
this.isPgpSigned = ko.observable(false);
this.isPgpEncrypted = ko.observable(false);
@ -159,7 +159,7 @@ class MessageModel extends AbstractModel {
this.isHtml(false);
this.hasImages(false);
this.attachments = new AttachmentCollectionModel;
this.attachments(new AttachmentCollectionModel);
this.isPgpSigned(false);
this.isPgpEncrypted(false);
@ -300,7 +300,7 @@ class MessageModel extends AbstractModel {
this.attachmentsSpecData(isArray(json.AttachmentsSpecData) ? json.AttachmentsSpecData : []);
this.foundedCIDs = isArray(json.FoundedCIDs) ? json.FoundedCIDs : [];
this.attachments = AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundedCIDs);
this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundedCIDs));
this.readReceipt(json.ReadReceipt || '');
@ -657,7 +657,7 @@ class MessageModel extends AbstractModel {
showInternalImages() {
const body = this.body;
if (body && !body.rlInitInternalImages) {
const findAttachmentByCid = cid => this.attachments.findByCid(cid);
const findAttachmentByCid = cid => this.attachments().findByCid(cid);
body.rlInitInternalImages = true;
@ -669,7 +669,7 @@ class MessageModel extends AbstractModel {
el.src = attachment.linkPreview();
}
} else if (data.xSrcLocation) {
const attachment = this.attachments.find(item => data.xSrcLocation === item.contentLocation)
const attachment = this.attachments().find(item => data.xSrcLocation === item.contentLocation)
|| findAttachmentByCid(data.xSrcLocation);
if (attachment && attachment.download) {
el.loading = 'lazy';

View file

@ -341,9 +341,9 @@
  
<span class="i18n text" data-i18n="MESSAGE/BUTTON_NOTIFY_READ_RECEIPT"></span>
</div>
<div class="attachmentsPlace" data-bind="visible: message() && message().attachments.hasVisible(),
<div class="attachmentsPlace" data-bind="visible: message() && message().attachments().hasVisible(),
css: {'selection-mode' : showAttachmnetControls, 'unselectedAttachmentsError': highlightUnselectedAttachments}">
<ul class="attachmentList" data-bind="foreach: message() ? message().attachments : []">
<ul class="attachmentList" data-bind="foreach: message() ? message().attachments() : []">
<li class="attachmentItem clearfix" draggable="true" data-tooltip-join="top"
data-bind="visible: !isLinked, event: { 'dragstart': eventDragStart }, attr: { 'title': fileName }, css: {'checked': checked}">
<div class="attachmentIconParent pull-left" data-bind="css: { 'hasPreview': hasPreview(), 'hasPreplay': hasPreplay(), 'isImage': isImage() }">
@ -393,7 +393,7 @@
</div>
<div class="attachmentsControls"
data-bind="visible: showAttachmnetControls() && message() && message().attachments.hasVisible()">
data-bind="visible: showAttachmnetControls() && message() && message().attachments().hasVisible()">
<span data-bind="visible: downloadAsZipAllowed">
<i class="icon-remove iconcolor-red" data-bind="visible: downloadAsZipError"></i>