added edition notification logic

This commit is contained in:
Nicolas Constant 2022-12-10 18:31:54 -05:00
parent 0ce8be99bd
commit 57f863e2a1
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
6 changed files with 82 additions and 25 deletions

View File

@ -209,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);
}
@ -677,7 +678,16 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
if (this.statusReplyingToWrapper) {
let cwPolicy = this.toolsService.checkContentWarning(status);
this.notificationService.newStatusPosted(this.statusReplyingToWrapper.status.id, new StatusWrapper(cwPolicy.status, account, cwPolicy.applyCw, cwPolicy.hide));
}
}
return status;
})
.then((status: Status) => {
let cwPolicy = this.toolsService.checkContentWarning(status);
let statusWrapper = new StatusWrapper(status, account, cwPolicy.applyCw, cwPolicy.hide);
//TODO: foreach account
this.statusesStateService.statusEditedStatusChanged(status.url, account.id, statusWrapper);
return status;
});

View File

@ -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>

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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, 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, 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, null);
} else {
this.cachedStatusStates[statusId][accountId].isBookmarked = isBookmarked;
}
@ -65,42 +65,60 @@ 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, new Date().toISOString(), editedStatus);
} else {
this.cachedStatusStates[statusId][accountId].isEdited = true;
this.cachedStatusStates[statusId][accountId].editionTime = new Date().toISOString();
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 editionTime: string,
public editedStatus: StatusWrapper) {
}
}