keep attachments on edition, fix #563
This commit is contained in:
parent
314c736cf4
commit
982a670352
|
@ -89,6 +89,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
this.isEditing = true;
|
||||
this.editingStatusId = value.status.id;
|
||||
this.redraftedStatus = value;
|
||||
this.mediaService.loadMedia(value.status.media_attachments);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -629,7 +630,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
let postPromise: Promise<Status>;
|
||||
|
||||
if (this.isEditing) {
|
||||
postPromise = this.mastodonService.editStatus(account, editingStatusId, s, visibility, title, inReplyToId, attachments.map(x => x.id), poll, scheduledAt);
|
||||
postPromise = this.mastodonService.editStatus(account, editingStatusId, s, visibility, title, inReplyToId, attachments, poll, scheduledAt);
|
||||
} else {
|
||||
postPromise = this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, attachments.map(x => x.id), poll, scheduledAt);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<div *ngFor="let m of media" class="media">
|
||||
<div *ngIf="m.attachment === null" class="media__loading" title="{{m.file.name}}">
|
||||
<div *ngIf="m.attachment === null" class="media__loading" title="{{getName(m)}}">
|
||||
<app-waiting-animation class="waiting-icon"></app-waiting-animation>
|
||||
</div>
|
||||
<div *ngIf="m.attachment !== null && m.attachment.type !== 'audio'" class="media__loaded" title="{{m.file.name}}"
|
||||
<div *ngIf="m.attachment !== null && m.attachment.type !== 'audio'" class="media__loaded" title="{{getName(m)}}"
|
||||
(mouseleave)="updateMedia(m)">
|
||||
<div class="media__loaded--migrating" *ngIf="m.isMigrating">
|
||||
<app-waiting-animation class="waiting-icon"></app-waiting-animation>
|
||||
|
|
|
@ -56,4 +56,13 @@ export class MediaComponent implements OnInit, OnDestroy {
|
|||
this.mediaService.update(account, media);
|
||||
return false;
|
||||
}
|
||||
|
||||
getName(media: MediaWrapper): string {
|
||||
if(media && media.file && media.file.name){
|
||||
return media.file.name;
|
||||
}
|
||||
if(media.attachment && media.attachment.description){
|
||||
return media.attachment.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,10 @@ export class AttachementsComponent implements OnInit {
|
|||
|
||||
@Input('attachments')
|
||||
set attachments(value: Attachment[]) {
|
||||
this.imageAttachments = [];
|
||||
this.videoAttachments = [];
|
||||
this.audioAttachments = [];
|
||||
|
||||
this._attachments = value;
|
||||
this.setAttachments(value);
|
||||
}
|
||||
|
|
|
@ -124,10 +124,10 @@ export class MastodonWrapperService {
|
|||
});
|
||||
}
|
||||
|
||||
editStatus(account: AccountInfo, statusId: string, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, mediaIds: string[], poll: PollParameters = null, scheduled_at: string = null): Promise<Status> {
|
||||
editStatus(account: AccountInfo, statusId: string, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, attachements: Attachment[], poll: PollParameters = null, scheduled_at: string = null): Promise<Status> {
|
||||
return this.refreshAccountIfNeeded(account)
|
||||
.then((refreshedAccount: AccountInfo) => {
|
||||
return this.mastodonService.editStatus(refreshedAccount, statusId, status, visibility, spoiler, in_reply_to_id, mediaIds, poll, scheduled_at);
|
||||
return this.mastodonService.editStatus(refreshedAccount, statusId, status, visibility, spoiler, in_reply_to_id, attachements, poll, scheduled_at);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -132,12 +132,13 @@ export class MastodonService {
|
|||
return this.httpClient.post<Status>(url, statusData, { headers: headers }).toPromise();
|
||||
}
|
||||
|
||||
editStatus(account: AccountInfo, statusId: string, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, mediaIds: string[], poll: PollParameters = null, scheduled_at: string = null): Promise<Status> {
|
||||
editStatus(account: AccountInfo, statusId: string, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, attachements: Attachment[], poll: PollParameters = null, scheduled_at: string = null): Promise<Status> {
|
||||
const url = `https://${account.instance}${this.apiRoutes.editStatus.replace('{0}', statusId)}`;
|
||||
|
||||
const statusData = new StatusData();
|
||||
statusData.status = status;
|
||||
statusData.media_ids = mediaIds;
|
||||
statusData.media_ids = attachements.map(x => x.id);
|
||||
statusData.media_attributes = attachements.map(x => new MediaAttributes(x.id, x.description));
|
||||
|
||||
if (poll) {
|
||||
statusData['poll'] = poll;
|
||||
|
@ -643,6 +644,8 @@ class StatusData {
|
|||
status: string;
|
||||
in_reply_to_id: string;
|
||||
media_ids: string[];
|
||||
media_attributes: MediaAttributes[];
|
||||
|
||||
// poll: PollParameters;
|
||||
sensitive: boolean;
|
||||
spoiler_text: string;
|
||||
|
@ -650,6 +653,13 @@ class StatusData {
|
|||
// scheduled_at: string;
|
||||
}
|
||||
|
||||
class MediaAttributes {
|
||||
constructor(
|
||||
public id: string,
|
||||
public description: string){
|
||||
}
|
||||
}
|
||||
|
||||
export class PollParameters {
|
||||
options: string[] = [];
|
||||
expires_in: number;
|
||||
|
|
|
@ -51,26 +51,51 @@ export class MediaService {
|
|||
});
|
||||
}
|
||||
|
||||
loadMedia(attachments: Attachment[]) {
|
||||
const wrappers: MediaWrapper[] = [];
|
||||
|
||||
for (const att of attachments) {
|
||||
const uniqueId = `${att.id}${Math.random()}`;
|
||||
const wrapper = new MediaWrapper(uniqueId, null, att);
|
||||
wrapper.description = att.description;
|
||||
wrapper.isEdited = true;
|
||||
wrappers.push(wrapper);
|
||||
}
|
||||
|
||||
this.mediaSubject.next(wrappers);
|
||||
|
||||
}
|
||||
|
||||
update(account: AccountInfo, media: MediaWrapper): Promise<void> {
|
||||
if (media.attachment.description === media.description) return;
|
||||
|
||||
return this.mastodonService.updateMediaAttachment(account, media.attachment.id, media.description)
|
||||
.then((att: Attachment) => {
|
||||
let medias = this.mediaSubject.value;
|
||||
let updatedMedia = medias.filter(x => x.id === media.id)[0];
|
||||
updatedMedia.attachment.description = att.description;
|
||||
this.mediaSubject.next(medias);
|
||||
})
|
||||
.catch((err) => {
|
||||
this.notificationService.notifyHttpError(err, account);
|
||||
});
|
||||
if (media.isEdited) {
|
||||
media.attachment.description = media.description;
|
||||
|
||||
let medias = this.mediaSubject.value;
|
||||
let updatedMedia = medias.filter(x => x.id === media.id)[0];
|
||||
updatedMedia.attachment.description = media.attachment.description;
|
||||
this.mediaSubject.next(medias);
|
||||
} else {
|
||||
return this.mastodonService.updateMediaAttachment(account, media.attachment.id, media.description)
|
||||
.then((att: Attachment) => {
|
||||
let medias = this.mediaSubject.value;
|
||||
let updatedMedia = medias.filter(x => x.id === media.id)[0];
|
||||
updatedMedia.attachment.description = att.description;
|
||||
this.mediaSubject.next(medias);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn('failing update');
|
||||
this.notificationService.notifyHttpError(err, account);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async retrieveUpToDateMedia(account: AccountInfo): Promise<MediaWrapper[]> {
|
||||
const allMedia = this.mediaSubject.value;
|
||||
let allPromises: Promise<any>[] = [];
|
||||
|
||||
for (const m of allMedia) {
|
||||
|
||||
for (const m of allMedia) {
|
||||
let t = this.update(account, m);
|
||||
allPromises.push(t);
|
||||
}
|
||||
|
@ -80,9 +105,9 @@ export class MediaService {
|
|||
return allMedia;
|
||||
}
|
||||
|
||||
addExistingMedia(media: MediaWrapper){
|
||||
if(!this.fileCache[media.attachment.url]) return;
|
||||
|
||||
addExistingMedia(media: MediaWrapper) {
|
||||
if (!this.fileCache[media.attachment.url]) return;
|
||||
|
||||
media.file = this.fileCache[media.attachment.url];
|
||||
let medias = this.mediaSubject.value;
|
||||
medias.push(media);
|
||||
|
@ -102,11 +127,15 @@ export class MediaService {
|
|||
migrateMedias(account: AccountInfo) {
|
||||
let medias = this.mediaSubject.value;
|
||||
medias.forEach(media => {
|
||||
media.isMigrating = true;
|
||||
if (!media.isEdited) {
|
||||
media.isMigrating = true;
|
||||
}
|
||||
});
|
||||
this.mediaSubject.next(medias);
|
||||
|
||||
for (let media of medias) {
|
||||
if (media.isEdited) continue;
|
||||
|
||||
this.mastodonService.uploadMediaAttachment(account, media.file, media.description)
|
||||
.then((attachment: Attachment) => {
|
||||
this.fileCache[attachment.url] = media.file;
|
||||
|
@ -131,7 +160,7 @@ export class MediaWrapper {
|
|||
public id: string,
|
||||
public file: File,
|
||||
attachment: Attachment) {
|
||||
this.attachment = attachment;
|
||||
this.attachment = attachment;
|
||||
}
|
||||
|
||||
private _attachment: Attachment;
|
||||
|
@ -139,7 +168,7 @@ export class MediaWrapper {
|
|||
return this._attachment;
|
||||
}
|
||||
|
||||
public set attachment(value: Attachment){
|
||||
public set attachment(value: Attachment) {
|
||||
if (value && value.meta && value.meta.audio_encode) {
|
||||
this.audioType = `audio/${value.meta.audio_encode}`;
|
||||
} else if (value && value.pleroma && value.pleroma.mime_type) {
|
||||
|
@ -152,4 +181,6 @@ export class MediaWrapper {
|
|||
public description: string;
|
||||
public isMigrating: boolean;
|
||||
public audioType: string;
|
||||
|
||||
public isEdited: boolean;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue