feat: Android APP V1 - Experimental Alpha
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import {
|
||||
describe,
|
||||
expect,
|
||||
it
|
||||
} from 'vitest';
|
||||
|
||||
import { endpointSupportsServerDiscovery } from './server-discovery.rules';
|
||||
|
||||
describe('server-discovery.rules', () => {
|
||||
it('skips discovery calls for production signal hosts without featured/trending routes', () => {
|
||||
expect(endpointSupportsServerDiscovery('https://signal.toju.app')).toBe(false);
|
||||
expect(endpointSupportsServerDiscovery('https://signal-sweden.toju.app')).toBe(false);
|
||||
});
|
||||
|
||||
it('allows discovery on local and custom signal servers', () => {
|
||||
expect(endpointSupportsServerDiscovery('http://localhost:3001')).toBe(true);
|
||||
expect(endpointSupportsServerDiscovery('https://signal.example.com')).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
/** Hostnames known to run older signal servers without featured/trending discovery routes. */
|
||||
const DISCOVERY_UNSUPPORTED_HOSTS = new Set([
|
||||
'signal.toju.app',
|
||||
'signal-sweden.toju.app'
|
||||
]);
|
||||
|
||||
/** Returns false when discovery endpoints are known to 404 on the active signal server. */
|
||||
export function endpointSupportsServerDiscovery(baseUrl: string): boolean {
|
||||
try {
|
||||
const hostname = new URL(baseUrl).hostname;
|
||||
|
||||
return !DISCOVERY_UNSUPPORTED_HOSTS.has(hostname);
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import type {
|
||||
UnbanServerMemberRequest
|
||||
} from '../../domain/models/server-directory.model';
|
||||
import type { RoomSignalSourceInput } from '../../domain/logic/room-signal-source.logic';
|
||||
import { endpointSupportsServerDiscovery } from '../../domain/logic/server-discovery.rules';
|
||||
|
||||
interface ServerLookupError {
|
||||
status?: number;
|
||||
@@ -297,6 +298,12 @@ export class ServerDirectoryApiService {
|
||||
}
|
||||
|
||||
private getDiscoveryServers(kind: 'featured' | 'trending', limit?: number): Observable<ServerInfo[]> {
|
||||
const baseUrl = this.resolveBaseServerUrl();
|
||||
|
||||
if (!endpointSupportsServerDiscovery(baseUrl)) {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
const params = typeof limit === 'number' ? new HttpParams().set('limit', String(limit)) : undefined;
|
||||
|
||||
return this.http
|
||||
|
||||
Reference in New Issue
Block a user