added mention replication in multiposting #58
This commit is contained in:
parent
81ff215840
commit
5cdca202f8
|
@ -12,7 +12,7 @@ import { StreamsState } from '../../states/streams.state';
|
||||||
import { NavigationService } from '../../services/navigation.service';
|
import { NavigationService } from '../../services/navigation.service';
|
||||||
import { NotificationService } from '../../services/notification.service';
|
import { NotificationService } from '../../services/notification.service';
|
||||||
import { MastodonService } from '../../services/mastodon.service';
|
import { MastodonService } from '../../services/mastodon.service';
|
||||||
import { restoreView } from '@angular/core/src/render3';
|
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||||
|
|
||||||
describe('CreateStatusComponent', () => {
|
describe('CreateStatusComponent', () => {
|
||||||
let component: CreateStatusComponent;
|
let component: CreateStatusComponent;
|
||||||
|
@ -33,6 +33,7 @@ describe('CreateStatusComponent', () => {
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
providers: [NavigationService, NotificationService, MastodonService],
|
providers: [NavigationService, NotificationService, MastodonService],
|
||||||
|
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -93,4 +94,42 @@ describe('CreateStatusComponent', () => {
|
||||||
expect(result[1].length).toBeLessThanOrEqual(500);
|
expect(result[1].length).toBeLessThanOrEqual(500);
|
||||||
expect(result[2].length).toBeLessThanOrEqual(500);
|
expect(result[2].length).toBeLessThanOrEqual(500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not count domain length when replying', () => {
|
||||||
|
const status = '@Lorem@ipsum.com ipsum dolor sit amet, consectetur adipiscing elit. Mauris sed ante id dolor vulputate pulvinar sit amet a nisl. Duis sagittis nisl sit amet est rhoncus rutrum. Duis aliquet eget erat nec molestie. Fusce bibendum consectetur rhoncus. Aenean vel neque ac diam hendrerit interdum id a nisl. Aenean leo ante, luctus eget erat at, interdum tincidunt turpis. Donec non efficitur magna. Nam placerat convallis tincidunt. Etiam ac scelerisque velit, at vestibulum turpis. In hac habitasse platea dictu';
|
||||||
|
(<any>component).maxCharLength = 500;
|
||||||
|
const result = <string[]>(<any>component).parseStatus(status);
|
||||||
|
expect(result.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not count domain length when replying', () => {
|
||||||
|
const status = '@Lorem@ipsum.com @1orem@ipsum.com ipsum dolor sit amet, consectetur adipiscing elit. Mauris sed ante id dolor vulputate pulvinar sit amet a nisl. Duis sagittis nisl sit amet est rhoncus rutrum. Duis aliquet eget erat nec molestie. Fusce bibendum consectetur rhoncus. Aenean vel neque ac diam hendrerit interdum id a nisl. Aenean leo ante, luctus eget erat at, interdum tincidunt turpis. Donec non efficitur magna. Nam placerat convallis tincidunt. Etiam ac scelerisque velit, at vestibulum turpis. In hac habitasse plate';
|
||||||
|
(<any>component).maxCharLength = 500;
|
||||||
|
const result = <string[]>(<any>component).parseStatus(status);
|
||||||
|
expect(result.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add alias in multiposting replies', () => {
|
||||||
|
const status = '@Lorem@ipsum.com ipsum dolor sit amet, consectetur adipiscing elit. Mauris sed ante id dolor vulputate pulvinar sit amet a nisl. Duis sagittis nisl sit amet est rhoncus rutrum. Duis aliquet eget erat nec molestie. Fusce bibendum consectetur rhoncus. Aenean vel neque ac diam hendrerit interdum id a nisl. Aenean leo ante, luctus eget erat at, interdum tincidunt turpis. Donec non efficitur magna. Nam placerat convallis tincidunt. Etiam ac scelerisque velit, at vestibulum turpis. In hac habitasse platea dictu0';
|
||||||
|
(<any>component).maxCharLength = 500;
|
||||||
|
const result = <string[]>(<any>component).parseStatus(status);
|
||||||
|
expect(result.length).toBe(2);
|
||||||
|
expect(result[0].length).toBeLessThanOrEqual(510);
|
||||||
|
expect(result[1].length).toBeLessThanOrEqual(510);
|
||||||
|
expect(result[0]).toContain('@Lorem@ipsum.com ');
|
||||||
|
expect(result[1]).toContain('@Lorem@ipsum.com ');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add alias in multiposting replies', () => {
|
||||||
|
const status = '@Lorem@ipsum.com @48756@987586.ipsum.com ipsum dolor sit amet, consectetur adipiscing elit. Mauris sed ante id dolor vulputate pulvinar sit amet a nisl. Duis sagittis nisl sit amet est rhoncus rutrum. Duis aliquet eget erat nec molestie. Fusce bibendum consectetur rhoncus. Aenean vel neque ac diam hendrerit interdum id a nisl. Aenean leo ante, luctus eget erat at, interdum tincidunt turpis. Donec non efficitur magna. Nam placerat convallis tincidunt. Etiam ac scelerisque velit, at vestibulum turpis. In hac habitasse platea dictu0';
|
||||||
|
(<any>component).maxCharLength = 500;
|
||||||
|
const result = <string[]>(<any>component).parseStatus(status);
|
||||||
|
expect(result.length).toBe(2);
|
||||||
|
expect(result[0].length).toBeLessThanOrEqual(527);
|
||||||
|
expect(result[1].length).toBeLessThanOrEqual(527);
|
||||||
|
expect(result[0]).toContain('@Lorem@ipsum.com ');
|
||||||
|
expect(result[1]).toContain('@Lorem@ipsum.com ');
|
||||||
|
console.warn(result);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
|
@ -88,43 +88,46 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private accountChanged(accounts: AccountInfo[]): void {
|
private accountChanged(accounts: AccountInfo[]): void {
|
||||||
const selectedAccount = accounts.filter(x => x.isSelected)[0];
|
if (accounts && accounts.length > 0) {
|
||||||
this.instancesInfoService.getMaxStatusChars(selectedAccount.instance)
|
const selectedAccount = accounts.filter(x => x.isSelected)[0];
|
||||||
.then((maxChars: number) => {
|
this.instancesInfoService.getMaxStatusChars(selectedAccount.instance)
|
||||||
this.maxCharLength = maxChars;
|
.then((maxChars: number) => {
|
||||||
this.countStatusChar(this.status);
|
this.maxCharLength = maxChars;
|
||||||
})
|
this.countStatusChar(this.status);
|
||||||
.catch((err: HttpErrorResponse) => {
|
})
|
||||||
this.notificationService.notifyHttpError(err);
|
.catch((err: HttpErrorResponse) => {
|
||||||
});
|
this.notificationService.notifyHttpError(err);
|
||||||
|
});
|
||||||
|
|
||||||
this.instancesInfoService.getDefaultPrivacy(selectedAccount)
|
this.instancesInfoService.getDefaultPrivacy(selectedAccount)
|
||||||
.then((defaultPrivacy: VisibilityEnum) => {
|
.then((defaultPrivacy: VisibilityEnum) => {
|
||||||
switch (defaultPrivacy) {
|
switch (defaultPrivacy) {
|
||||||
case VisibilityEnum.Public:
|
case VisibilityEnum.Public:
|
||||||
this.selectedPrivacy = 'Public';
|
this.selectedPrivacy = 'Public';
|
||||||
break;
|
break;
|
||||||
case VisibilityEnum.Unlisted:
|
case VisibilityEnum.Unlisted:
|
||||||
this.selectedPrivacy = 'Unlisted';
|
this.selectedPrivacy = 'Unlisted';
|
||||||
break;
|
break;
|
||||||
case VisibilityEnum.Private:
|
case VisibilityEnum.Private:
|
||||||
this.selectedPrivacy = 'Follows-only';
|
this.selectedPrivacy = 'Follows-only';
|
||||||
break;
|
break;
|
||||||
case VisibilityEnum.Direct:
|
case VisibilityEnum.Direct:
|
||||||
this.selectedPrivacy = 'DM';
|
this.selectedPrivacy = 'DM';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err: HttpErrorResponse) => {
|
.catch((err: HttpErrorResponse) => {
|
||||||
this.notificationService.notifyHttpError(err);
|
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];
|
||||||
|
const statusExtraChars = this.getMentionExtraChars(status);
|
||||||
|
|
||||||
const statusLength = currentStatus.length;
|
const statusLength = currentStatus.length - statusExtraChars;
|
||||||
this.charCountLeft = this.maxCharLength - statusLength;
|
this.charCountLeft = this.maxCharLength - statusLength;
|
||||||
this.postCounts = parseStatus.length;
|
this.postCounts = parseStatus.length;
|
||||||
}
|
}
|
||||||
|
@ -233,15 +236,44 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseStatus(status: string): string[] {
|
private parseStatus(status: string): string[] {
|
||||||
|
let mentionExtraChars = this.getMentionExtraChars(status);
|
||||||
let trucatedStatus = `${status}`;
|
let trucatedStatus = `${status}`;
|
||||||
let results = [];
|
let results = [];
|
||||||
const maxChars = this.maxCharLength - 6;
|
|
||||||
while (trucatedStatus.length > this.maxCharLength) {
|
let aggregateMention = '';
|
||||||
|
let mentions = this.getMentionsFromStatus(status);
|
||||||
|
mentions.forEach(x => {
|
||||||
|
aggregateMention += `${x} `;
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentMaxCharLength = this.maxCharLength + mentionExtraChars;
|
||||||
|
const maxChars = currentMaxCharLength - 6;
|
||||||
|
|
||||||
|
while (trucatedStatus.length > currentMaxCharLength) {
|
||||||
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 = aggregateMention + trucatedStatus.substr(nextIndex + 1);
|
||||||
}
|
}
|
||||||
results.push(trucatedStatus);
|
results.push(trucatedStatus);
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getMentionExtraChars(status: string): number{
|
||||||
|
let mentionExtraChars = 0;
|
||||||
|
let mentions = this.getMentionsFromStatus(status);
|
||||||
|
|
||||||
|
for (const mention of mentions) {
|
||||||
|
if (mention.lastIndexOf('@') !== 0) {
|
||||||
|
const domain = mention.split('@')[2];
|
||||||
|
if (domain.length > 1) {
|
||||||
|
mentionExtraChars += (domain.length + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mentionExtraChars;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getMentionsFromStatus(status: string): string[]{
|
||||||
|
return status.split(' ').filter(x => x.indexOf('@') === 0 && x.length > 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue