D&R stop messing with status state, fix #291

This commit is contained in:
Nicolas Constant 2020-05-28 23:56:42 -04:00
parent 8000f51aaa
commit 0ee30eba76
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 36 additions and 18 deletions

View File

@ -41,6 +41,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
faClock = faClock; faClock = faClock;
autoSuggestUserActionsStream = new EventEmitter<AutosuggestUserActionEnum>(); autoSuggestUserActionsStream = new EventEmitter<AutosuggestUserActionEnum>();
private isRedrafting: boolean;
private _title: string; private _title: string;
set title(value: string) { set title(value: string) {
@ -54,7 +55,11 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
private _status: string = ''; private _status: string = '';
@Input('status') @Input('status')
set status(value: string) { set status(value: string) {
this.statusStateService.setStatusContent(value, this.statusReplyingToWrapper); if (this.isRedrafting) {
this.statusStateService.setStatusContent(value, null);
} else {
this.statusStateService.setStatusContent(value, this.statusReplyingToWrapper);
}
this.countStatusChar(value); this.countStatusChar(value);
this.detectAutosuggestion(value); this.detectAutosuggestion(value);
this._status = value; this._status = value;
@ -80,9 +85,10 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
@Input('redraftedStatus') @Input('redraftedStatus')
set redraftedStatus(value: StatusWrapper) { set redraftedStatus(value: StatusWrapper) {
if (value) { if (value) {
this.isRedrafting = true;
this.statusLoaded = false; this.statusLoaded = false;
if(value.status && value.status.media_attachments){ if (value.status && value.status.media_attachments) {
for (const m of value.status.media_attachments) { for (const m of value.status.media_attachments) {
this.mediaService.addExistingMedia(new MediaWrapper(m.id, null, m)); this.mediaService.addExistingMedia(new MediaWrapper(m.id, null, m));
} }
@ -103,7 +109,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
var dom = parser.parseFromString(content, 'text/html') var dom = parser.parseFromString(content, 'text/html')
this.status = dom.body.textContent; this.status = dom.body.textContent;
this.statusStateService.setStatusContent(this.status, this.statusReplyingToWrapper); // this.statusStateService.setStatusContent(this.status, this.statusReplyingToWrapper);
this.setVisibilityFromStatus(value.status); this.setVisibilityFromStatus(value.status);
this.title = value.status.spoiler_text; this.title = value.status.spoiler_text;
@ -193,10 +199,13 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
public viewContainerRef: ViewContainerRef) { public viewContainerRef: ViewContainerRef) {
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts); this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
this.status = this.statusStateService.getStatusContent(this.statusReplyingToWrapper);
} }
ngOnInit() { ngOnInit() {
if (!this.isRedrafting) {
this.status = this.statusStateService.getStatusContent(this.statusReplyingToWrapper);
}
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => { this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
this.accountChanged(accounts); this.accountChanged(accounts);
}); });
@ -209,10 +218,11 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
this.statusReplyingTo = this.statusReplyingToWrapper.status; this.statusReplyingTo = this.statusReplyingToWrapper.status;
} }
let state = this.statusStateService.getStatusContent(this.statusReplyingToWrapper); // let state = this.statusStateService.getStatusContent(this.statusReplyingToWrapper);
if (state && state !== '') { // if (state && state !== '') {
this.status = state; // this.status = state;
} else { // } else {
if(!this.status || this.status === '') {
const uniqueMentions = this.getMentions(this.statusReplyingTo, this.statusReplyingToWrapper.provider); const uniqueMentions = this.getMentions(this.statusReplyingTo, this.statusReplyingToWrapper.provider);
for (const mention of uniqueMentions) { for (const mention of uniqueMentions) {
this.status += `@${mention} `; this.status += `@${mention} `;
@ -233,6 +243,10 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
} }
ngOnDestroy() { ngOnDestroy() {
if(this.isRedrafting){
this.statusStateService.resetStatusContent(null);
}
this.accountSub.unsubscribe(); this.accountSub.unsubscribe();
} }
@ -563,7 +577,11 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
this.scheduledStatusService.statusAdded(acc); this.scheduledStatusService.statusAdded(acc);
} }
this.statusStateService.resetStatusContent(this.statusReplyingToWrapper); if(this.isRedrafting){
this.statusStateService.resetStatusContent(null);
} else {
this.statusStateService.resetStatusContent(this.statusReplyingToWrapper);
}
}) })
.catch((err: HttpErrorResponse) => { .catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err, acc); this.notificationService.notifyHttpError(err, acc);
@ -741,9 +759,9 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
if (isVisible) { if (isVisible) {
setTimeout(() => { setTimeout(() => {
try{ try {
this.footerElement.nativeElement.scrollIntoViewIfNeeded({ behavior: 'instant', block: 'end', inline: 'start' }); this.footerElement.nativeElement.scrollIntoViewIfNeeded({ behavior: 'instant', block: 'end', inline: 'start' });
}catch(err) { } catch (err) {
this.footerElement.nativeElement.scrollIntoView({ behavior: 'instant', block: 'end', inline: 'start' }); this.footerElement.nativeElement.scrollIntoView({ behavior: 'instant', block: 'end', inline: 'start' });
} }
}, 0); }, 0);
@ -850,11 +868,11 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
const mastodonMentionRegex = /<span class="h-card"><a href="https:\/\/([a-zA-Z0-9.]{0,255})\/[a-zA-Z0-9_@/-]{0,255}" class="u-url mention">@<span>([a-zA-Z0-9_-]{0,255})<\/span><\/a><\/span>/gmi; const mastodonMentionRegex = /<span class="h-card"><a href="https:\/\/([a-zA-Z0-9.]{0,255})\/[a-zA-Z0-9_@/-]{0,255}" class="u-url mention">@<span>([a-zA-Z0-9_-]{0,255})<\/span><\/a><\/span>/gmi;
const pleromaMentionRegex = /<span class="h-card"><a data-user="[a-zA-Z0-9]{0,255}" class="u-url mention" href="https:\/\/([a-zA-Z0-9.]{0,255})\/[a-zA-Z0-9_@/-]{0,255}" rel="ugc">@<span>([a-zA-Z0-9_-]{0,255})<\/span><\/a><\/span>/gmi; const pleromaMentionRegex = /<span class="h-card"><a data-user="[a-zA-Z0-9]{0,255}" class="u-url mention" href="https:\/\/([a-zA-Z0-9.]{0,255})\/[a-zA-Z0-9_@/-]{0,255}" rel="ugc">@<span>([a-zA-Z0-9_-]{0,255})<\/span><\/a><\/span>/gmi;
while(data.match(mastodonMentionRegex)){ while (data.match(mastodonMentionRegex)) {
data = data.replace(mastodonMentionRegex, '@$2@$1'); data = data.replace(mastodonMentionRegex, '@$2@$1');
} }
while(data.match(pleromaMentionRegex)){ while (data.match(pleromaMentionRegex)) {
data = data.replace(pleromaMentionRegex, '@$2@$1'); data = data.replace(pleromaMentionRegex, '@$2@$1');
} }