* remove get() with string pt 1 * remove get() with string pt 2 * fix typo * fix some null exceptions in get() * fixup code style
		
			
				
	
	
		
			25 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import { store } from '../_store/store'
 | 
						|
import { toast } from '../_utils/toast'
 | 
						|
import { reblogStatus, unreblogStatus } from '../_api/reblog'
 | 
						|
import { setStatusReblogged as setStatusRebloggedInDatabase } from '../_database/timelines/updateStatus'
 | 
						|
 | 
						|
export async function setReblogged (statusId, reblogged) {
 | 
						|
  let online = store.get()
 | 
						|
  if (!online) {
 | 
						|
    toast.say(`You cannot ${reblogged ? 'boost' : 'unboost'} while offline.`)
 | 
						|
    return
 | 
						|
  }
 | 
						|
  let { currentInstance, accessToken } = store.get()
 | 
						|
  let networkPromise = reblogged
 | 
						|
    ? reblogStatus(currentInstance, accessToken, statusId)
 | 
						|
    : unreblogStatus(currentInstance, accessToken, statusId)
 | 
						|
  store.setStatusReblogged(currentInstance, statusId, reblogged) // optimistic update
 | 
						|
  try {
 | 
						|
    await networkPromise
 | 
						|
    await setStatusRebloggedInDatabase(currentInstance, statusId, reblogged)
 | 
						|
  } catch (e) {
 | 
						|
    console.error(e)
 | 
						|
    toast.say(`Failed to ${reblogged ? 'boost' : 'unboost'}. ` + (e.message || ''))
 | 
						|
    store.setStatusReblogged(currentInstance, statusId, !reblogged) // undo optimistic update
 | 
						|
  }
 | 
						|
}
 |