mirror of
https://github.com/NicolasConstant/sengi
synced 2025-02-08 16:08:40 +01:00
better handling of redraft
This commit is contained in:
parent
9c8a1a829f
commit
f3fe5f900b
@ -41,6 +41,29 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||
return this._status;
|
||||
}
|
||||
|
||||
@Input('redraftedStatus')
|
||||
set redraftedStatus(value: StatusWrapper) {
|
||||
if (value) {
|
||||
this.status = value.status.content.replace(/<[^>]*>/g, '');
|
||||
this.setVisibilityFromStatus(value.status);
|
||||
this.title = value.status.spoiler_text;
|
||||
|
||||
if (value.status.in_reply_to_id) {
|
||||
this.isSending = true;
|
||||
this.mastodonService.getStatus(value.provider, value.status.in_reply_to_id)
|
||||
.then((status: Status) => {
|
||||
this.statusReplyingTo = status;
|
||||
})
|
||||
.catch(err => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
})
|
||||
.then(() => {
|
||||
this.isSending = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private maxCharLength: number;
|
||||
charCountLeft: number;
|
||||
postCounts: number = 1;
|
||||
@ -112,20 +135,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||
this.status += `@${mention} `;
|
||||
}
|
||||
|
||||
switch (this.statusReplyingTo.visibility) {
|
||||
case 'unlisted':
|
||||
this.setVisibility(VisibilityEnum.Unlisted);
|
||||
break;
|
||||
case 'public':
|
||||
this.setVisibility(VisibilityEnum.Public);
|
||||
break;
|
||||
case 'private':
|
||||
this.setVisibility(VisibilityEnum.Private);
|
||||
break;
|
||||
case 'direct':
|
||||
this.setVisibility(VisibilityEnum.Direct);
|
||||
break;
|
||||
}
|
||||
this.setVisibilityFromStatus(this.statusReplyingTo);
|
||||
|
||||
this.title = this.statusReplyingTo.spoiler_text;
|
||||
} else if (this.replyingUserHandle) {
|
||||
@ -196,6 +206,23 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
private setVisibilityFromStatus(status: Status) {
|
||||
switch (status.visibility) {
|
||||
case 'unlisted':
|
||||
this.setVisibility(VisibilityEnum.Unlisted);
|
||||
break;
|
||||
case 'public':
|
||||
this.setVisibility(VisibilityEnum.Public);
|
||||
break;
|
||||
case 'private':
|
||||
this.setVisibility(VisibilityEnum.Private);
|
||||
break;
|
||||
case 'direct':
|
||||
this.setVisibility(VisibilityEnum.Direct);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private setVisibility(defaultPrivacy: VisibilityEnum) {
|
||||
switch (defaultPrivacy) {
|
||||
case VisibilityEnum.Public:
|
||||
|
@ -4,5 +4,5 @@
|
||||
<app-create-status (onClose)="closeColumn()"
|
||||
[isDirectMention]="isDirectMention"
|
||||
[replyingUserHandle]="userHandle"
|
||||
[status]="status"></app-create-status>
|
||||
[redraftedStatus]="redraftedStatus"></app-create-status>
|
||||
</div>
|
@ -1,6 +1,7 @@
|
||||
import { Component, OnInit, Input } from '@angular/core';
|
||||
|
||||
import { NavigationService } from '../../../services/navigation.service';
|
||||
import { StatusWrapper } from '../../../models/common.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-add-new-status',
|
||||
@ -11,7 +12,7 @@ export class AddNewStatusComponent implements OnInit {
|
||||
|
||||
@Input() isDirectMention: boolean;
|
||||
@Input() userHandle: string;
|
||||
@Input() status: string;
|
||||
@Input() redraftedStatus: StatusWrapper;
|
||||
|
||||
constructor(private readonly navigationService: NavigationService) {
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
<app-add-new-status *ngIf="openPanel === 'createNewStatus'"
|
||||
[isDirectMention]="isDirectMention"
|
||||
[userHandle]="userHandle"
|
||||
[status]="statusContent"></app-add-new-status>
|
||||
[redraftedStatus]="redraftedStatus"></app-add-new-status>
|
||||
<app-add-new-account *ngIf="openPanel === 'addNewAccount'"></app-add-new-account>
|
||||
<app-search *ngIf="openPanel === 'search'"
|
||||
(browseAccountEvent)="browseAccount($event)"
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { faTimes } from "@fortawesome/free-solid-svg-icons";
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
import { NavigationService, LeftPanelType, OpenLeftPanelEvent, LeftPanelAction } from '../../services/navigation.service';
|
||||
import { AccountWrapper } from '../../models/account.models';
|
||||
import { OpenThreadEvent } from '../../services/tools.service';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { StatusWrapper } from '../../models/common.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-floating-column',
|
||||
@ -23,7 +24,7 @@ export class FloatingColumnComponent implements OnInit, OnDestroy {
|
||||
|
||||
isDirectMention: boolean;
|
||||
userHandle: string;
|
||||
statusContent: string;
|
||||
redraftedStatus: StatusWrapper;
|
||||
|
||||
openPanel: string = '';
|
||||
|
||||
@ -53,7 +54,7 @@ export class FloatingColumnComponent implements OnInit, OnDestroy {
|
||||
} else {
|
||||
this.isDirectMention = event.action === LeftPanelAction.DM;
|
||||
this.userHandle = event.userHandle;
|
||||
this.statusContent = event.statusContent;
|
||||
this.redraftedStatus = event.status;
|
||||
this.openPanel = 'createNewStatus';
|
||||
}
|
||||
break;
|
||||
|
@ -406,7 +406,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||
})
|
||||
.then(() => {
|
||||
if (redraft) {
|
||||
this.navigationService.redraft(this.displayedStatus.content)
|
||||
this.navigationService.redraft(this.statusWrapper)
|
||||
}
|
||||
|
||||
const deletedStatus = new StatusWrapper(this.displayedStatus, selectedAccount);
|
||||
|
@ -108,6 +108,12 @@ export class MastodonService {
|
||||
return this.httpClient.post<Status>(url, statusData, { headers: headers }).toPromise();
|
||||
}
|
||||
|
||||
getStatus(account: AccountInfo, statusId: string): Promise<Status> {
|
||||
const route = `https://${account.instance}${this.apiRoutes.getStatus.replace('{0}', statusId)}`;
|
||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.get<Status>(route, { headers: headers }).toPromise()
|
||||
}
|
||||
|
||||
search(account: AccountInfo, query: string, resolve: boolean = false): Promise<Results> {
|
||||
if (query[0] === '#') query = query.substr(1);
|
||||
const route = `https://${account.instance}${this.apiRoutes.search}?q=${query}&resolve=${resolve}`;
|
||||
|
@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
|
||||
import { AccountWrapper } from '../models/account.models';
|
||||
import { OpenMediaEvent } from '../models/common.model';
|
||||
import { OpenMediaEvent, StatusWrapper } from '../models/common.model';
|
||||
|
||||
@Injectable()
|
||||
export class NavigationService {
|
||||
@ -36,8 +36,8 @@ export class NavigationService {
|
||||
this.activatedPanelSubject.next(newEvent);
|
||||
}
|
||||
|
||||
redraft(statusContent: string){
|
||||
const newEvent = new OpenLeftPanelEvent(LeftPanelType.CreateNewStatus, LeftPanelAction.Redraft, null, statusContent.replace(/<[^>]*>/g, ''));
|
||||
redraft(status: StatusWrapper){
|
||||
const newEvent = new OpenLeftPanelEvent(LeftPanelType.CreateNewStatus, LeftPanelAction.Redraft, null, status);// statusContent.replace(/<[^>]*>/g, ''));
|
||||
this.activatedPanelSubject.next(newEvent);
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ export class OpenLeftPanelEvent {
|
||||
public type: LeftPanelType,
|
||||
public action: LeftPanelAction = LeftPanelAction.None,
|
||||
public userHandle: string = null,
|
||||
public statusContent: string = null) {
|
||||
public status: StatusWrapper = null) {
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user