1
0
mirror of https://github.com/NicolasConstant/sengi synced 2024-12-22 21:58:59 +01:00

ensure all alt media are updated, fix #430

This commit is contained in:
Nicolas Constant 2023-04-23 18:27:47 -04:00
parent 22cad9e22d
commit eac8c6120a
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 20 additions and 5 deletions

View File

@ -537,7 +537,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
return false; return false;
} }
onSubmit(): boolean { async onSubmit(): Promise<boolean> {
if (this.isSending || this.mentionTooFarAwayError) return false; if (this.isSending || this.mentionTooFarAwayError) return false;
this.isSending = true; this.isSending = true;
@ -558,9 +558,10 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
break; break;
} }
const mediaAttachments = this.mediaService.mediaSubject.value.map(x => x.attachment);
const acc = this.toolsService.getSelectedAccounts()[0]; const acc = this.toolsService.getSelectedAccounts()[0];
const mediaAttachments = (await this.mediaService.retrieveUpToDateMedia(acc)).map(x => x.attachment);
let usableStatus: Promise<Status>; let usableStatus: Promise<Status>;
if (this.statusReplyingToWrapper) { if (this.statusReplyingToWrapper) {
usableStatus = this.toolsService.getStatusUsableByAccount(acc, this.statusReplyingToWrapper); usableStatus = this.toolsService.getStatusUsableByAccount(acc, this.statusReplyingToWrapper);

View File

@ -51,10 +51,10 @@ export class MediaService {
}); });
} }
update(account: AccountInfo, media: MediaWrapper) { update(account: AccountInfo, media: MediaWrapper): Promise<void> {
if (media.attachment.description === media.description) return; if (media.attachment.description === media.description) return;
this.mastodonService.updateMediaAttachment(account, media.attachment.id, media.description) return this.mastodonService.updateMediaAttachment(account, media.attachment.id, media.description)
.then((att: Attachment) => { .then((att: Attachment) => {
let medias = this.mediaSubject.value; let medias = this.mediaSubject.value;
let updatedMedia = medias.filter(x => x.id === media.id)[0]; let updatedMedia = medias.filter(x => x.id === media.id)[0];
@ -66,6 +66,20 @@ export class MediaService {
}); });
} }
async retrieveUpToDateMedia(account: AccountInfo): Promise<MediaWrapper[]> {
const allMedia = this.mediaSubject.value;
let allPromises: Promise<any>[] = [];
for (const m of allMedia) {
let t = this.update(account, m);
allPromises.push(t);
}
await Promise.all(allPromises);
return allMedia;
}
addExistingMedia(media: MediaWrapper){ addExistingMedia(media: MediaWrapper){
if(!this.fileCache[media.attachment.url]) return; if(!this.fileCache[media.attachment.url]) return;