Skip to content

Commit 545773a

Browse files
wa0x6eCopilot
andauthored
feat: add support for flag code (#1014)
* feat: loosen flag detection to include all non-zero * refactor: use snake case * fix: use camelcase variable name * chore: remove console.log * Update src/graphql/helpers.ts Co-authored-by: Copilot <[email protected]> * docs: add flag codes decription --------- Co-authored-by: Copilot <[email protected]>
1 parent 9899ddc commit 545773a

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ yarn start
6565

6666
To load a space settings in the database you can go on this endpoint <http://localhost:3000/api/spaces/yam.eth/poke> (change yam.eth with the space you want to activate).
6767

68+
## Flag codes
69+
70+
The hub uses flag codes (`flagCode`) to mark proposals and spaces for various reasons:
71+
72+
| Flag Code | Description | Purpose |
73+
|-----------|-------------------------|-------------------------------------------------------------------|
74+
| `1` | Spam/Malicious Content | Reserved for content identified as spam or malicious |
75+
| `2` | DMCA Requests | Reserved for Digital Millennium Copyright Act takedown requests |
76+
| `3+` | Future Use | Additional codes may be introduced for other moderation purposes |
77+
78+
When content is flagged, it may have restricted visibility or functionality depending on the flag type applied.
79+
6880
## License
6981

7082
Snapshot is open-sourced software licensed under the © [MIT license](LICENSE).

src/graphql/helpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ export function formatSpace({
141141
space.skinSettings = skinSettings;
142142

143143
space.verified = verified ?? null;
144-
space.flagged = flagged ?? null;
144+
space.flagged = flagged > 0;
145+
space.flagCode = flagged;
145146
space.hibernated = hibernated ?? null;
146147
space.turbo =
147148
new Date((turboExpiration || 0) * 1000) > new Date() ? true : turbo ?? null;
@@ -464,6 +465,9 @@ export function formatProposal(proposal) {
464465
}));
465466
proposal.privacy = proposal.privacy || '';
466467
proposal.quorumType = proposal.quorum_type || 'default';
468+
const rawFlagged = proposal.flagged;
469+
proposal.flagCode = rawFlagged;
470+
proposal.flagged = rawFlagged > 0;
467471
return proposal;
468472
}
469473

src/graphql/operations/proposals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default async function (parent, args) {
6666
}
6767

6868
if (where.flagged === true) {
69-
searchSql += ' AND p.flagged = 1';
69+
searchSql += ' AND p.flagged > 0';
7070
}
7171

7272
if (where.flagged === false) {

src/graphql/schema.gql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ type Space {
441441
template: String
442442
verified: Boolean
443443
flagged: Boolean
444+
flagCode: Int
444445
hibernated: Boolean
445446
turbo: Boolean
446447
turboExpiration: Int
@@ -510,6 +511,7 @@ type Proposal {
510511
scores_updated: Int
511512
votes: Int
512513
flagged: Boolean
514+
flagCode: Int
513515
}
514516

515517
type Strategy {

src/helpers/metrics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ new client.Gauge({
100100
{ status },
101101
(
102102
await db.queryAsync(
103-
`SELECT COUNT(id) as count FROM spaces WHERE ${status} = 1`
103+
`SELECT COUNT(id) as count FROM spaces WHERE ${status} > 0`
104104
)
105105
)[0].count
106106
);

src/helpers/spaces.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ async function loadSpaces() {
172172
space.id,
173173
{
174174
...JSON.parse(space.settings),
175-
flagged: space.flagged === 1,
175+
flagged: space.flagged > 0,
176+
flagCode: space.flagged,
176177
verified: space.verified === 1,
177178
turbo: isTurbo(!!space.turbo, space.turbo_expiration),
178179
turboExpiration: space.turbo_expiration,
@@ -319,7 +320,7 @@ export async function getSpace(id: string) {
319320
return {
320321
...JSON.parse(space.settings),
321322
domain: space.domain,
322-
flagged: space.flagged === 1,
323+
flagged: space.flagged > 0,
323324
verified: space.verified === 1,
324325
turbo: isTurbo(!!space.turbo, space.turbo_expiration),
325326
turboExpiration: space.turbo_expiration,

0 commit comments

Comments
 (0)