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 {
|
import {
|
||||||
getAccount as getAccountFromDatabase,
|
getAccount as getAccountFromDatabase,
|
||||||
setAccount as setAccountInDatabase,
|
setAccount as setAccountInDatabase} from '../_database/accounts'
|
||||||
|
import {
|
||||||
getRelationship as getRelationshipFromDatabase,
|
getRelationship as getRelationshipFromDatabase,
|
||||||
setRelationship as setRelationshipInDatabase
|
setRelationship as setRelationshipInDatabase
|
||||||
} from '../_database/accountsAndRelationships'
|
} from '../_database/relationships'
|
||||||
import { store } from '../_store/store'
|
import { store } from '../_store/store'
|
||||||
|
|
||||||
async function updateAccount (accountId, instanceName, accessToken) {
|
async function updateAccount (accountId, instanceName, accessToken) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { toast } from '../_utils/toast'
|
||||||
import { updateProfileAndRelationship } from './accounts'
|
import { updateProfileAndRelationship } from './accounts'
|
||||||
import {
|
import {
|
||||||
getRelationship as getRelationshipFromDatabase
|
getRelationship as getRelationshipFromDatabase
|
||||||
} from '../_database/accountsAndRelationships'
|
} from '../_database/relationships'
|
||||||
|
|
||||||
export async function setAccountFollowed (accountId, follow, toastOnSuccess) {
|
export async function setAccountFollowed (accountId, follow, toastOnSuccess) {
|
||||||
let { currentInstance, accessToken } = store.get()
|
let { currentInstance, accessToken } = store.get()
|
||||||
|
|
22
routes/_actions/setShowReblogs.js
Normal file
22
routes/_actions/setShowReblogs.js
Normal file
|
@ -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 || ''))
|
||||||
|
}
|
||||||
|
}
|
8
routes/_api/relationships.js
Normal file
8
routes/_api/relationships.js
Normal file
|
@ -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]
|
||||||
|
}
|
7
routes/_api/showReblogs.js
Normal file
7
routes/_api/showReblogs.js
Normal file
|
@ -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'
|
import { auth, basename } from './utils'
|
||||||
|
|
||||||
export function getVerifyCredentials (instanceName, accessToken) {
|
export function getVerifyCredentials (instanceName, accessToken) {
|
||||||
|
@ -10,10 +10,3 @@ export function getAccount (instanceName, accessToken, accountId) {
|
||||||
let url = `${basename(instanceName)}/api/v1/accounts/${accountId}`
|
let url = `${basename(instanceName)}/api/v1/accounts/${accountId}`
|
||||||
return get(url, auth(accessToken), {timeout: DEFAULT_TIMEOUT})
|
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 { setAccountBlocked } from '../../../_actions/block'
|
||||||
import { setAccountMuted } from '../../../_actions/mute'
|
import { setAccountMuted } from '../../../_actions/mute'
|
||||||
import { setAccountFollowed } from '../../../_actions/follow'
|
import { setAccountFollowed } from '../../../_actions/follow'
|
||||||
|
import { setShowReblogs } from '../../../_actions/setShowReblogs'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
oncreate,
|
oncreate,
|
||||||
|
@ -59,10 +60,16 @@ export default {
|
||||||
//
|
//
|
||||||
// end copypasta (StatusOptionsDialog.html / AccountProfileOptionsDialog.html)
|
// end copypasta (StatusOptionsDialog.html / AccountProfileOptionsDialog.html)
|
||||||
//
|
//
|
||||||
|
showingReblogs: ({ relationship }) => !!relationship.showing_reblogs,
|
||||||
|
showReblogsLabel: ({ showingReblogs, acct }) => (
|
||||||
|
showingReblogs
|
||||||
|
? `Hide boosts from @${acct}`
|
||||||
|
: `Show boosts from @${acct}`
|
||||||
|
),
|
||||||
items: ({
|
items: ({
|
||||||
blockLabel, blocking, blockIcon, muteLabel, muteIcon,
|
blockLabel, blocking, blockIcon, muteLabel, muteIcon,
|
||||||
followLabel, followIcon, following, followRequested,
|
followLabel, followIcon, following, followRequested,
|
||||||
accountId, verifyCredentialsId, acct, isUser
|
accountId, verifyCredentialsId, acct, isUser, showReblogsLabel
|
||||||
}) => ([
|
}) => ([
|
||||||
!isUser && {
|
!isUser && {
|
||||||
key: 'mention',
|
key: 'mention',
|
||||||
|
@ -84,6 +91,11 @@ export default {
|
||||||
label: muteLabel,
|
label: muteLabel,
|
||||||
icon: muteIcon
|
icon: muteIcon
|
||||||
},
|
},
|
||||||
|
!isUser && following && {
|
||||||
|
key: 'showReblogs',
|
||||||
|
label: showReblogsLabel,
|
||||||
|
icon: '#fa-retweet'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'copy',
|
key: 'copy',
|
||||||
label: 'Copy link to account',
|
label: 'Copy link to account',
|
||||||
|
@ -106,6 +118,8 @@ export default {
|
||||||
return this.onMuteClicked()
|
return this.onMuteClicked()
|
||||||
case 'copy':
|
case 'copy':
|
||||||
return this.onCopyClicked()
|
return this.onCopyClicked()
|
||||||
|
case 'showReblogs':
|
||||||
|
return this.onShowReblogsClicked()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async onMentionClicked () {
|
async onMentionClicked () {
|
||||||
|
@ -132,6 +146,11 @@ export default {
|
||||||
this.close()
|
this.close()
|
||||||
await setAccountMuted(accountId, !muting, true)
|
await setAccountMuted(accountId, !muting, true)
|
||||||
},
|
},
|
||||||
|
async onShowReblogsClicked () {
|
||||||
|
let { accountId, showingReblogs } = this.get()
|
||||||
|
this.close()
|
||||||
|
await setShowReblogs(accountId, !showingReblogs, true)
|
||||||
|
},
|
||||||
async onCopyClicked () {
|
async onCopyClicked () {
|
||||||
let { account } = this.get()
|
let { account } = this.get()
|
||||||
let { url } = account
|
let { url } = account
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import {
|
import { ACCOUNTS_STORE, USERNAME_LOWERCASE } from './constants'
|
||||||
ACCOUNTS_STORE, RELATIONSHIPS_STORE, USERNAME_LOWERCASE
|
import { accountsCache } from './cache'
|
||||||
} from './constants'
|
|
||||||
import { accountsCache, relationshipsCache } from './cache'
|
|
||||||
import { cloneForStorage, getGenericEntityWithId, setGenericEntityWithId } from './helpers'
|
import { cloneForStorage, getGenericEntityWithId, setGenericEntityWithId } from './helpers'
|
||||||
import { dbPromise, getDatabase } from './databaseLifecycle'
|
import { dbPromise, getDatabase } from './databaseLifecycle'
|
||||||
import { createAccountUsernamePrefixKeyRange } from './keys'
|
import { createAccountUsernamePrefixKeyRange } from './keys'
|
||||||
|
@ -14,14 +12,6 @@ export async function setAccount (instanceName, account) {
|
||||||
return setGenericEntityWithId(ACCOUNTS_STORE, accountsCache, instanceName, cloneForStorage(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) {
|
export async function searchAccountsByUsername (instanceName, usernamePrefix, limit = 20) {
|
||||||
const db = await getDatabase(instanceName)
|
const db = await getDatabase(instanceName)
|
||||||
return dbPromise(db, ACCOUNTS_STORE, 'readonly', (accountsStore, callback) => {
|
return dbPromise(db, ACCOUNTS_STORE, 'readonly', (accountsStore, callback) => {
|
11
routes/_database/relationships.js
Normal file
11
routes/_database/relationships.js
Normal file
|
@ -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 {
|
import {
|
||||||
searchAccountsByUsername as searchAccountsByUsernameInDatabase
|
searchAccountsByUsername as searchAccountsByUsernameInDatabase
|
||||||
} from '../../_database/accountsAndRelationships'
|
} from '../../_database/accounts'
|
||||||
|
|
||||||
const SEARCH_RESULTS_LIMIT = 4
|
const SEARCH_RESULTS_LIMIT = 4
|
||||||
const DATABASE_SEARCH_RESULTS_LIMIT = 30
|
const DATABASE_SEARCH_RESULTS_LIMIT = 30
|
||||||
|
|
Loading…
Reference in a new issue