-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Appview v1 generating and ingesting mute ops w/ bsync (#2067)
* build bsync protos in appview, standardize per-package proto gen directory * configure appview with bsync, allow mute endpoints to use bsync * import fixes in bsync * configure appview ingester with bsync, ingest mute ops into db * test bsync mutes roundtrip w/ appview, setup bsync in dev-env * build * ensure to propagate errors when bsyncOnlyMutes is on
- Loading branch information
Showing
32 changed files
with
1,274 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: v1 | ||
plugins: | ||
- plugin: es | ||
opt: | ||
- target=ts | ||
- import_extension=.ts | ||
out: src/proto | ||
- plugin: connect-es | ||
opt: | ||
- target=ts | ||
- import_extension=.ts | ||
out: src/proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,45 @@ | ||
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({ | ||
auth: ctx.authVerifier.standard, | ||
handler: async ({ auth, input }) => { | ||
handler: async ({ req, auth, input }) => { | ||
const { list } = input.body | ||
const requester = auth.credentials.iss | ||
const db = ctx.db.getPrimary() | ||
|
||
await ctx.services.graph(db).unmuteActorList({ | ||
list, | ||
mutedByDid: requester, | ||
}) | ||
const unmuteActorList = async () => { | ||
await ctx.services.graph(db).unmuteActorList({ | ||
list, | ||
mutedByDid: requester, | ||
}) | ||
} | ||
|
||
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') | ||
} | ||
} | ||
} | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Service } from './proto/bsync_connect' | ||
import { | ||
Code, | ||
ConnectError, | ||
PromiseClient, | ||
createPromiseClient, | ||
Interceptor, | ||
} from '@connectrpc/connect' | ||
import { | ||
createConnectTransport, | ||
ConnectTransportOptions, | ||
} from '@connectrpc/connect-node' | ||
|
||
export type BsyncClient = PromiseClient<typeof Service> | ||
|
||
export const createBsyncClient = ( | ||
opts: ConnectTransportOptions, | ||
): BsyncClient => { | ||
const transport = createConnectTransport(opts) | ||
return createPromiseClient(Service, transport) | ||
} | ||
|
||
export { Code } | ||
|
||
export const isBsyncError = ( | ||
err: unknown, | ||
code?: Code, | ||
): err is ConnectError => { | ||
if (err instanceof ConnectError) { | ||
return !code || err.code === code | ||
} | ||
return false | ||
} | ||
|
||
export const authWithApiKey = | ||
(apiKey: string): Interceptor => | ||
(next) => | ||
(req) => { | ||
req.header.set('authorization', `Bearer ${apiKey}`) | ||
return next(req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.