keep cache for media for d&rd, fix #281
This commit is contained in:
parent
e40f5e41e5
commit
6a7d389b55
|
@ -17,7 +17,7 @@ import { NotificationService } from '../../services/notification.service';
|
||||||
import { StatusWrapper } from '../../models/common.model';
|
import { StatusWrapper } from '../../models/common.model';
|
||||||
import { AccountInfo } from '../../states/accounts.state';
|
import { AccountInfo } from '../../states/accounts.state';
|
||||||
import { InstancesInfoService } from '../../services/instances-info.service';
|
import { InstancesInfoService } from '../../services/instances-info.service';
|
||||||
import { MediaService } from '../../services/media.service';
|
import { MediaService, MediaWrapper } from '../../services/media.service';
|
||||||
import { AutosuggestSelection, AutosuggestUserActionEnum } from './autosuggest/autosuggest.component';
|
import { AutosuggestSelection, AutosuggestUserActionEnum } from './autosuggest/autosuggest.component';
|
||||||
import { EmojiPickerComponent } from './emoji-picker/emoji-picker.component';
|
import { EmojiPickerComponent } from './emoji-picker/emoji-picker.component';
|
||||||
import { PollEditorComponent } from './poll-editor/poll-editor.component';
|
import { PollEditorComponent } from './poll-editor/poll-editor.component';
|
||||||
|
@ -82,6 +82,12 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.statusLoaded = false;
|
this.statusLoaded = false;
|
||||||
|
|
||||||
|
if(value.status && value.status.media_attachments){
|
||||||
|
for (const m of value.status.media_attachments) {
|
||||||
|
this.mediaService.addExistingMedia(new MediaWrapper(m.id, null, m));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const newLine = String.fromCharCode(13, 10);
|
const newLine = String.fromCharCode(13, 10);
|
||||||
let content = value.status.content;
|
let content = value.status.content;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { NotificationService } from './notification.service';
|
||||||
})
|
})
|
||||||
export class MediaService {
|
export class MediaService {
|
||||||
mediaSubject: BehaviorSubject<MediaWrapper[]> = new BehaviorSubject<MediaWrapper[]>([]);
|
mediaSubject: BehaviorSubject<MediaWrapper[]> = new BehaviorSubject<MediaWrapper[]>([]);
|
||||||
|
fileCache: { [url: string]: File } = {};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly notificationService: NotificationService,
|
private readonly notificationService: NotificationService,
|
||||||
|
@ -36,6 +37,7 @@ export class MediaService {
|
||||||
|
|
||||||
this.mastodonService.uploadMediaAttachment(account, file, null)
|
this.mastodonService.uploadMediaAttachment(account, file, null)
|
||||||
.then((attachment: Attachment) => {
|
.then((attachment: Attachment) => {
|
||||||
|
this.fileCache[attachment.url] = file;
|
||||||
let currentMedias = this.mediaSubject.value;
|
let currentMedias = this.mediaSubject.value;
|
||||||
let currentMedia = currentMedias.filter(x => x.id === uniqueId)[0];
|
let currentMedia = currentMedias.filter(x => x.id === uniqueId)[0];
|
||||||
if (currentMedia) {
|
if (currentMedia) {
|
||||||
|
@ -64,6 +66,15 @@ export class MediaService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
this.mediaSubject.next(medias);
|
||||||
|
}
|
||||||
|
|
||||||
remove(media: MediaWrapper) {
|
remove(media: MediaWrapper) {
|
||||||
let medias = this.mediaSubject.value;
|
let medias = this.mediaSubject.value;
|
||||||
let filteredMedias = medias.filter(x => x.id !== media.id);
|
let filteredMedias = medias.filter(x => x.id !== media.id);
|
||||||
|
@ -84,6 +95,7 @@ export class MediaService {
|
||||||
for (let media of medias) {
|
for (let media of medias) {
|
||||||
this.mastodonService.uploadMediaAttachment(account, media.file, media.description)
|
this.mastodonService.uploadMediaAttachment(account, media.file, media.description)
|
||||||
.then((attachment: Attachment) => {
|
.then((attachment: Attachment) => {
|
||||||
|
this.fileCache[attachment.url] = media.file;
|
||||||
let currentMedias = this.mediaSubject.value;
|
let currentMedias = this.mediaSubject.value;
|
||||||
let currentMedia = currentMedias.filter(x => x.id === media.id)[0];
|
let currentMedia = currentMedias.filter(x => x.id === media.id)[0];
|
||||||
if (currentMedia) {
|
if (currentMedia) {
|
||||||
|
|
Loading…
Reference in New Issue