forked from cybrespace/pinafore
Add ability to show/hide boosts from accounts (#491)
Fixes some stuff in #6
This commit is contained in:
parent
dc091f1360
commit
d6af3b69a7
|
@ -1,10 +1,12 @@
|
|||
import { getAccount, getRelationship } from '../_api/user'
|
||||
import { getAccount } from '../_api/user'
|
||||
import { getRelationship } from '../_api/relationships'
|
||||
import {
|
||||
getAccount as getAccountFromDatabase,
|
||||
setAccount as setAccountInDatabase,
|
||||
setAccount as setAccountInDatabase} from '../_database/accounts'
|
||||
import {
|
||||
getRelationship as getRelationshipFromDatabase,
|
||||
setRelationship as setRelationshipInDatabase
|
||||
} from '../_database/accountsAndRelationships'
|
||||
} from '../_database/relationships'
|
||||
import { store } from '../_store/store'
|
||||
|
||||
async function updateAccount (accountId, instanceName, accessToken) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { toast } from '../_utils/toast'
|
|||
import { updateProfileAndRelationship } from './accounts'
|
||||
import {
|
||||
getRelationship as getRelationshipFromDatabase
|
||||
} from '../_database/accountsAndRelationships'
|
||||
} from '../_database/relationships'
|
||||
|
||||
export async function setAccountFollowed (accountId, follow, toastOnSuccess) {
|
||||
let { currentInstance, accessToken } = store.get()
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import { store } from '../_store/store'
|
||||
import { setShowReblogs as setShowReblogsApi } from '../_api/showReblogs'
|
||||
import { toast } from '../_utils/toast'
|
||||
import { updateProfileAndRelationship } from './accounts'
|
||||
|
||||
export async function setShowReblogs (accountId, showReblogs, toastOnSuccess) {
|
||||
let { currentInstance, accessToken } = store.get()
|
||||
try {
|
||||
await setShowReblogsApi(currentInstance, accessToken, accountId, showReblogs)
|
||||
await updateProfileAndRelationship(accountId)
|
||||
if (toastOnSuccess) {
|
||||
if (showReblogs) {
|
||||
toast.say('Showing boosts')
|
||||
} else {
|
||||
toast.say('Hiding boosts')
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
toast.say(`Unable to ${showReblogs ? 'show' : 'hide'} boosts: ` + (e.message || ''))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
import { basename, auth } from './utils'
|
||||
import { get, paramsString, DEFAULT_TIMEOUT } from '../_utils/ajax'
|
||||
|
||||
export async function getRelationship (instanceName, accessToken, accountId) {
|
||||
let url = `${basename(instanceName)}/api/v1/accounts/relationships?${paramsString({id: accountId})}`
|
||||
let res = await get(url, auth(accessToken), {timeout: DEFAULT_TIMEOUT})
|
||||
return res[0]
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import { auth, basename } from './utils'
|
||||
import { post, WRITE_TIMEOUT } from '../_utils/ajax'
|
||||
|
||||
export function setShowReblogs (instanceName, accessToken, accountId, showReblogs) {
|
||||
let url = `${basename(instanceName)}/api/v1/accounts/${accountId}/follow`
|
||||
return post(url, { reblogs: !!showReblogs }, auth(accessToken), {timeout: WRITE_TIMEOUT})
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { get, paramsString, DEFAULT_TIMEOUT } from '../_utils/ajax'
|
||||
import { get, DEFAULT_TIMEOUT } from '../_utils/ajax'
|
||||
import { auth, basename } from './utils'
|
||||
|
||||
export function getVerifyCredentials (instanceName, accessToken) {
|
||||
|
@ -10,10 +10,3 @@ export function getAccount (instanceName, accessToken, accountId) {
|
|||
let url = `${basename(instanceName)}/api/v1/accounts/${accountId}`
|
||||
return get(url, auth(accessToken), {timeout: DEFAULT_TIMEOUT})
|
||||
}
|
||||
|
||||
export async function getRelationship (instanceName, accessToken, accountId) {
|
||||
let url = `${basename(instanceName)}/api/v1/accounts/relationships`
|
||||
url += '?' + paramsString({id: accountId})
|
||||
let res = await get(url, auth(accessToken), {timeout: DEFAULT_TIMEOUT})
|
||||
return res[0]
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import { oncreate } from '../helpers/onCreateDialog'
|
|||
import { setAccountBlocked } from '../../../_actions/block'
|
||||
import { setAccountMuted } from '../../../_actions/mute'
|
||||
import { setAccountFollowed } from '../../../_actions/follow'
|
||||
import { setShowReblogs } from '../../../_actions/setShowReblogs'
|
||||
|
||||
export default {
|
||||
oncreate,
|
||||
|
@ -59,10 +60,16 @@ export default {
|
|||
//
|
||||
// end copypasta (StatusOptionsDialog.html / AccountProfileOptionsDialog.html)
|
||||
//
|
||||
showingReblogs: ({ relationship }) => !!relationship.showing_reblogs,
|
||||
showReblogsLabel: ({ showingReblogs, acct }) => (
|
||||
showingReblogs
|
||||
? `Hide boosts from @${acct}`
|
||||
: `Show boosts from @${acct}`
|
||||
),
|
||||
items: ({
|
||||
blockLabel, blocking, blockIcon, muteLabel, muteIcon,
|
||||
followLabel, followIcon, following, followRequested,
|
||||
accountId, verifyCredentialsId, acct, isUser
|
||||
accountId, verifyCredentialsId, acct, isUser, showReblogsLabel
|
||||
}) => ([
|
||||
!isUser && {
|
||||
key: 'mention',
|
||||
|
@ -84,6 +91,11 @@ export default {
|
|||
label: muteLabel,
|
||||
icon: muteIcon
|
||||
},
|
||||
!isUser && following && {
|
||||
key: 'showReblogs',
|
||||
label: showReblogsLabel,
|
||||
icon: '#fa-retweet'
|
||||
},
|
||||
{
|
||||
key: 'copy',
|
||||
label: 'Copy link to account',
|
||||
|
@ -106,6 +118,8 @@ export default {
|
|||
return this.onMuteClicked()
|
||||
case 'copy':
|
||||
return this.onCopyClicked()
|
||||
case 'showReblogs':
|
||||
return this.onShowReblogsClicked()
|
||||
}
|
||||
},
|
||||
async onMentionClicked () {
|
||||
|
@ -132,6 +146,11 @@ export default {
|
|||
this.close()
|
||||
await setAccountMuted(accountId, !muting, true)
|
||||
},
|
||||
async onShowReblogsClicked () {
|
||||
let { accountId, showingReblogs } = this.get()
|
||||
this.close()
|
||||
await setShowReblogs(accountId, !showingReblogs, true)
|
||||
},
|
||||
async onCopyClicked () {
|
||||
let { account } = this.get()
|
||||
let { url } = account
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import {
|
||||
ACCOUNTS_STORE, RELATIONSHIPS_STORE, USERNAME_LOWERCASE
|
||||
} from './constants'
|
||||
import { accountsCache, relationshipsCache } from './cache'
|
||||
import { ACCOUNTS_STORE, USERNAME_LOWERCASE } from './constants'
|
||||
import { accountsCache } from './cache'
|
||||
import { cloneForStorage, getGenericEntityWithId, setGenericEntityWithId } from './helpers'
|
||||
import { dbPromise, getDatabase } from './databaseLifecycle'
|
||||
import { createAccountUsernamePrefixKeyRange } from './keys'
|
||||
|
@ -14,14 +12,6 @@ export async function setAccount (instanceName, account) {
|
|||
return setGenericEntityWithId(ACCOUNTS_STORE, accountsCache, instanceName, cloneForStorage(account))
|
||||
}
|
||||
|
||||
export async function getRelationship (instanceName, accountId) {
|
||||
return getGenericEntityWithId(RELATIONSHIPS_STORE, relationshipsCache, instanceName, accountId)
|
||||
}
|
||||
|
||||
export async function setRelationship (instanceName, relationship) {
|
||||
return setGenericEntityWithId(RELATIONSHIPS_STORE, relationshipsCache, instanceName, cloneForStorage(relationship))
|
||||
}
|
||||
|
||||
export async function searchAccountsByUsername (instanceName, usernamePrefix, limit = 20) {
|
||||
const db = await getDatabase(instanceName)
|
||||
return dbPromise(db, ACCOUNTS_STORE, 'readonly', (accountsStore, callback) => {
|
|
@ -0,0 +1,11 @@
|
|||
import { cloneForStorage, getGenericEntityWithId, setGenericEntityWithId } from './helpers'
|
||||
import { RELATIONSHIPS_STORE } from './constants'
|
||||
import { relationshipsCache } from './cache'
|
||||
|
||||
export async function getRelationship (instanceName, accountId) {
|
||||
return getGenericEntityWithId(RELATIONSHIPS_STORE, relationshipsCache, instanceName, accountId)
|
||||
}
|
||||
|
||||
export async function setRelationship (instanceName, relationship) {
|
||||
return setGenericEntityWithId(RELATIONSHIPS_STORE, relationshipsCache, instanceName, cloneForStorage(relationship))
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import {
|
||||
searchAccountsByUsername as searchAccountsByUsernameInDatabase
|
||||
} from '../../_database/accountsAndRelationships'
|
||||
} from '../../_database/accounts'
|
||||
|
||||
const SEARCH_RESULTS_LIMIT = 4
|
||||
const DATABASE_SEARCH_RESULTS_LIMIT = 30
|
||||
|
|
Loading…
Reference in New Issue