Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
fix(profiles): consolidate a ton of redundantly copied-and-pasted rec…
Browse files Browse the repository at this point in the history
…ord() calls with helper functions
  • Loading branch information
jpezninjo committed Oct 18, 2023
1 parent a680560 commit b5e74b5
Showing 1 changed file with 23 additions and 56 deletions.
79 changes: 23 additions & 56 deletions composables/masto/relationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ async function fetchRelationships() {
requested[i][1].value = relationships[i]
}

function recordEngagement(dataGlean: string, account: mastodon.v1.Account) {
engagement.record({
ui_identifier: dataGlean,
mastodon_account_id: account.id,
mastodon_account_handle: account.acct,
...engagementDetails[dataGlean],
})
}

export async function toggleFollowAccount(relationship: mastodon.v1.Relationship, account: mastodon.v1.Account, dataGlean?: string) {
const { client } = $(useMasto())
const i18n = useNuxtApp().$i18n
Expand All @@ -49,14 +58,8 @@ export async function toggleFollowAccount(relationship: mastodon.v1.Relationship
}) !== 'confirm')
return

if (dataGlean) {
engagement.record({
ui_identifier: dataGlean,
mastodon_account_id: account.id,
mastodon_account_handle: account.acct,
...engagementDetails[dataGlean],
})
}
if (dataGlean)
recordEngagement(dataGlean, account)
}

if (unfollow) {
Expand Down Expand Up @@ -85,24 +88,12 @@ export async function toggleMuteAccount(relationship: mastodon.v1.Relationship,
}) !== 'confirm')
return

if (dataGlean) {
engagement.record({
ui_identifier: dataGlean,
mastodon_account_id: account.id,
mastodon_account_handle: account.acct,
...engagementDetails[dataGlean],
})
}
if (dataGlean)
recordEngagement(dataGlean, account)
}
else {
if (dataGlean) {
engagement.record({
ui_identifier: dataGlean,
mastodon_account_id: account.id,
mastodon_account_handle: account.acct,
...engagementDetails[dataGlean],
})
}
if (dataGlean)
recordEngagement(dataGlean, account)
}

relationship!.muting = !relationship!.muting
Expand All @@ -125,24 +116,12 @@ export async function toggleBlockAccount(relationship: mastodon.v1.Relationship,
}) !== 'confirm')
return

if (dataGlean) {
engagement.record({
ui_identifier: dataGlean,
mastodon_account_id: account.id,
mastodon_account_handle: account.acct,
...engagementDetails[dataGlean],
})
}
if (dataGlean)
recordEngagement(dataGlean, account)
}
else {
if (dataGlean) {
engagement.record({
ui_identifier: dataGlean,
mastodon_account_id: account.id,
mastodon_account_handle: account.acct,
...engagementDetails[dataGlean],
})
}
if (dataGlean)
recordEngagement(dataGlean, account)
}

relationship!.blocking = !relationship!.blocking
Expand All @@ -161,24 +140,12 @@ export async function toggleBlockDomain(relationship: mastodon.v1.Relationship,
}) !== 'confirm')
return

if (dataGlean) {
engagement.record({
ui_identifier: dataGlean,
mastodon_account_id: account.id,
mastodon_account_handle: account.acct,
...engagementDetails[dataGlean],
})
}
if (dataGlean)
recordEngagement(dataGlean, account)
}
else {
if (dataGlean) {
engagement.record({
ui_identifier: dataGlean,
mastodon_account_id: account.id,
mastodon_account_handle: account.acct,
...engagementDetails[dataGlean],
})
}
if (dataGlean)
recordEngagement(dataGlean, account)
}

relationship!.domainBlocking = !relationship!.domainBlocking
Expand Down

0 comments on commit b5e74b5

Please sign in to comment.