fix #54
This commit is contained in:
parent
b4fdce6e66
commit
81ff215840
|
@ -22,7 +22,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
private _status: string = '';
|
private _status: string = '';
|
||||||
set status(value: string){
|
set status(value: string) {
|
||||||
this.countStatusChar(value);
|
this.countStatusChar(value);
|
||||||
this._status = value;
|
this._status = value;
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
private readonly mastodonService: MastodonService,
|
private readonly mastodonService: MastodonService,
|
||||||
private readonly instancesInfoService: InstancesInfoService,
|
private readonly instancesInfoService: InstancesInfoService,
|
||||||
private readonly mediaService: MediaService) {
|
private readonly mediaService: MediaService) {
|
||||||
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
|
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
||||||
|
@ -83,7 +83,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(){
|
ngOnDestroy() {
|
||||||
this.accountSub.unsubscribe();
|
this.accountSub.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,10 +93,34 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
.then((maxChars: number) => {
|
.then((maxChars: number) => {
|
||||||
this.maxCharLength = maxChars;
|
this.maxCharLength = maxChars;
|
||||||
this.countStatusChar(this.status);
|
this.countStatusChar(this.status);
|
||||||
|
})
|
||||||
|
.catch((err: HttpErrorResponse) => {
|
||||||
|
this.notificationService.notifyHttpError(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.instancesInfoService.getDefaultPrivacy(selectedAccount)
|
||||||
|
.then((defaultPrivacy: VisibilityEnum) => {
|
||||||
|
switch (defaultPrivacy) {
|
||||||
|
case VisibilityEnum.Public:
|
||||||
|
this.selectedPrivacy = 'Public';
|
||||||
|
break;
|
||||||
|
case VisibilityEnum.Unlisted:
|
||||||
|
this.selectedPrivacy = 'Unlisted';
|
||||||
|
break;
|
||||||
|
case VisibilityEnum.Private:
|
||||||
|
this.selectedPrivacy = 'Follows-only';
|
||||||
|
break;
|
||||||
|
case VisibilityEnum.Direct:
|
||||||
|
this.selectedPrivacy = 'DM';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err: HttpErrorResponse) => {
|
||||||
|
this.notificationService.notifyHttpError(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private countStatusChar(status: string){
|
private countStatusChar(status: string) {
|
||||||
const parseStatus = this.parseStatus(status);
|
const parseStatus = this.parseStatus(status);
|
||||||
const currentStatus = parseStatus[parseStatus.length - 1];
|
const currentStatus = parseStatus[parseStatus.length - 1];
|
||||||
|
|
||||||
|
@ -185,7 +209,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
let parsedStatus = this.parseStatus(status);
|
let parsedStatus = this.parseStatus(status);
|
||||||
let resultPromise = Promise.resolve(previousStatus);
|
let resultPromise = Promise.resolve(previousStatus);
|
||||||
|
|
||||||
for(let i = 0; i < parsedStatus.length; i++){
|
for (let i = 0; i < parsedStatus.length; i++) {
|
||||||
let s = parsedStatus[i];
|
let s = parsedStatus[i];
|
||||||
resultPromise = resultPromise.then((pStatus: Status) => {
|
resultPromise = resultPromise.then((pStatus: Status) => {
|
||||||
let inReplyToId = null;
|
let inReplyToId = null;
|
||||||
|
@ -193,9 +217,9 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
inReplyToId = pStatus.id;
|
inReplyToId = pStatus.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i === 0){
|
if (i === 0) {
|
||||||
return this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, attachments.map(x => x.id))
|
return this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, attachments.map(x => x.id))
|
||||||
.then((status:Status) => {
|
.then((status: Status) => {
|
||||||
this.mediaService.clearMedia();
|
this.mediaService.clearMedia();
|
||||||
return status;
|
return status;
|
||||||
});
|
});
|
||||||
|
@ -212,7 +236,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
let trucatedStatus = `${status}`;
|
let trucatedStatus = `${status}`;
|
||||||
let results = [];
|
let results = [];
|
||||||
const maxChars = this.maxCharLength - 6;
|
const maxChars = this.maxCharLength - 6;
|
||||||
while(trucatedStatus.length > this.maxCharLength){
|
while (trucatedStatus.length > this.maxCharLength) {
|
||||||
const nextIndex = trucatedStatus.lastIndexOf(' ', maxChars);
|
const nextIndex = trucatedStatus.lastIndexOf(' ', maxChars);
|
||||||
results.push(trucatedStatus.substr(0, nextIndex) + ' (...)');
|
results.push(trucatedStatus.substr(0, nextIndex) + ' (...)');
|
||||||
trucatedStatus = trucatedStatus.substr(nextIndex + 1);
|
trucatedStatus = trucatedStatus.substr(nextIndex + 1);
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { MastodonService } from './mastodon.service';
|
import { MastodonService, VisibilityEnum } from './mastodon.service';
|
||||||
import { Instance } from './models/mastodon.interfaces';
|
import { Instance, Account } from './models/mastodon.interfaces';
|
||||||
|
import { AccountInfo } from '../states/accounts.state';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class InstancesInfoService {
|
export class InstancesInfoService {
|
||||||
private defaultMaxChars = 500;
|
private defaultMaxChars = 500;
|
||||||
private cachedMaxInstanceChar: { [id: string] : Promise<number>; } = {};
|
private cachedMaxInstanceChar: { [id: string]: Promise<number>; } = {};
|
||||||
|
private cachedDefaultPrivacy: { [id: string]: Promise<VisibilityEnum>; } = {};
|
||||||
|
|
||||||
constructor(private mastodonService: MastodonService) { }
|
constructor(private mastodonService: MastodonService) { }
|
||||||
|
|
||||||
getMaxStatusChars(instance:string): Promise<number> {
|
getMaxStatusChars(instance: string): Promise<number> {
|
||||||
if(!this.cachedMaxInstanceChar[instance]){
|
if (!this.cachedMaxInstanceChar[instance]) {
|
||||||
this.cachedMaxInstanceChar[instance] = this.mastodonService.getInstance(instance)
|
this.cachedMaxInstanceChar[instance] = this.mastodonService.getInstance(instance)
|
||||||
.then((instance: Instance)=>{
|
.then((instance: Instance) => {
|
||||||
if(instance.max_toot_chars){
|
if (instance.max_toot_chars) {
|
||||||
return instance.max_toot_chars;
|
return instance.max_toot_chars;
|
||||||
} else {
|
} else {
|
||||||
return this.defaultMaxChars;
|
return this.defaultMaxChars;
|
||||||
|
@ -28,4 +30,29 @@ export class InstancesInfoService {
|
||||||
}
|
}
|
||||||
return this.cachedMaxInstanceChar[instance];
|
return this.cachedMaxInstanceChar[instance];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDefaultPrivacy(account: AccountInfo): Promise<VisibilityEnum> {
|
||||||
|
const instance = account.instance;
|
||||||
|
if (!this.cachedDefaultPrivacy[instance]) {
|
||||||
|
this.cachedDefaultPrivacy[instance] = this.mastodonService.retrieveAccountDetails(account)
|
||||||
|
.then((accountDetails: Account) => {
|
||||||
|
switch (accountDetails.source.privacy) {
|
||||||
|
case 'public':
|
||||||
|
return VisibilityEnum.Public;
|
||||||
|
case 'unlisted':
|
||||||
|
return VisibilityEnum.Unlisted;
|
||||||
|
case 'private':
|
||||||
|
return VisibilityEnum.Private;
|
||||||
|
case 'direct':
|
||||||
|
return VisibilityEnum.Direct;
|
||||||
|
default:
|
||||||
|
return VisibilityEnum.Public;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
return VisibilityEnum.Public;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this.cachedDefaultPrivacy[instance];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,14 @@ export interface Account {
|
||||||
moved: boolean;
|
moved: boolean;
|
||||||
fields: Field[];
|
fields: Field[];
|
||||||
bot: boolean;
|
bot: boolean;
|
||||||
|
source: AccountInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AccountInfo {
|
||||||
|
privacy: string;
|
||||||
|
sensitive: boolean;
|
||||||
|
note: string;
|
||||||
|
fields: Field[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Emoji {
|
export interface Emoji {
|
||||||
|
|
Loading…
Reference in New Issue