supporting new instance v2 model
This commit is contained in:
parent
232a86566c
commit
22cad9e22d
|
@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
|||
|
||||
import { VisibilityEnum } from './mastodon.service';
|
||||
import { MastodonWrapperService } from './mastodon-wrapper.service';
|
||||
import { Instance, Account } from './models/mastodon.interfaces';
|
||||
import { Instance, Instancev1, Instancev2, Account } from './models/mastodon.interfaces';
|
||||
import { AccountInfo } from '../states/accounts.state';
|
||||
|
||||
@Injectable({
|
||||
|
@ -19,11 +19,20 @@ export class InstancesInfoService {
|
|||
if (!this.cachedMaxInstanceChar[instance]) {
|
||||
this.cachedMaxInstanceChar[instance] = this.mastodonService.getInstance(instance)
|
||||
.then((instance: Instance) => {
|
||||
if (instance.max_toot_chars) {
|
||||
return instance.max_toot_chars;
|
||||
if (+instance.version.split('.')[0] >= 4) {
|
||||
const instanceV2 = <Instancev2>instance;
|
||||
if (instanceV2
|
||||
&& instanceV2.configuration
|
||||
&& instanceV2.configuration.statuses
|
||||
&& instanceV2.configuration.statuses.max_characters)
|
||||
return instanceV2.configuration.statuses.max_characters;
|
||||
} else {
|
||||
return this.defaultMaxChars;
|
||||
const instanceV1 = <Instancev1>instance;
|
||||
if (instanceV1 && instanceV1.max_toot_chars)
|
||||
return instanceV1.max_toot_chars;
|
||||
}
|
||||
|
||||
return this.defaultMaxChars;
|
||||
})
|
||||
.catch(() => {
|
||||
return this.defaultMaxChars;
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
|||
import { HttpHeaders, HttpClient, HttpResponse } from '@angular/common/http';
|
||||
|
||||
import { ApiRoutes } from './models/api.settings';
|
||||
import { Account, Status, Results, Context, Relationship, Instance, Attachment, Notification, List, Poll, Emoji, Conversation, ScheduledStatus, Tag } from "./models/mastodon.interfaces";
|
||||
import { Account, Status, Results, Context, Relationship, Instance, Attachment, Notification, List, Poll, Emoji, Conversation, ScheduledStatus, Tag, Instancev2, Instancev1 } from "./models/mastodon.interfaces";
|
||||
import { AccountInfo } from '../states/accounts.state';
|
||||
import { StreamTypeEnum, StreamElement } from '../states/streams.state';
|
||||
|
||||
|
@ -14,10 +14,10 @@ export class MastodonService {
|
|||
|
||||
getInstance(instance: string): Promise<Instance> {
|
||||
let route = `https://${instance}${this.apiRoutes.getInstancev2}`;
|
||||
return this.httpClient.get<Instance>(route).toPromise()
|
||||
return this.httpClient.get<Instancev2>(route).toPromise()
|
||||
.catch(err => {
|
||||
route = `https://${instance}${this.apiRoutes.getInstance}`;
|
||||
return this.httpClient.get<Instance>(route).toPromise();
|
||||
return this.httpClient.get<Instancev1>(route).toPromise();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -110,21 +110,43 @@ export interface Error {
|
|||
error: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface Instance {
|
||||
uri: string;
|
||||
title: string;
|
||||
description: string;
|
||||
email: string;
|
||||
version: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface Instancev1 extends Instance {
|
||||
uri: string;
|
||||
email: string;
|
||||
urls: InstanceUrls;
|
||||
contact_account: Account;
|
||||
max_toot_chars: number;
|
||||
}
|
||||
|
||||
export interface Instancev2 extends Instance {
|
||||
configuration: Instancev2Configuration
|
||||
}
|
||||
|
||||
export interface Instancev2Configuration {
|
||||
urls: Instancev2Urls;
|
||||
statuses: Instancev2Statuses
|
||||
}
|
||||
|
||||
export interface InstanceUrls {
|
||||
streaming_api: string;
|
||||
}
|
||||
|
||||
export interface Instancev2Urls {
|
||||
streaming: string;
|
||||
}
|
||||
|
||||
export interface Instancev2Statuses {
|
||||
max_characters: number;
|
||||
}
|
||||
|
||||
export interface Mention {
|
||||
url: string;
|
||||
username: string;
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Store } from '@ngxs/store';
|
|||
|
||||
import { AccountInfo } from '../states/accounts.state';
|
||||
import { MastodonWrapperService } from './mastodon-wrapper.service';
|
||||
import { Account, Results, Status, Emoji } from "./models/mastodon.interfaces";
|
||||
import { Account, Results, Status, Emoji, Instancev2, Instancev1 } from "./models/mastodon.interfaces";
|
||||
import { StatusWrapper } from '../models/common.model';
|
||||
import { AccountSettings, SaveAccountSettings, GlobalSettings, SaveSettings, ContentWarningPolicy, SaveContentWarningPolicy, ContentWarningPolicyEnum, TimeLineModeEnum, TimeLineHeaderEnum } from '../states/settings.state';
|
||||
import { SettingsService } from './settings.service';
|
||||
|
@ -94,7 +94,19 @@ export class ToolsService {
|
|||
const minor = +splittedVersion[1];
|
||||
|
||||
let streamingApi = "";
|
||||
if(instance.urls) streamingApi = instance.urls.streaming_api;
|
||||
|
||||
if (major >= 4) {
|
||||
const instanceV2 = <Instancev2>instance;
|
||||
|
||||
if (instanceV2
|
||||
&& instanceV2.configuration
|
||||
&& instanceV2.configuration.urls)
|
||||
streamingApi = instanceV2.configuration.urls.streaming;
|
||||
} else {
|
||||
const instanceV1 = <Instancev1>instance;
|
||||
if (instanceV1 && instanceV1.urls)
|
||||
streamingApi = instanceV1.urls.streaming_api;
|
||||
}
|
||||
|
||||
let instanceInfo = new InstanceInfo(type, major, minor, streamingApi);
|
||||
this.instanceInfos[acc.instance] = instanceInfo;
|
||||
|
|
Loading…
Reference in New Issue