warn user instead of disallowing unsupported servers

This commit is contained in:
ari melody 2024-06-22 16:35:41 +01:00
parent 1da2789684
commit e6c5bcf3c3
4 changed files with 15 additions and 31 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "spacesocial-client",
"version": "0.1.0",
"version": "0.1.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "spacesocial-client",
"version": "0.1.0",
"version": "0.1.1",
"license": "ISC",
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.1.1",

View file

@ -93,25 +93,6 @@ export async function getTimeline(last_post_id) {
}).then(res => res.json());
return data;
let posts = [];
for (let i in data) {
const post_data = data[i];
const post = await parsePost(post_data, 1);
if (!post) {
if (post === null || post === undefined) {
if (post_data.id) {
console.warn("Failed to parse post #" + post_data.id);
} else {
console.warn("Failed to parse post:");
console.warn(post_data);
}
}
continue;
}
posts.push(post);
}
return posts;
}
export async function getPost(post_id, num_replies) {

View file

@ -39,13 +39,16 @@ export class Client {
}
this.instance = new Instance(host, data.version);
if (this.instance.type == server_types.INCOMPATIBLE) {
console.error(`Server ${host} is not supported - ${data.version}`);
alert(`Sorry, this app is not compatible with ${host}!`);
return false;
}
console.log(`Server is "${this.instance.type}" (or compatible) with capabilities: [${this.instance.capabilities}].`);
if (this.instance.type == server_types.UNSUPPORTED) {
console.warn(`Server ${host} is unsupported - ${data.version}`);
if (!confirm(
`This app does not officially support ${host}. ` +
`Things may break, or otherwise not work as epxected! ` +
`Are you sure you wish to continue?`
)) return false;
} else {
console.log(`Server is "${this.instance.type}" (or compatible) with capabilities: [${this.instance.capabilities}].`);
}
this.app = await api.createApp(host);

View file

@ -27,16 +27,16 @@ export class Instance {
}
#setType(version) {
this.type = server_types.UNSUPPORTED;
if (version.constructor !== String) return;
let version_lower = version.toLowerCase();
for (let i = 1; i < Object.keys(server_types).length; i++) {
const check_type = Object.values(server_types)[i];
if (version_lower.includes(check_type)) {
this.type = check_type;
break;
return;
}
}
if (this.type === server_types.UNSUPPORTED) return;
}
#getCapabilities(type) {
@ -56,7 +56,7 @@ export class Instance {
case server_types.ICESHRIMP:
// more trouble than it's worth atm
// the server already hands this to us ;p
// c.push(capabilities.MARKDOWN_CONTENT);
//c.push(capabilities.MARKDOWN_CONTENT);
c.push(capabilities.REACTIONS);
break;
case server_types.SHARKEY: