clear medias after sending status #56
This commit is contained in:
parent
1c7dd94452
commit
0ec97cbf4f
@ -166,7 +166,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||
.then((status: Status) => {
|
||||
return this.sendStatus(acc, this.status, visibility, this.title, status, mediaAttachments);
|
||||
})
|
||||
.then((res: Status) => {
|
||||
.then((res: Status) => {
|
||||
this.title = '';
|
||||
this.status = '';
|
||||
this.onClose.emit();
|
||||
@ -194,7 +194,11 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
if(i === 0){
|
||||
return this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, attachments.map(x => x.id));
|
||||
return this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, attachments.map(x => x.id))
|
||||
.then((status:Status) => {
|
||||
this.mediaService.clearMedia();
|
||||
return status;
|
||||
});
|
||||
} else {
|
||||
return this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, []);
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
|
||||
import { AccountInfo } from '../states/accounts.state';
|
||||
import { ApiRoutes } from './models/api.settings';
|
||||
import { Attachment } from './models/mastodon.interfaces';
|
||||
import { MastodonService } from './mastodon.service';
|
||||
import { NotificationService } from './notification.service';
|
||||
@ -12,47 +10,45 @@ import { NotificationService } from './notification.service';
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MediaService {
|
||||
private apiRoutes = new ApiRoutes();
|
||||
|
||||
export class MediaService {
|
||||
mediaSubject: BehaviorSubject<MediaWrapper[]> = new BehaviorSubject<MediaWrapper[]>([]);
|
||||
|
||||
constructor(
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly mastodonService: MastodonService) { }
|
||||
|
||||
uploadMedia(account: AccountInfo, files: File[]){
|
||||
uploadMedia(account: AccountInfo, files: File[]) {
|
||||
for (let file of files) {
|
||||
this.postMedia(account, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private postMedia(account: AccountInfo, file: File){
|
||||
private postMedia(account: AccountInfo, file: File) {
|
||||
const uniqueId = `${file.name}${file.size}${Math.random()}`;
|
||||
const wrapper = new MediaWrapper(uniqueId, file, null, null);
|
||||
const wrapper = new MediaWrapper(uniqueId, file, null);
|
||||
|
||||
let medias = this.mediaSubject.value;
|
||||
medias.push(wrapper);
|
||||
this.mediaSubject.next(medias);
|
||||
|
||||
this.mastodonService.uploadMediaAttachment(account, file)
|
||||
this.mastodonService.uploadMediaAttachment(account, file)
|
||||
.then((attachment: Attachment) => {
|
||||
let currentMedias = this.mediaSubject.value;
|
||||
let currentMedia = currentMedias.filter(x => x.id === uniqueId)[0];
|
||||
if(currentMedia){
|
||||
if (currentMedia) {
|
||||
currentMedia.attachment = attachment;
|
||||
this.mediaSubject.next(currentMedias);
|
||||
}
|
||||
})
|
||||
.catch((err)=>{
|
||||
.catch((err) => {
|
||||
this.remove(wrapper);
|
||||
this.notificationService.notifyHttpError(err);
|
||||
});
|
||||
}
|
||||
|
||||
update( account: AccountInfo, media: MediaWrapper): any {
|
||||
if(media.attachment.description === media.description) return;
|
||||
|
||||
update(account: AccountInfo, media: MediaWrapper): any {
|
||||
if (media.attachment.description === media.description) return;
|
||||
|
||||
this.mastodonService.updateMediaAttachment(account, media.attachment.id, media.description)
|
||||
.then((att: Attachment) => {
|
||||
let medias = this.mediaSubject.value;
|
||||
@ -70,12 +66,20 @@ export class MediaService {
|
||||
let filteredMedias = medias.filter(x => x.id !== media.id);
|
||||
this.mediaSubject.next(filteredMedias);
|
||||
}
|
||||
|
||||
clearMedia() {
|
||||
this.mediaSubject.next([]);
|
||||
}
|
||||
|
||||
// migrate
|
||||
}
|
||||
|
||||
export class MediaWrapper {
|
||||
constructor(
|
||||
public id: string,
|
||||
public file: File,
|
||||
public attachment: Attachment,
|
||||
public description: string) {}
|
||||
public file: File,
|
||||
public attachment: Attachment) { }
|
||||
|
||||
public description: string;
|
||||
public isMigrating: boolean;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body ondragstart="return false;" ondrop="return false;">
|
||||
<app-root>
|
||||
<div class="lds-ripple">
|
||||
<div></div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user