fix #65
This commit is contained in:
parent
d26490be62
commit
891174a05a
|
@ -34,8 +34,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
private maxCharLength: number;
|
private maxCharLength: number;
|
||||||
charCountLeft: number;
|
charCountLeft: number;
|
||||||
postCounts: number = 1;
|
postCounts: number = 1;
|
||||||
|
|
||||||
isSending: boolean;
|
isSending: boolean;
|
||||||
|
mentionTooFarAwayError: boolean;
|
||||||
|
|
||||||
@Input() statusReplyingToWrapper: StatusWrapper;
|
@Input() statusReplyingToWrapper: StatusWrapper;
|
||||||
@Output() onClose = new EventEmitter();
|
@Output() onClose = new EventEmitter();
|
||||||
|
@ -76,6 +76,21 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
this.status += `@${mention} `;
|
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.title = this.statusReplyingTo.spoiler_text;
|
this.title = this.statusReplyingTo.spoiler_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,60 +115,54 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
this.notificationService.notifyHttpError(err);
|
this.notificationService.notifyHttpError(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.instancesInfoService.getDefaultPrivacy(selectedAccount)
|
if (!this.statusReplyingToWrapper) {
|
||||||
.then((defaultPrivacy: VisibilityEnum) => {
|
this.instancesInfoService.getDefaultPrivacy(selectedAccount)
|
||||||
switch (defaultPrivacy) {
|
.then((defaultPrivacy: VisibilityEnum) => {
|
||||||
case VisibilityEnum.Public:
|
this.setVisibility(defaultPrivacy);
|
||||||
this.selectedPrivacy = 'Public';
|
})
|
||||||
break;
|
.catch((err: HttpErrorResponse) => {
|
||||||
case VisibilityEnum.Unlisted:
|
this.notificationService.notifyHttpError(err);
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mentionTooFarAwayError: boolean;
|
private setVisibility(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private countStatusChar(status: string) {
|
private countStatusChar(status: string) {
|
||||||
this.mentionTooFarAwayError = false;
|
this.mentionTooFarAwayError = false;
|
||||||
const parseStatus = this.parseStatus(status);
|
const parseStatus = this.parseStatus(status);
|
||||||
|
|
||||||
const mentions = this.getMentionsFromStatus(status);
|
const mentions = this.getMentionsFromStatus(status);
|
||||||
if(mentions.length > 0){
|
if (mentions.length > 0) {
|
||||||
let containAllMention = true;
|
let containAllMention = true;
|
||||||
mentions.forEach(m => {
|
mentions.forEach(m => {
|
||||||
if(!parseStatus[0].includes(m)){
|
if (!parseStatus[0].includes(m)) {
|
||||||
containAllMention = false;
|
containAllMention = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!containAllMention){
|
if (!containAllMention) {
|
||||||
this.mentionTooFarAwayError = true;
|
this.mentionTooFarAwayError = true;
|
||||||
this.charCountLeft = this.maxCharLength - status.length;
|
this.charCountLeft = this.maxCharLength - status.length;
|
||||||
this.postCounts = 1;
|
this.postCounts = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const lastMention = mentions[mentions.length - 1];
|
|
||||||
// const lastMentionPosition = status.lastIndexOf(lastMention);
|
|
||||||
// console.warn(`lastMentionPosition ${lastMentionPosition}`);
|
|
||||||
// if(lastMentionPosition > (this.maxCharLength - lastMention.length * 2 + 10)){
|
|
||||||
// this.mentionTooFarAwayError = true;
|
|
||||||
// this.charCountLeft = this.maxCharLength - status.length;
|
|
||||||
// this.postCounts = 1;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentStatus = parseStatus[parseStatus.length - 1];
|
const currentStatus = parseStatus[parseStatus.length - 1];
|
||||||
|
@ -196,7 +205,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
this.isSending = true;
|
this.isSending = true;
|
||||||
|
|
||||||
let visibility: VisibilityEnum = VisibilityEnum.Unknown;
|
let visibility: VisibilityEnum = VisibilityEnum.Unknown;
|
||||||
switch (this.selectedPrivacy) { //FIXME: in case of responding, set the visibility to original
|
switch (this.selectedPrivacy) {
|
||||||
case 'Public':
|
case 'Public':
|
||||||
visibility = VisibilityEnum.Public;
|
visibility = VisibilityEnum.Public;
|
||||||
break;
|
break;
|
||||||
|
@ -290,7 +299,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getMentionExtraChars(status: string): number{
|
private getMentionExtraChars(status: string): number {
|
||||||
let mentionExtraChars = 0;
|
let mentionExtraChars = 0;
|
||||||
let mentions = this.getMentionsFromStatus(status);
|
let mentions = this.getMentionsFromStatus(status);
|
||||||
|
|
||||||
|
@ -305,7 +314,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
return mentionExtraChars;
|
return mentionExtraChars;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getMentionsFromStatus(status: string): string[]{
|
private getMentionsFromStatus(status: string): string[] {
|
||||||
return status.split(' ').filter(x => x.indexOf('@') === 0 && x.length > 1);
|
return status.split(' ').filter(x => x.indexOf('@') === 0 && x.length > 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ export interface Status {
|
||||||
favourited: boolean;
|
favourited: boolean;
|
||||||
sensitive: boolean;
|
sensitive: boolean;
|
||||||
spoiler_text: string;
|
spoiler_text: string;
|
||||||
visibility: string;
|
visibility: 'public' | 'unlisted' | 'private' | 'direct';
|
||||||
media_attachments: Attachment[];
|
media_attachments: Attachment[];
|
||||||
mentions: Mention[];
|
mentions: Mention[];
|
||||||
tags: Tag[];
|
tags: Tag[];
|
||||||
|
|
Loading…
Reference in New Issue