Skip to content

Commit

Permalink
ensure to propagate errors when bsyncOnlyMutes is on
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Jan 22, 2024
1 parent 7b600b6 commit b1db937
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 48 deletions.
33 changes: 21 additions & 12 deletions packages/bsky/src/api/app/bsky/graph/muteActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { InvalidRequestError } from '@atproto/xrpc-server'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { MuteOperation_Type } from '../../../../proto/bsync_pb'
import { BsyncClient } from '../../../../bsync'

export default function (server: Server, ctx: AppContext) {
server.app.bsky.graph.muteActor({
Expand All @@ -20,24 +21,32 @@ export default function (server: Server, ctx: AppContext) {
throw new InvalidRequestError('Cannot mute oneself')
}

if (!ctx.cfg.bsyncOnlyMutes) {
const muteActor = async () => {
await ctx.services.graph(db).muteActor({
subjectDid,
mutedByDid: requester,
})
} else {
assert(ctx.bsyncClient)
}

if (ctx.bsyncClient) {
try {
await ctx.bsyncClient.addMuteOperation({
type: MuteOperation_Type.ADD,
actorDid: requester,
subject: subjectDid,
})
} catch (err) {
req.log.warn(err, 'failed to sync mute op to bsync')
const addBsyncMuteOp = async (bsyncClient: BsyncClient) => {
await bsyncClient.addMuteOperation({
type: MuteOperation_Type.ADD,
actorDid: requester,
subject: subjectDid,
})
}

if (ctx.cfg.bsyncOnlyMutes) {
assert(ctx.bsyncClient)
await addBsyncMuteOp(ctx.bsyncClient)
} else {
await muteActor()
if (ctx.bsyncClient) {
try {
await addBsyncMuteOp(ctx.bsyncClient)
} catch (err) {
req.log.warn(err, 'failed to sync mute op to bsync')
}
}
}
},
Expand Down
33 changes: 21 additions & 12 deletions packages/bsky/src/api/app/bsky/graph/muteActorList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as lex from '../../../../lexicon/lexicons'
import AppContext from '../../../../context'
import { AtUri } from '@atproto/syntax'
import { MuteOperation_Type } from '../../../../proto/bsync_pb'
import { BsyncClient } from '../../../../bsync'

export default function (server: Server, ctx: AppContext) {
server.app.bsky.graph.muteActorList({
Expand All @@ -21,24 +22,32 @@ export default function (server: Server, ctx: AppContext) {
throw new InvalidRequestError(`Invalid collection: expected: ${collId}`)
}

if (!ctx.cfg.bsyncOnlyMutes) {
const muteActorList = async () => {
await ctx.services.graph(db).muteActorList({
list,
mutedByDid: requester,
})
} else {
assert(ctx.bsyncClient)
}

if (ctx.bsyncClient) {
try {
await ctx.bsyncClient.addMuteOperation({
type: MuteOperation_Type.ADD,
actorDid: requester,
subject: list,
})
} catch (err) {
req.log.warn(err, 'failed to sync mute op to bsync')
const addBsyncMuteOp = async (bsyncClient: BsyncClient) => {
await bsyncClient.addMuteOperation({
type: MuteOperation_Type.ADD,
actorDid: requester,
subject: list,
})
}

if (ctx.cfg.bsyncOnlyMutes) {
assert(ctx.bsyncClient)
await addBsyncMuteOp(ctx.bsyncClient)
} else {
await muteActorList()
if (ctx.bsyncClient) {
try {
await addBsyncMuteOp(ctx.bsyncClient)
} catch (err) {
req.log.warn(err, 'failed to sync mute op to bsync')
}
}
}
},
Expand Down
33 changes: 21 additions & 12 deletions packages/bsky/src/api/app/bsky/graph/unmuteActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { InvalidRequestError } from '@atproto/xrpc-server'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { MuteOperation_Type } from '../../../../proto/bsync_pb'
import { BsyncClient } from '../../../../bsync'

export default function (server: Server, ctx: AppContext) {
server.app.bsky.graph.unmuteActor({
Expand All @@ -20,24 +21,32 @@ export default function (server: Server, ctx: AppContext) {
throw new InvalidRequestError('Cannot mute oneself')
}

if (!ctx.cfg.bsyncOnlyMutes) {
const unmuteActor = async () => {
await ctx.services.graph(db).unmuteActor({
subjectDid,
mutedByDid: requester,
})
} else {
assert(ctx.bsyncClient)
}

if (ctx.bsyncClient) {
try {
await ctx.bsyncClient.addMuteOperation({
type: MuteOperation_Type.REMOVE,
actorDid: requester,
subject: subjectDid,
})
} catch (err) {
req.log.warn(err, 'failed to sync mute op to bsync')
const addBsyncMuteOp = async (bsyncClient: BsyncClient) => {
await bsyncClient.addMuteOperation({
type: MuteOperation_Type.REMOVE,
actorDid: requester,
subject: subjectDid,
})
}

if (ctx.cfg.bsyncOnlyMutes) {
assert(ctx.bsyncClient)
await addBsyncMuteOp(ctx.bsyncClient)
} else {
await unmuteActor()
if (ctx.bsyncClient) {
try {
await addBsyncMuteOp(ctx.bsyncClient)
} catch (err) {
req.log.warn(err, 'failed to sync mute op to bsync')
}
}
}
},
Expand Down
33 changes: 21 additions & 12 deletions packages/bsky/src/api/app/bsky/graph/unmuteActorList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from 'node:assert'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { MuteOperation_Type } from '../../../../proto/bsync_pb'
import { BsyncClient } from '../../../../bsync'

export default function (server: Server, ctx: AppContext) {
server.app.bsky.graph.unmuteActorList({
Expand All @@ -11,24 +12,32 @@ export default function (server: Server, ctx: AppContext) {
const requester = auth.credentials.iss
const db = ctx.db.getPrimary()

if (!ctx.cfg.bsyncOnlyMutes) {
const unmuteActorList = async () => {
await ctx.services.graph(db).unmuteActorList({
list,
mutedByDid: requester,
})
} else {
assert(ctx.bsyncClient)
}

if (ctx.bsyncClient) {
try {
await ctx.bsyncClient.addMuteOperation({
type: MuteOperation_Type.REMOVE,
actorDid: requester,
subject: list,
})
} catch (err) {
req.log.warn(err, 'failed to sync mute op to bsync')
const addBsyncMuteOp = async (bsyncClient: BsyncClient) => {
await bsyncClient.addMuteOperation({
type: MuteOperation_Type.REMOVE,
actorDid: requester,
subject: list,
})
}

if (ctx.cfg.bsyncOnlyMutes) {
assert(ctx.bsyncClient)
await addBsyncMuteOp(ctx.bsyncClient)
} else {
await unmuteActorList()
if (ctx.bsyncClient) {
try {
await addBsyncMuteOp(ctx.bsyncClient)
} catch (err) {
req.log.warn(err, 'failed to sync mute op to bsync')
}
}
}
},
Expand Down

0 comments on commit b1db937

Please sign in to comment.