diff --git a/src/app/components/create-status/create-status.component.html b/src/app/components/create-status/create-status.component.html index a6a450de..8fef8712 100644 --- a/src/app/components/create-status/create-status.component.html +++ b/src/app/components/create-status/create-status.component.html @@ -93,6 +93,6 @@ {{ l.name }} - + diff --git a/src/app/components/create-status/create-status.component.ts b/src/app/components/create-status/create-status.component.ts index 78f18cd1..f39650f0 100644 --- a/src/app/components/create-status/create-status.component.ts +++ b/src/app/components/create-status/create-status.component.ts @@ -155,6 +155,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy { instanceSupportsScheduling = true; isEditing: boolean; editingStatusId: string; + configuredLanguages: ILanguage[] = []; + selectedLanguage: ILanguage; private statusLoaded: boolean; private hasSuggestions: boolean; @@ -222,9 +224,6 @@ export class CreateStatusComponent implements OnInit, OnDestroy { this.accounts$ = this.store.select(state => state.registeredaccounts.accounts); } - configuredLanguages: ILanguage[] = []; - selectedLanguage: ILanguage; - private initLanguages(){ this.configuredLanguages = this.languageService.getConfiguredLanguages(); this.selectedLanguage = this.languageService.getSelectedLanguage(); @@ -652,6 +651,14 @@ export class CreateStatusComponent implements OnInit, OnDestroy { return false; } + private currentLang(): string { + if(this.selectedLanguage){ + return this.selectedLanguage.iso639; + } + return null; + } + + private sendStatus(account: AccountInfo, status: string, visibility: VisibilityEnum, title: string, previousStatus: Status, attachments: Attachment[], poll: PollParameters, scheduledAt: string, editingStatusId: string): Promise { let parsedStatus = this.parseStatus(status); let resultPromise = Promise.resolve(previousStatus); @@ -669,9 +676,9 @@ export class CreateStatusComponent implements OnInit, OnDestroy { let postPromise: Promise; if (this.isEditing) { - postPromise = this.mastodonService.editStatus(account, editingStatusId, s, visibility, title, inReplyToId, attachments, poll, scheduledAt); + postPromise = this.mastodonService.editStatus(account, editingStatusId, s, visibility, title, inReplyToId, attachments, poll, scheduledAt, this.currentLang()); } else { - postPromise = this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, attachments.map(x => x.id), poll, scheduledAt); + postPromise = this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, attachments.map(x => x.id), poll, scheduledAt, this.currentLang()); } return postPromise @@ -681,9 +688,9 @@ export class CreateStatusComponent implements OnInit, OnDestroy { }); } else { if (this.isEditing) { - return this.mastodonService.editStatus(account, editingStatusId, s, visibility, title, inReplyToId, [], null, scheduledAt); + return this.mastodonService.editStatus(account, editingStatusId, s, visibility, title, inReplyToId, [], null, scheduledAt, this.currentLang()); } else { - return this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, [], null, scheduledAt); + return this.mastodonService.postNewStatus(account, s, visibility, title, inReplyToId, [], null, scheduledAt, this.currentLang()); } } }) diff --git a/src/app/services/mastodon-wrapper.service.ts b/src/app/services/mastodon-wrapper.service.ts index c7c51b88..541cdfe9 100644 --- a/src/app/services/mastodon-wrapper.service.ts +++ b/src/app/services/mastodon-wrapper.service.ts @@ -117,17 +117,17 @@ export class MastodonWrapperService { }); } - postNewStatus(account: AccountInfo, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, mediaIds: string[], poll: PollParameters = null, scheduled_at: string = null): Promise { + postNewStatus(account: AccountInfo, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, mediaIds: string[], poll: PollParameters = null, scheduled_at: string = null, lang: string = null): Promise { return this.refreshAccountIfNeeded(account) .then((refreshedAccount: AccountInfo) => { - return this.mastodonService.postNewStatus(refreshedAccount, status, visibility, spoiler, in_reply_to_id, mediaIds, poll, scheduled_at); + return this.mastodonService.postNewStatus(refreshedAccount, status, visibility, spoiler, in_reply_to_id, mediaIds, poll, scheduled_at, lang); }); } - editStatus(account: AccountInfo, statusId: string, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, attachements: Attachment[], poll: PollParameters = null, scheduled_at: string = null): Promise { + editStatus(account: AccountInfo, statusId: string, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, attachements: Attachment[], poll: PollParameters = null, scheduled_at: string = null, lang: string = null): Promise { return this.refreshAccountIfNeeded(account) .then((refreshedAccount: AccountInfo) => { - return this.mastodonService.editStatus(refreshedAccount, statusId, status, visibility, spoiler, in_reply_to_id, attachements, poll, scheduled_at); + return this.mastodonService.editStatus(refreshedAccount, statusId, status, visibility, spoiler, in_reply_to_id, attachements, poll, scheduled_at, lang); }); } diff --git a/src/app/services/mastodon.service.ts b/src/app/services/mastodon.service.ts index 4b985817..f833f960 100644 --- a/src/app/services/mastodon.service.ts +++ b/src/app/services/mastodon.service.ts @@ -88,7 +88,7 @@ export class MastodonService { return origString.replace(regEx, ""); }; - postNewStatus(account: AccountInfo, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, mediaIds: string[], poll: PollParameters = null, scheduled_at: string = null): Promise { + postNewStatus(account: AccountInfo, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, mediaIds: string[], poll: PollParameters = null, scheduled_at: string = null, lang: string = null): Promise { const url = `https://${account.instance}${this.apiRoutes.postNewStatus}`; const statusData = new StatusData(); @@ -106,10 +106,16 @@ export class MastodonService { if (in_reply_to_id) { statusData.in_reply_to_id = in_reply_to_id; } + if (spoiler) { statusData.sensitive = true; statusData.spoiler_text = spoiler; } + + if(lang) { + statusData.language = lang; + } + switch (visibility) { case VisibilityEnum.Public: statusData.visibility = 'public'; @@ -132,7 +138,7 @@ export class MastodonService { return this.httpClient.post(url, statusData, { headers: headers }).toPromise(); } - editStatus(account: AccountInfo, statusId: string, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, attachements: Attachment[], poll: PollParameters = null, scheduled_at: string = null): Promise { + editStatus(account: AccountInfo, statusId: string, status: string, visibility: VisibilityEnum, spoiler: string = null, in_reply_to_id: string = null, attachements: Attachment[], poll: PollParameters = null, scheduled_at: string = null, lang: string = null): Promise { const url = `https://${account.instance}${this.apiRoutes.editStatus.replace('{0}', statusId)}`; const statusData = new StatusData(); @@ -151,10 +157,16 @@ export class MastodonService { if (in_reply_to_id) { statusData.in_reply_to_id = in_reply_to_id; } + if (spoiler) { statusData.sensitive = true; statusData.spoiler_text = spoiler; } + + if(lang) { + statusData.language = lang; + } + switch (visibility) { case VisibilityEnum.Public: statusData.visibility = 'public'; @@ -651,6 +663,8 @@ class StatusData { spoiler_text: string; visibility: string; // scheduled_at: string; + + language: string; } class MediaAttributes {