warn user instead of disallowing unsupported servers
This commit is contained in:
		
							parent
							
								
									1da2789684
								
							
						
					
					
						commit
						e6c5bcf3c3
					
				
					 4 changed files with 15 additions and 31 deletions
				
			
		
							
								
								
									
										4
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										4
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							|  | @ -1,12 +1,12 @@ | ||||||
| { | { | ||||||
|     "name": "spacesocial-client", |     "name": "spacesocial-client", | ||||||
|     "version": "0.1.0", |     "version": "0.1.1", | ||||||
|     "lockfileVersion": 3, |     "lockfileVersion": 3, | ||||||
|     "requires": true, |     "requires": true, | ||||||
|     "packages": { |     "packages": { | ||||||
|         "": { |         "": { | ||||||
|             "name": "spacesocial-client", |             "name": "spacesocial-client", | ||||||
|             "version": "0.1.0", |             "version": "0.1.1", | ||||||
|             "license": "ISC", |             "license": "ISC", | ||||||
|             "devDependencies": { |             "devDependencies": { | ||||||
|                 "@sveltejs/vite-plugin-svelte": "^3.1.1", |                 "@sveltejs/vite-plugin-svelte": "^3.1.1", | ||||||
|  |  | ||||||
|  | @ -93,25 +93,6 @@ export async function getTimeline(last_post_id) { | ||||||
|     }).then(res => res.json()); |     }).then(res => res.json()); | ||||||
| 
 | 
 | ||||||
|     return data; |     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) { | export async function getPost(post_id, num_replies) { | ||||||
|  |  | ||||||
|  | @ -39,13 +39,16 @@ export class Client { | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         this.instance = new Instance(host, data.version); |         this.instance = new Instance(host, data.version); | ||||||
|         if (this.instance.type == server_types.INCOMPATIBLE) { |         if (this.instance.type == server_types.UNSUPPORTED) { | ||||||
|             console.error(`Server ${host} is not supported - ${data.version}`); |             console.warn(`Server ${host} is unsupported - ${data.version}`); | ||||||
|             alert(`Sorry, this app is not compatible with ${host}!`); |             if (!confirm( | ||||||
|             return false; | 		`This app does not officially support ${host}. ` + | ||||||
|         } | 		`Things may break, or otherwise not work as epxected! ` + | ||||||
| 
 | 		`Are you sure you wish to continue?` | ||||||
|         console.log(`Server is "${this.instance.type}" (or compatible) with capabilities: [${this.instance.capabilities}].`); | 	    )) return false; | ||||||
|  |         } else { | ||||||
|  | 	    console.log(`Server is "${this.instance.type}" (or compatible) with capabilities: [${this.instance.capabilities}].`); | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
|         this.app = await api.createApp(host); |         this.app = await api.createApp(host); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,16 +27,16 @@ export class Instance { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #setType(version) { |     #setType(version) { | ||||||
|  | 	this.type = server_types.UNSUPPORTED; | ||||||
|         if (version.constructor !== String) return; |         if (version.constructor !== String) return; | ||||||
|         let version_lower = version.toLowerCase(); |         let version_lower = version.toLowerCase(); | ||||||
|         for (let i = 1; i < Object.keys(server_types).length; i++) { |         for (let i = 1; i < Object.keys(server_types).length; i++) { | ||||||
|             const check_type = Object.values(server_types)[i]; |             const check_type = Object.values(server_types)[i]; | ||||||
|             if (version_lower.includes(check_type)) { |             if (version_lower.includes(check_type)) { | ||||||
|                 this.type = check_type; |                 this.type = check_type; | ||||||
|                 break; | 		return; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if (this.type === server_types.UNSUPPORTED) return; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #getCapabilities(type) { |     #getCapabilities(type) { | ||||||
|  | @ -56,7 +56,7 @@ export class Instance { | ||||||
|             case server_types.ICESHRIMP: |             case server_types.ICESHRIMP: | ||||||
|                 // more trouble than it's worth atm
 |                 // more trouble than it's worth atm
 | ||||||
|                 // the server already hands this to us ;p
 |                 // the server already hands this to us ;p
 | ||||||
|                 // c.push(capabilities.MARKDOWN_CONTENT);
 |                 //c.push(capabilities.MARKDOWN_CONTENT);
 | ||||||
|                 c.push(capabilities.REACTIONS); |                 c.push(capabilities.REACTIONS); | ||||||
|                 break; |                 break; | ||||||
|             case server_types.SHARKEY: |             case server_types.SHARKEY: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue