Merge pull request #516 from NicolasConstant/topic_edit-status_enhancements
Topic edit status enhancements
This commit is contained in:
commit
54d4b300f4
|
@ -173,7 +173,7 @@ const routes: Routes = [
|
|||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
PickerModule,
|
||||
OwlDateTimeModule,
|
||||
OwlDateTimeModule,
|
||||
OwlNativeDateTimeModule,
|
||||
OverlayModule,
|
||||
RouterModule.forRoot(routes),
|
||||
|
|
|
@ -83,12 +83,21 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
return s;
|
||||
}
|
||||
|
||||
@Input('statusToEdit')
|
||||
set statusToEdit(value: StatusWrapper) {
|
||||
if (value) {
|
||||
this.isEditing = true;
|
||||
this.editingStatusId = value.status.id;
|
||||
this.redraftedStatus = value;
|
||||
}
|
||||
}
|
||||
|
||||
@Input('redraftedStatus')
|
||||
set redraftedStatus(value: StatusWrapper) {
|
||||
if (value) {
|
||||
this.isRedrafting = true;
|
||||
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));
|
||||
|
@ -141,6 +150,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
autosuggestData: string = null;
|
||||
instanceSupportsPoll = true;
|
||||
instanceSupportsScheduling = true;
|
||||
isEditing: boolean;
|
||||
editingStatusId: string;
|
||||
private statusLoaded: boolean;
|
||||
private hasSuggestions: boolean;
|
||||
|
||||
|
@ -198,7 +209,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
private readonly instancesInfoService: InstancesInfoService,
|
||||
private readonly mediaService: MediaService,
|
||||
private readonly overlay: Overlay,
|
||||
public viewContainerRef: ViewContainerRef) {
|
||||
public viewContainerRef: ViewContainerRef,
|
||||
private readonly statusesStateService: StatusesStateService) {
|
||||
|
||||
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
|
||||
}
|
||||
|
@ -436,7 +448,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
private setVisibility(defaultPrivacy: VisibilityEnum) {
|
||||
if(this.selectedPrivacySetByRedraft) return;
|
||||
if (this.selectedPrivacySetByRedraft) return;
|
||||
|
||||
switch (defaultPrivacy) {
|
||||
case VisibilityEnum.Public:
|
||||
|
@ -494,14 +506,14 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
|
||||
private getMentions(status: Status): string[] {
|
||||
let acct = status.account.acct;
|
||||
if(!acct.includes('@')) {
|
||||
if (!acct.includes('@')) {
|
||||
acct += `@${status.account.url.replace('https://', '').split('/')[0]}`
|
||||
}
|
||||
|
||||
const mentions = [acct];
|
||||
status.mentions.forEach(m => {
|
||||
let mentionAcct = m.acct;
|
||||
if(!mentionAcct.includes('@')){
|
||||
if (!mentionAcct.includes('@')) {
|
||||
mentionAcct += `@${m.url.replace('https://', '').split('/')[0]}`;
|
||||
}
|
||||
mentions.push(mentionAcct);
|
||||
|
@ -572,7 +584,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
|
||||
usableStatus
|
||||
.then((status: Status) => {
|
||||
return this.sendStatus(acc, this.status, visibility, this.title, status, mediaAttachments, poll, scheduledTime);
|
||||
return this.sendStatus(acc, this.status, visibility, this.title, status, mediaAttachments, poll, scheduledTime, this.editingStatusId);
|
||||
})
|
||||
.then((res: Status) => {
|
||||
this.title = '';
|
||||
|
@ -599,7 +611,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
return false;
|
||||
}
|
||||
|
||||
private sendStatus(account: AccountInfo, status: string, visibility: VisibilityEnum, title: string, previousStatus: Status, attachments: Attachment[], poll: PollParameters, scheduledAt: string): Promise<Status> {
|
||||
private sendStatus(account: AccountInfo, status: string, visibility: VisibilityEnum, title: string, previousStatus: Status, attachments: Attachment[], poll: PollParameters, scheduledAt: string, editingStatusId: string): Promise<Status> {
|
||||
let parsedStatus = this.parseStatus(status);
|
||||
let resultPromise = Promise.resolve(previousStatus);
|
||||
|
||||
|
@ -613,13 +625,25 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
if (i === 0) {
|
||||
return this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, attachments.map(x => x.id), poll, scheduledAt)
|
||||
let postPromise: Promise<Status>;
|
||||
|
||||
if (this.isEditing) {
|
||||
postPromise = this.mastodonService.editStatus(account, editingStatusId, s, visibility, title, inReplyToId, attachments.map(x => x.id), poll, scheduledAt);
|
||||
} else {
|
||||
postPromise = this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, attachments.map(x => x.id), poll, scheduledAt);
|
||||
}
|
||||
|
||||
return postPromise
|
||||
.then((status: Status) => {
|
||||
this.mediaService.clearMedia();
|
||||
return status;
|
||||
});
|
||||
} else {
|
||||
return this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, [], null, scheduledAt);
|
||||
if (this.isEditing) {
|
||||
return this.mastodonService.editStatus(account, editingStatusId, s, visibility, title, inReplyToId, [], null, scheduledAt);
|
||||
} else {
|
||||
return this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, [], null, scheduledAt);
|
||||
}
|
||||
}
|
||||
})
|
||||
.then((status: Status) => {
|
||||
|
@ -628,6 +652,16 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
this.notificationService.newStatusPosted(this.statusReplyingToWrapper.status.id, new StatusWrapper(cwPolicy.status, account, cwPolicy.applyCw, cwPolicy.hide));
|
||||
}
|
||||
|
||||
return status;
|
||||
})
|
||||
.then((status: Status) => {
|
||||
if (this.isEditing) {
|
||||
let cwPolicy = this.toolsService.checkContentWarning(status);
|
||||
let statusWrapper = new StatusWrapper(status, account, cwPolicy.applyCw, cwPolicy.hide);
|
||||
|
||||
this.statusesStateService.statusEditedStatusChanged(status.url, account.id, statusWrapper);
|
||||
}
|
||||
|
||||
return status;
|
||||
});
|
||||
}
|
||||
|
@ -636,8 +670,6 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
private parseStatus(status: string): string[] {
|
||||
//console.error(status.toString());
|
||||
|
||||
let mentionExtraChars = this.getMentionExtraChars(status);
|
||||
let urlExtraChar = this.getLinksExtraChars(status);
|
||||
let trucatedStatus = `${status}`;
|
||||
|
@ -654,8 +686,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
|
||||
while (trucatedStatus.length > currentMaxCharLength) {
|
||||
const nextIndex = trucatedStatus.lastIndexOf(' ', maxChars);
|
||||
|
||||
if(nextIndex === -1){
|
||||
|
||||
if (nextIndex === -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -706,8 +738,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
suggestionSelected(selection: AutosuggestSelection) {
|
||||
if (this.status.includes(selection.pattern)) {
|
||||
this.status = this.replacePatternWithAutosuggest(this.status, selection.pattern, selection.autosuggest);
|
||||
|
||||
let cleanStatus = this.status.replace(/\r?\n/g, ' ');
|
||||
|
||||
let cleanStatus = this.status.replace(/\r?\n/g, ' ');
|
||||
let newCaretPosition = cleanStatus.indexOf(`${selection.autosuggest}`) + selection.autosuggest.length;
|
||||
if (newCaretPosition > cleanStatus.length) newCaretPosition = cleanStatus.length;
|
||||
|
||||
|
@ -756,7 +788,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
w++;
|
||||
result += `${word}`;
|
||||
|
||||
if(w < wordCount || i === nberLines){
|
||||
if (w < wordCount || i === nberLines) {
|
||||
result += ' ';
|
||||
}
|
||||
});
|
||||
|
@ -768,7 +800,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
result = result.replace(' ', ' ');
|
||||
|
||||
let endRegex = new RegExp(`${autosuggest} $`, 'i');
|
||||
if(!result.match(endRegex)){
|
||||
if (!result.match(endRegex)) {
|
||||
result = result.substring(0, result.length - 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<div class=" new-message-body flexcroll">
|
||||
<app-create-status (onClose)="closeColumn()" [isDirectMention]="isDirectMention"
|
||||
[replyingUserHandle]="userHandle" [redraftedStatus]="redraftedStatus"></app-create-status>
|
||||
|
||||
[replyingUserHandle]="userHandle" [statusToEdit]="statusToEdit" [redraftedStatus]="redraftedStatus"></app-create-status>
|
||||
</div>
|
||||
</div>
|
|
@ -13,6 +13,7 @@ export class AddNewStatusComponent implements OnInit {
|
|||
@Input() isDirectMention: boolean;
|
||||
@Input() userHandle: string;
|
||||
@Input() redraftedStatus: StatusWrapper;
|
||||
@Input() statusToEdit: StatusWrapper;
|
||||
|
||||
constructor(private readonly navigationService: NavigationService) {
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<div class="floating-column">
|
||||
<div class="floating-column__inner">
|
||||
<div class="sliding-column" [class.sliding-column__right-display]="overlayActive">
|
||||
<app-stream-overlay class="stream-overlay" *ngIf="overlayActive"
|
||||
<app-stream-overlay class="stream-overlay" *ngIf="overlayActive"
|
||||
(closeOverlay)="closeOverlay()"
|
||||
[browseAccountData]="overlayAccountToBrowse"
|
||||
[browseAccountData]="overlayAccountToBrowse"
|
||||
[browseHashtagData]="overlayHashtagToBrowse"
|
||||
[browseThreadData]="overlayThreadToBrowse"></app-stream-overlay>
|
||||
|
||||
|
@ -15,15 +15,17 @@
|
|||
</div>
|
||||
|
||||
<app-manage-account *ngIf="openPanel === 'manageAccount'" [account]="userAccountUsed"
|
||||
(browseAccountEvent)="browseAccount($event)"
|
||||
(browseAccountEvent)="browseAccount($event)"
|
||||
(browseHashtagEvent)="browseHashtag($event)"
|
||||
(browseThreadEvent)="browseThread($event)"></app-manage-account>
|
||||
<app-add-new-status *ngIf="openPanel === 'createNewStatus'" [isDirectMention]="isDirectMention"
|
||||
[userHandle]="userHandle" [redraftedStatus]="redraftedStatus"></app-add-new-status>
|
||||
[userHandle]="userHandle"
|
||||
[redraftedStatus]="redraftedStatus"
|
||||
[statusToEdit]="statusToEdit"></app-add-new-status>
|
||||
<app-add-new-account *ngIf="openPanel === 'addNewAccount'"></app-add-new-account>
|
||||
<app-search *ngIf="openPanel === 'search'"
|
||||
<app-search *ngIf="openPanel === 'search'"
|
||||
(browseAccountEvent)="browseAccount($event)"
|
||||
(browseHashtagEvent)="browseHashtag($event)"
|
||||
(browseHashtagEvent)="browseHashtag($event)"
|
||||
(browseThreadEvent)="browseThread($event)">
|
||||
</app-search>
|
||||
<app-settings *ngIf="openPanel === 'settings'"></app-settings>
|
||||
|
|
|
@ -25,6 +25,7 @@ export class FloatingColumnComponent implements OnInit, OnDestroy {
|
|||
isDirectMention: boolean;
|
||||
userHandle: string;
|
||||
redraftedStatus: StatusWrapper;
|
||||
statusToEdit: StatusWrapper;
|
||||
|
||||
openPanel: string = '';
|
||||
|
||||
|
@ -49,12 +50,21 @@ export class FloatingColumnComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
break;
|
||||
case LeftPanelType.CreateNewStatus:
|
||||
case LeftPanelType.EditStatus:
|
||||
if (this.openPanel === 'createNewStatus' && !event.userHandle) {
|
||||
this.closePanel();
|
||||
} else {
|
||||
this.isDirectMention = event.action === LeftPanelAction.DM;
|
||||
this.userHandle = event.userHandle;
|
||||
this.redraftedStatus = event.status;
|
||||
|
||||
if(event.type === LeftPanelType.CreateNewStatus){
|
||||
this.redraftedStatus = event.status;
|
||||
this.statusToEdit = null;
|
||||
} else {
|
||||
this.redraftedStatus = null;
|
||||
this.statusToEdit = event.status;
|
||||
}
|
||||
|
||||
this.openPanel = 'createNewStatus';
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<a href class="context-menu-link" (click)="onContextMenu($event)"
|
||||
<a href class="context-menu-link" (click)="onContextMenu($event)"
|
||||
[class.context-menu-link__status]="statusWrapper"
|
||||
[class.context-menu-link__profile]="displayedAccount"
|
||||
title="More">
|
||||
|
@ -40,6 +40,9 @@
|
|||
<ng-template contextMenuItem (execute)="unpinFromProfile()" *ngIf="statusWrapper && isOwnerSelected && displayedStatus.pinned && displayedStatus.visibility === 'public'">
|
||||
Unpin from profile
|
||||
</ng-template>
|
||||
<ng-template contextMenuItem (execute)="edit()" *ngIf="statusWrapper && isOwnerSelected && isEditingAvailable">
|
||||
Edit
|
||||
</ng-template>
|
||||
<ng-template contextMenuItem (execute)="delete(false)" *ngIf="statusWrapper && isOwnerSelected">
|
||||
Delete
|
||||
</ng-template>
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Observable, Subscription } from 'rxjs';
|
|||
import { Store } from '@ngxs/store';
|
||||
|
||||
import { Status, Account, Results } from '../../../../../services/models/mastodon.interfaces';
|
||||
import { ToolsService, OpenThreadEvent } from '../../../../../services/tools.service';
|
||||
import { ToolsService, OpenThreadEvent, InstanceInfo } from '../../../../../services/tools.service';
|
||||
import { StatusWrapper } from '../../../../../models/common.model';
|
||||
import { NavigationService } from '../../../../../services/navigation.service';
|
||||
import { AccountInfo } from '../../../../../states/accounts.state';
|
||||
|
@ -27,6 +27,8 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
|
|||
username: string;
|
||||
isOwnerSelected: boolean;
|
||||
|
||||
isEditingAvailable: boolean;
|
||||
|
||||
@Input() statusWrapper: StatusWrapper;
|
||||
@Input() displayedAccount: Account;
|
||||
|
||||
|
@ -78,6 +80,14 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
|
|||
|
||||
this.isOwnerSelected = selectedAccount.username.toLowerCase() === this.displayedStatus.account.username.toLowerCase()
|
||||
&& selectedAccount.instance.toLowerCase() === this.displayedStatus.account.url.replace('https://', '').split('/')[0].toLowerCase();
|
||||
|
||||
this.toolsService.getInstanceInfo(selectedAccount).then((instanceInfo: InstanceInfo) => {
|
||||
if (instanceInfo.major >= 4) {
|
||||
this.isEditingAvailable = true;
|
||||
} else {
|
||||
this.isEditingAvailable = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -282,6 +292,18 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
|
|||
return false;
|
||||
}
|
||||
|
||||
edit(): boolean {
|
||||
const selectedAccount = this.toolsService.getSelectedAccounts()[0];
|
||||
this.getStatus(selectedAccount)
|
||||
.then(() => {
|
||||
this.navigationService.edit(this.statusWrapper);
|
||||
})
|
||||
.catch(err => {
|
||||
this.notificationService.notifyHttpError(err, selectedAccount);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
private getStatus(account: AccountInfo): Promise<Status> {
|
||||
let statusPromise: Promise<Status> = Promise.resolve(this.statusWrapper.status);
|
||||
|
||||
|
|
|
@ -85,6 +85,9 @@
|
|||
<div class="status__labels--label status__labels--remote" title="this status isn't federated with this instance" *ngIf="isRemote">
|
||||
remote
|
||||
</div>
|
||||
<div class="status__labels--label status__labels--edited" title="this status was edited" *ngIf="statusWrapper.status.edited_at">
|
||||
edited
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
@ -105,6 +105,17 @@
|
|||
background-color: rgb(33, 69, 136);
|
||||
background-color: rgb(38, 77, 148);
|
||||
}
|
||||
&--edited {
|
||||
background-color: rgb(167, 0, 153);
|
||||
background-color: rgb(0, 128, 167);
|
||||
background-color: rgb(65, 65, 71);
|
||||
background-color: rgb(144, 184, 0);
|
||||
background-color: rgb(82, 105, 0);
|
||||
|
||||
background-color: rgb(95, 95, 95);
|
||||
|
||||
// color: black;
|
||||
}
|
||||
}
|
||||
&__name {
|
||||
display: inline-block;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Component, OnInit, Input, Output, EventEmitter, ViewChild, ElementRef } from "@angular/core";
|
||||
import { faStar, faRetweet, faList, faThumbtack } from "@fortawesome/free-solid-svg-icons";
|
||||
import { Subscription } from "rxjs";
|
||||
|
||||
import { Status, Account } from "../../../services/models/mastodon.interfaces";
|
||||
import { OpenThreadEvent, ToolsService } from "../../../services/tools.service";
|
||||
|
@ -7,7 +8,8 @@ import { ActionBarComponent } from "./action-bar/action-bar.component";
|
|||
import { StatusWrapper } from '../../../models/common.model';
|
||||
import { EmojiConverter, EmojiTypeEnum } from '../../../tools/emoji.tools';
|
||||
import { ContentWarningPolicyEnum } from '../../../states/settings.state';
|
||||
import { stat } from 'fs';
|
||||
import { StatusesStateService, StatusState } from "../../../services/statuses-state.service";
|
||||
|
||||
|
||||
@Component({
|
||||
selector: "app-status",
|
||||
|
@ -56,6 +58,8 @@ export class StatusComponent implements OnInit {
|
|||
private _statusWrapper: StatusWrapper;
|
||||
status: Status;
|
||||
|
||||
private statusesStateServiceSub: Subscription;
|
||||
|
||||
@Input('statusWrapper')
|
||||
set statusWrapper(value: StatusWrapper) {
|
||||
this._statusWrapper = value;
|
||||
|
@ -97,9 +101,19 @@ export class StatusComponent implements OnInit {
|
|||
|
||||
constructor(
|
||||
public elem: ElementRef,
|
||||
private readonly toolsService: ToolsService) { }
|
||||
private readonly toolsService: ToolsService,
|
||||
private readonly statusesStateService: StatusesStateService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.statusesStateServiceSub = this.statusesStateService.stateNotification.subscribe(notification => {
|
||||
if(this._statusWrapper.status.url === notification.statusId && notification.isEdited) {
|
||||
this.statusWrapper = notification.editedStatus;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(){
|
||||
if(this.statusesStateServiceSub) this.statusesStateServiceSub.unsubscribe();
|
||||
}
|
||||
|
||||
private ensureMentionAreDisplayed(data: string): string {
|
||||
|
|
|
@ -124,6 +124,13 @@ 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> {
|
||||
return this.refreshAccountIfNeeded(account)
|
||||
.then((refreshedAccount: AccountInfo) => {
|
||||
return this.mastodonService.editStatus(refreshedAccount, statusId, status, visibility, spoiler, in_reply_to_id, mediaIds, poll, scheduled_at);
|
||||
});
|
||||
}
|
||||
|
||||
getStatus(account: AccountInfo, statusId: string): Promise<Status> {
|
||||
return this.refreshAccountIfNeeded(account)
|
||||
.then((refreshedAccount: AccountInfo) => {
|
||||
|
|
|
@ -128,6 +128,50 @@ 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> {
|
||||
const url = `https://${account.instance}${this.apiRoutes.editStatus.replace('{0}', statusId)}`;
|
||||
|
||||
const statusData = new StatusData();
|
||||
statusData.status = status;
|
||||
statusData.media_ids = mediaIds;
|
||||
|
||||
if (poll) {
|
||||
statusData['poll'] = poll;
|
||||
}
|
||||
|
||||
if (scheduled_at) {
|
||||
statusData['scheduled_at'] = scheduled_at;
|
||||
}
|
||||
|
||||
if (in_reply_to_id) {
|
||||
statusData.in_reply_to_id = in_reply_to_id;
|
||||
}
|
||||
if (spoiler) {
|
||||
statusData.sensitive = true;
|
||||
statusData.spoiler_text = spoiler;
|
||||
}
|
||||
switch (visibility) {
|
||||
case VisibilityEnum.Public:
|
||||
statusData.visibility = 'public';
|
||||
break;
|
||||
case VisibilityEnum.Unlisted:
|
||||
statusData.visibility = 'unlisted';
|
||||
break;
|
||||
case VisibilityEnum.Private:
|
||||
statusData.visibility = 'private';
|
||||
break;
|
||||
case VisibilityEnum.Direct:
|
||||
statusData.visibility = 'direct';
|
||||
break;
|
||||
default:
|
||||
statusData.visibility = 'private';
|
||||
break;
|
||||
}
|
||||
|
||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.put<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}` });
|
||||
|
|
|
@ -41,6 +41,7 @@ export class ApiRoutes {
|
|||
getStatusRebloggedBy = '/api/v1/statuses/{0}/reblogged_by';
|
||||
getStatusFavouritedBy = '/api/v1/statuses/{0}/favourited_by';
|
||||
postNewStatus = '/api/v1/statuses';
|
||||
editStatus = '/api/v1/statuses/{0}';
|
||||
deleteStatus = '/api/v1/statuses/{0}';
|
||||
reblogStatus = '/api/v1/statuses/{0}/reblog';
|
||||
unreblogStatus = '/api/v1/statuses/{0}/unreblog';
|
||||
|
|
|
@ -172,6 +172,7 @@ export interface Status {
|
|||
reblog: Status;
|
||||
content: string;
|
||||
created_at: string;
|
||||
edited_at: string;
|
||||
reblogs_count: number;
|
||||
replies_count: number;
|
||||
favourites_count: string;
|
||||
|
|
|
@ -9,7 +9,7 @@ export class NavigationService {
|
|||
private accountToManage: AccountWrapper;
|
||||
activatedPanelSubject = new BehaviorSubject<OpenLeftPanelEvent>(new OpenLeftPanelEvent(LeftPanelType.Closed));
|
||||
activatedMediaSubject: Subject<OpenMediaEvent> = new Subject<OpenMediaEvent>();
|
||||
columnSelectedSubject = new BehaviorSubject<number>(-1);
|
||||
columnSelectedSubject = new BehaviorSubject<number>(-1);
|
||||
|
||||
constructor() { }
|
||||
|
||||
|
@ -41,6 +41,11 @@ export class NavigationService {
|
|||
this.activatedPanelSubject.next(newEvent);
|
||||
}
|
||||
|
||||
edit(status: StatusWrapper){
|
||||
const newEvent = new OpenLeftPanelEvent(LeftPanelType.EditStatus, LeftPanelAction.Edit, null, status);
|
||||
this.activatedPanelSubject.next(newEvent);
|
||||
}
|
||||
|
||||
columnSelected(index: number): void {
|
||||
this.columnSelectedSubject.next(index);
|
||||
}
|
||||
|
@ -68,6 +73,7 @@ export enum LeftPanelAction {
|
|||
DM = 1,
|
||||
Mention = 2,
|
||||
Redraft = 3,
|
||||
Edit = 4,
|
||||
}
|
||||
|
||||
export enum LeftPanelType {
|
||||
|
@ -77,5 +83,6 @@ export enum LeftPanelType {
|
|||
Search = 3,
|
||||
AddNewAccount = 4,
|
||||
Settings = 5,
|
||||
ScheduledStatuses = 6
|
||||
ScheduledStatuses = 6,
|
||||
EditStatus = 7,
|
||||
}
|
|
@ -6,15 +6,15 @@ import { StatusWrapper } from '../models/common.model';
|
|||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class StatusesStateService {
|
||||
private cachedStatusText: { [statusId: string]: string } = {};
|
||||
private cachedStatusStates: { [statusId: string]: { [accountId: string]: StatusState } } = {};
|
||||
export class StatusesStateService {
|
||||
private cachedStatusText: { [statusId: string]: string } = {};
|
||||
private cachedStatusStates: { [statusId: string]: { [accountId: string]: StatusState } } = {};
|
||||
public stateNotification = new Subject<StatusState>();
|
||||
|
||||
constructor() { }
|
||||
|
||||
getStateForStatus(statusId: string): StatusState[] {
|
||||
if(!this.cachedStatusStates[statusId])
|
||||
if (!this.cachedStatusStates[statusId])
|
||||
return null;
|
||||
|
||||
let results: StatusState[] = [];
|
||||
|
@ -31,7 +31,7 @@ export class StatusesStateService {
|
|||
this.cachedStatusStates[statusId] = {};
|
||||
|
||||
if (!this.cachedStatusStates[statusId][accountId]) {
|
||||
this.cachedStatusStates[statusId][accountId] = new StatusState(statusId, accountId, isFavorited, null, null);
|
||||
this.cachedStatusStates[statusId][accountId] = new StatusState(statusId, accountId, isFavorited, null, null, null, null);
|
||||
} else {
|
||||
this.cachedStatusStates[statusId][accountId].isFavorited = isFavorited;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ export class StatusesStateService {
|
|||
this.cachedStatusStates[statusId] = {};
|
||||
|
||||
if (!this.cachedStatusStates[statusId][accountId]) {
|
||||
this.cachedStatusStates[statusId][accountId] = new StatusState(statusId, accountId, null, isRebloged, null);
|
||||
this.cachedStatusStates[statusId][accountId] = new StatusState(statusId, accountId, null, isRebloged, null, null, null);
|
||||
} else {
|
||||
this.cachedStatusStates[statusId][accountId].isRebloged = isRebloged;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ export class StatusesStateService {
|
|||
this.cachedStatusStates[statusId] = {};
|
||||
|
||||
if (!this.cachedStatusStates[statusId][accountId]) {
|
||||
this.cachedStatusStates[statusId][accountId] = new StatusState(statusId, accountId, null, null, isBookmarked);
|
||||
this.cachedStatusStates[statusId][accountId] = new StatusState(statusId, accountId, null, null, isBookmarked, null, null);
|
||||
} else {
|
||||
this.cachedStatusStates[statusId][accountId].isBookmarked = isBookmarked;
|
||||
}
|
||||
|
@ -65,42 +65,58 @@ export class StatusesStateService {
|
|||
this.stateNotification.next(this.cachedStatusStates[statusId][accountId]);
|
||||
}
|
||||
|
||||
setStatusContent(data: string, replyingToStatus: StatusWrapper){
|
||||
if(replyingToStatus){
|
||||
statusEditedStatusChanged(statusId: string, accountId: string, editedStatus: StatusWrapper) {
|
||||
if (!this.cachedStatusStates[statusId])
|
||||
this.cachedStatusStates[statusId] = {};
|
||||
|
||||
if (!this.cachedStatusStates[statusId][accountId]) {
|
||||
this.cachedStatusStates[statusId][accountId] = new StatusState(statusId, accountId, null, null, null, true, editedStatus);
|
||||
} else {
|
||||
this.cachedStatusStates[statusId][accountId].isEdited = true;
|
||||
this.cachedStatusStates[statusId][accountId].editedStatus = editedStatus;
|
||||
}
|
||||
|
||||
this.stateNotification.next(this.cachedStatusStates[statusId][accountId]);
|
||||
}
|
||||
|
||||
setStatusContent(data: string, replyingToStatus: StatusWrapper) {
|
||||
if (replyingToStatus) {
|
||||
this.cachedStatusText[replyingToStatus.status.uri] = data;
|
||||
} else {
|
||||
this.cachedStatusText['none'] = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getStatusContent(replyingToStatus: StatusWrapper): string{
|
||||
getStatusContent(replyingToStatus: StatusWrapper): string {
|
||||
let data: string;
|
||||
if(replyingToStatus){
|
||||
if (replyingToStatus) {
|
||||
data = this.cachedStatusText[replyingToStatus.status.uri];
|
||||
} else {
|
||||
data = this.cachedStatusText['none'];
|
||||
}
|
||||
|
||||
if(!data) return '';
|
||||
if (!data) return '';
|
||||
return data;
|
||||
}
|
||||
|
||||
resetStatusContent(replyingToStatus: StatusWrapper){
|
||||
if(replyingToStatus){
|
||||
resetStatusContent(replyingToStatus: StatusWrapper) {
|
||||
if (replyingToStatus) {
|
||||
this.cachedStatusText[replyingToStatus.status.uri] = '';
|
||||
} else {
|
||||
this.cachedStatusText['none'] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class StatusState {
|
||||
|
||||
|
||||
constructor(
|
||||
public statusId: string,
|
||||
public accountId: string,
|
||||
public isFavorited: boolean,
|
||||
public statusId: string,
|
||||
public accountId: string,
|
||||
public isFavorited: boolean,
|
||||
public isRebloged: boolean,
|
||||
public isBookmarked: boolean) {
|
||||
public isBookmarked: boolean,
|
||||
public isEdited: boolean,
|
||||
public editedStatus: StatusWrapper) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue