1
0
mirror of https://github.com/NicolasConstant/sengi synced 2024-12-22 21:58:59 +01:00

language posting working

This commit is contained in:
Nicolas Constant 2023-08-04 03:20:48 -04:00
parent 91b2f4a0f0
commit 32efac5aa4
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
4 changed files with 35 additions and 14 deletions

View File

@ -93,6 +93,6 @@
{{ l.name }}
</ng-template>
</context-menu>
<app-media></app-media>
</form>

View File

@ -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<Status> {
let parsedStatus = this.parseStatus(status);
let resultPromise = Promise.resolve(previousStatus);
@ -669,9 +676,9 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
let postPromise: Promise<Status>;
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());
}
}
})

View File

@ -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<Status> {
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<Status> {
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<Status> {
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<Status> {
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);
});
}

View File

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