ssb: Only admins are offered the option to enable peer exchange.
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build Tilde Friends / Build-All (push) Successful in 32m49s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build Tilde Friends / Build-All (push) Successful in 32m49s
				
			This commit is contained in:
		| @@ -112,6 +112,9 @@ tfrpc.register(async function globalSettingsGet(key) { | ||||
| tfrpc.register(async function globalSettingsSet(key, value) { | ||||
| 	return core.globalSettingsSet(key, value); | ||||
| }); | ||||
| tfrpc.register(function isAdministrator() { | ||||
| 	return core.user?.credentials?.permissions?.administration; | ||||
| }); | ||||
|  | ||||
| core.register('onBroadcastsChanged', async function () { | ||||
| 	await tfrpc.rpc.set('broadcasts', await ssb.getBroadcasts()); | ||||
|   | ||||
| @@ -49,9 +49,7 @@ class TfTabNewsElement extends LitElement { | ||||
| 		tfrpc.rpc.localStorageGet('drafts').then(function (d) { | ||||
| 			self.drafts = JSON.parse(d || '{}'); | ||||
| 		}); | ||||
| 		tfrpc.rpc.globalSettingsGet('peer_exchange').then(function (value) { | ||||
| 			self.peer_exchange = value; | ||||
| 		}); | ||||
| 		this.check_peer_exchange(); | ||||
| 	} | ||||
|  | ||||
| 	connectedCallback() { | ||||
| @@ -64,6 +62,14 @@ class TfTabNewsElement extends LitElement { | ||||
| 		document.body.removeEventListener('keypress', this.on_keypress.bind(this)); | ||||
| 	} | ||||
|  | ||||
| 	async check_peer_exchange() { | ||||
| 		if (await tfrpc.rpc.isAdministrator()) { | ||||
| 			this.peer_exchange = await tfrpc.rpc.globalSettingsGet('peer_exchange'); | ||||
| 		} else { | ||||
| 			this.peer_exchange = undefined; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	load_latest() { | ||||
| 		let news = this.shadowRoot?.getElementById('news'); | ||||
| 		if (news) { | ||||
| @@ -174,7 +180,7 @@ class TfTabNewsElement extends LitElement { | ||||
|  | ||||
| 	async enable_peer_exchange() { | ||||
| 		await tfrpc.rpc.globalSettingsSet('peer_exchange', true); | ||||
| 		this.peer_exchange = await tfrpc.rpc.globalSettingsGet('peer_exchange'); | ||||
| 		await this.check_peer_exchange(); | ||||
| 	} | ||||
|  | ||||
| 	render_sidebar() { | ||||
| @@ -266,7 +272,7 @@ class TfTabNewsElement extends LitElement { | ||||
| 							</button> | ||||
| 							<button | ||||
| 								class=${'w3-bar-item w3-button' + | ||||
| 								(this.peer_exchange ? ' w3-hide' : '')} | ||||
| 								(this.peer_exchange !== false ? ' w3-hide' : '')} | ||||
| 								@click=${this.enable_peer_exchange} | ||||
| 							> | ||||
| 								Enable peer exchange | ||||
|   | ||||
		Reference in New Issue
	
	Block a user