Use /api/v1/settings/move_followers endpoint to move followers

This commit is contained in:
silverpill 2023-01-09 22:31:39 +00:00
parent f1cd206a39
commit 2be8e2baa0
5 changed files with 31 additions and 47 deletions

View file

@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added "Experiments" section to Settings page (includes "Move Followers" feature).
### Changed
- Use `/api/v1/settings/move_followers` endpoint to move followers.
## [1.9.0] - 2023-01-08
### Added

View file

@ -48,3 +48,22 @@ export async function exportFollows(
const blob = await response.blob()
downloadBlob(blob)
}
export async function moveFollowers(
authToken: string,
fromActorId: string,
followersCsv: string,
): Promise<User> {
const url = `${BACKEND_URL}/api/v1/settings/move_followers`
const response = await http(url, {
method: "POST",
authToken,
json: { from_actor_id: fromActorId, followers_csv: followersCsv },
})
const data = await response.json()
if (response.status !== 200) {
throw new Error(data.message)
} else {
return data
}
}

View file

@ -267,25 +267,6 @@ interface UnsignedActivity {
message: string,
}
export async function getUnsignedMove(
authToken: string,
fromActorId: string,
followersCsv: string,
): Promise<UnsignedActivity> {
const url = `${BACKEND_URL}/api/v1/accounts/move_followers`
const response = await http(url, {
method: "POST",
authToken,
json: { from_actor_id: fromActorId, followers_csv: followersCsv },
})
const data = await response.json()
if (response.status !== 200) {
throw new Error(data.message)
} else {
return data
}
}
export async function getUnsignedUpdate(
authToken: string,
): Promise<UnsignedActivity> {

View file

@ -1,33 +1,10 @@
import {
getUnsignedMove,
getUnsignedUpdate,
sendSignedActivity,
} from "@/api/users"
import { useCurrentUser } from "@/store/user"
import { getWallet, getWalletSignature } from "@/utils/ethereum"
async function signMoveActivity(fromActorId: string, followersCsv: string) {
const { ensureAuthToken } = useCurrentUser()
const signer = await getWallet()
if (!signer) {
return
}
const walletAddress = await signer.getAddress()
const authToken = ensureAuthToken()
const { params, message } = await getUnsignedMove(
authToken,
fromActorId,
followersCsv,
)
const signature = await getWalletSignature(signer, message)
await sendSignedActivity(
authToken,
params,
walletAddress,
signature,
)
}
async function signUpdateActivity(): Promise<void> {
const { ensureAuthToken } = useCurrentUser()
if (!confirm("This action will sign a message with your wallet and send it to your followers. Continue?")) {
@ -51,7 +28,6 @@ async function signUpdateActivity(): Promise<void> {
export function useSignedActivity() {
return {
signMoveActivity,
signUpdateActivity,
}
}

View file

@ -36,13 +36,12 @@
import { $, $ref } from "vue/macros"
import { useRouter } from "vue-router"
import { moveFollowers } from "@/api/settings"
import SidebarLayout from "@/components/SidebarLayout.vue"
import { useSignedActivity } from "@/composables/signed-activity"
import { useCurrentUser } from "@/store/user"
const router = useRouter()
const { currentUser } = $(useCurrentUser())
const { signMoveActivity } = useSignedActivity()
const { currentUser, ensureAuthToken, setCurrentUser } = $(useCurrentUser())
const fromActorId = $ref("")
const followersCsv = $ref("")
@ -55,7 +54,12 @@ async function move() {
if (currentUser === null) {
return
}
await signMoveActivity(fromActorId, followersCsv)
const user = await moveFollowers(
ensureAuthToken(),
fromActorId,
followersCsv,
)
setCurrentUser(user)
router.push({ name: "profile", params: { profileId: currentUser.id } })
}
</script>