From c7a6e06f9a370db1223bf69a49ec68e270bce988 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:50:20 -0400 Subject: [PATCH 1/3] feat: wayfarer poi colors & sponsor filtering --- packages/locales/lib/human/en.json | 5 +- packages/types/lib/general.d.ts | 2 + packages/types/lib/scanner.d.ts | 6 ++ server/src/configs/default.json | 5 +- server/src/graphql/typeDefs/map.graphql | 2 + server/src/graphql/typeDefs/scanner.graphql | 2 + server/src/models/Gym.js | 27 ++++---- server/src/models/PoI.js | 6 +- server/src/models/Pokestop.js | 16 +++-- server/src/services/filters/builder/base.js | 1 + .../services/functions/getPlacementCells.js | 11 +++- server/src/services/ui/clientOptions.js | 2 + server/src/services/ui/primary.js | 15 +++-- src/components/layout/drawer/Extras.jsx | 66 +++++++++---------- .../tiles/submissionCells/S14Cell.jsx | 4 +- .../tiles/submissionCells/SubmissionCell.jsx | 14 +++- src/services/queries/submissionCells.js | 2 + 17 files changed, 122 insertions(+), 64 deletions(-) diff --git a/packages/locales/lib/human/en.json b/packages/locales/lib/human/en.json index 2da6f9438..ace66bcae 100644 --- a/packages/locales/lib/human/en.json +++ b/packages/locales/lib/human/en.json @@ -671,5 +671,6 @@ "done": "Done", "fast": "Fast", "charged": "Charged", - "offline_mode": "Offline Mode" -} + "offline_mode": "Offline Mode", + "include_sponsored": "Include Sponsored" +} \ No newline at end of file diff --git a/packages/types/lib/general.d.ts b/packages/types/lib/general.d.ts index fdbc69f67..a55b1ca92 100644 --- a/packages/types/lib/general.d.ts +++ b/packages/types/lib/general.d.ts @@ -36,6 +36,8 @@ export interface PoI { id: string lat: number lon: number + showcase: boolean + partner: boolean } export interface BaseCell { diff --git a/packages/types/lib/scanner.d.ts b/packages/types/lib/scanner.d.ts index 30303462f..8a47a6365 100644 --- a/packages/types/lib/scanner.d.ts +++ b/packages/types/lib/scanner.d.ts @@ -53,6 +53,7 @@ export interface Gym { total_cp: number first_seen_timestamp: number sponsor_id: number + partner_id: number raid_pokemon_costume: number raid_pokemon_gender: number raid_pokemon_evolution: number @@ -161,6 +162,7 @@ export interface Pokestop { pokestop_display: number first_seen_timestamp: number sponsor_id: number + partner_id: number ar_scan_eligible: boolean quests: Quest[] invasions: Invasion[] @@ -168,6 +170,10 @@ export interface Pokestop { power_up_level: number power_up_points: number power_up_end_timestamp: number + showcase_expiry?: number + showcase_pokemon_id?: number + showcase_ranking_standard?: number + showcase_rankings?: ShowcaseDetails | string } export type FullPokestop = FullModel diff --git a/server/src/configs/default.json b/server/src/configs/default.json index 7e97aa096..f9afe7dd2 100644 --- a/server/src/configs/default.json +++ b/server/src/configs/default.json @@ -412,6 +412,8 @@ "darkMapBorder": "#ff0000", "cellBlocked": "#000000", "poiColor": "#03ffff", + "showcaseColor": "#D365F5", + "partnerColor": "#F60042", "enablePortalPopupCoords": false }, "s2cells": { @@ -554,7 +556,8 @@ "enabled": false, "rings": true, "s17Cells": true, - "s14Cells": true + "s14Cells": true, + "includeSponsored": true }, "s2cells": { "enabled": false, diff --git a/server/src/graphql/typeDefs/map.graphql b/server/src/graphql/typeDefs/map.graphql index 159f38118..bf5667bd8 100644 --- a/server/src/graphql/typeDefs/map.graphql +++ b/server/src/graphql/typeDefs/map.graphql @@ -131,6 +131,8 @@ type PoI { id: ID lat: Float lon: Float + showcase: Boolean + partner: Boolean } type SubmissionCell { diff --git a/server/src/graphql/typeDefs/scanner.graphql b/server/src/graphql/typeDefs/scanner.graphql index 322d55067..756a9c6c7 100644 --- a/server/src/graphql/typeDefs/scanner.graphql +++ b/server/src/graphql/typeDefs/scanner.graphql @@ -37,6 +37,7 @@ type Gym { total_cp: Int first_seen_timestamp: Int sponsor_id: Int + partner_id: Int raid_pokemon_costume: Int raid_pokemon_gender: Int raid_pokemon_evolution: Int @@ -140,6 +141,7 @@ type Pokestop { pokestop_display: Int first_seen_timestamp: Int sponsor_id: Int + partner_id: Int ar_scan_eligible: Boolean quests: [Quest] invasions: [Invasion] diff --git a/server/src/models/Gym.js b/server/src/models/Gym.js index 77c2dd088..6bd88a724 100644 --- a/server/src/models/Gym.js +++ b/server/src/models/Gym.js @@ -567,36 +567,41 @@ class Gym extends Model { .first() } - static getSubmissions(perms, args, { isMad }) { + static async getSubmissions(perms, args, { isMad }) { const { - filters: { onlyAreas = [] }, + filters: { onlyAreas = [], onlyIncludeSponsored = true }, minLat, minLon, maxLat, maxLon, } = args + const wiggle = 0.025 const query = this.query() .whereBetween(`lat${isMad ? 'itude' : ''}`, [ - minLat - 0.025, - maxLat + 0.025, + minLat - wiggle, + maxLat + wiggle, ]) .andWhereBetween(`lon${isMad ? 'gitude' : ''}`, [ - minLon - 0.025, - maxLon + 0.025, + minLon - wiggle, + maxLon + wiggle, ]) .andWhere(isMad ? 'enabled' : 'deleted', isMad) if (isMad) { query.select(['gym_id AS id', 'latitude AS lat', 'longitude AS lon']) } else { - query.select(['id', 'lat', 'lon']).andWhere((poi) => { - poi.whereNull('sponsor_id').orWhere('sponsor_id', 0) - }) + query.select(['id', 'lat', 'lon', 'partner_id']) + + if (!onlyIncludeSponsored) { + query.andWhere((poi) => { + poi.whereNull('partner_id').orWhere('partner_id', 0) + }) + } } if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) { return [] } - - return query + const results = await query + return results } } diff --git a/server/src/models/PoI.js b/server/src/models/PoI.js index 36ad1e742..201ad4168 100644 --- a/server/src/models/PoI.js +++ b/server/src/models/PoI.js @@ -4,11 +4,15 @@ class PoI { * @param {string} id * @param {number} lat * @param {number} lon + * @param {boolean} [partner] + * @param {boolean} [showcase] */ - constructor(id, lat, lon) { + constructor(id, lat, lon, partner = false, showcase = false) { this.id = id this.lat = lat this.lon = lon + this.partner = partner + this.showcase = showcase } } diff --git a/server/src/models/Pokestop.js b/server/src/models/Pokestop.js index e81a47150..2ec4eff04 100644 --- a/server/src/models/Pokestop.js +++ b/server/src/models/Pokestop.js @@ -1723,9 +1723,9 @@ class Pokestop extends Model { .first() } - static getSubmissions(perms, args, { isMad }) { + static getSubmissions(perms, args, { isMad, hasShowcaseData }) { const { - filters: { onlyAreas = [] }, + filters: { onlyAreas = [], onlyIncludeSponsored = true }, minLat, minLon, maxLat, @@ -1744,9 +1744,15 @@ class Pokestop extends Model { if (isMad) { query.select(['pokestop_id AS id', 'latitude AS lat', 'longitude AS lon']) } else { - query.select(['id', 'lat', 'lon']).andWhere((poi) => { - poi.whereNull('sponsor_id').orWhere('sponsor_id', 0) - }) + query.select(['id', 'lat', 'lon', 'partner_id']) + if (!onlyIncludeSponsored) { + query.andWhere((poi) => { + poi.whereNull('partner_id').orWhere('partner_id', 0) + }) + } + if (hasShowcaseData) { + query.select('showcase_expiry') + } } if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) { return [] diff --git a/server/src/services/filters/builder/base.js b/server/src/services/filters/builder/base.js index a025ab37a..985d4c514 100644 --- a/server/src/services/filters/builder/base.js +++ b/server/src/services/filters/builder/base.js @@ -158,6 +158,7 @@ function buildDefaultFilters(perms, database) { rings: defaultFilters.submissionCells.rings, s17Cells: defaultFilters.submissionCells.s17Cells, s14Cells: defaultFilters.submissionCells.s14Cells, + includeSponsored: defaultFilters.submissionCells.includeSponsored, filter: { global: new BaseFilter() }, } : undefined, diff --git a/server/src/services/functions/getPlacementCells.js b/server/src/services/functions/getPlacementCells.js index 01c194781..8f05d5533 100644 --- a/server/src/services/functions/getPlacementCells.js +++ b/server/src/services/functions/getPlacementCells.js @@ -60,7 +60,16 @@ function getPlacementCells(filters, pokestops, gyms) { ? Object.values(indexedCells) : [], pois: filters.filters.onlyRings - ? allCoords.map((poi) => new PoI(poi.id, poi.lat, poi.lon)) + ? allCoords.map( + (poi) => + new PoI( + poi.id, + poi.lat, + poi.lon, + !!poi.partner_id, + 'showcase_expiry' in poi ? !!poi.showcase_expiry : false, + ), + ) : [], } } diff --git a/server/src/services/ui/clientOptions.js b/server/src/services/ui/clientOptions.js index e5c71c47e..32dbc93f4 100644 --- a/server/src/services/ui/clientOptions.js +++ b/server/src/services/ui/clientOptions.js @@ -82,6 +82,8 @@ function clientOptions(perms) { darkMapBorder: { type: 'color', perm: ['submissionCells'] }, cellBlocked: { type: 'color', perm: ['submissionCells'] }, poiColor: { type: 'color', perm: ['submissionCells'] }, + partnerColor: { type: 'color', perm: ['submissionCells'] }, + showcaseColor: { type: 'color', perm: ['submissionCells'] }, }, s2cells: { lightMapBorder: { type: 'color', perm: ['s2cells'] }, diff --git a/server/src/services/ui/primary.js b/server/src/services/ui/primary.js index 5d77db71f..a62315dce 100644 --- a/server/src/services/ui/primary.js +++ b/server/src/services/ui/primary.js @@ -149,10 +149,13 @@ function generateUi(req, perms) { wayfarer: perms.portals || perms.submissionCells ? { - portals: (perms.portals && Db.models.Portal) || undefined, + portals: !!(perms.portals && Db.models.Portal) || undefined, submissionCells: - (perms.submissionCells && Db.models.Pokestop && Db.models.Gym) || - undefined, + !!( + perms.submissionCells && + Db.models.Pokestop && + Db.models.Gym + ) || undefined, } : undefined, s2cells: perms.s2cells ? { enabled: true, cells: true } : undefined, @@ -164,9 +167,9 @@ function generateUi(req, perms) { perms.spawnpoints || perms.scanCells || perms.devices ? { spawnpoints: - (perms.spawnpoints && Db.models.Spawnpoint) || undefined, - scanCells: (perms.scanCells && Db.models.ScanCell) || undefined, - devices: (perms.devices && Db.models.Device) || undefined, + !!(perms.spawnpoints && Db.models.Spawnpoint) || undefined, + scanCells: !!(perms.scanCells && Db.models.ScanCell) || undefined, + devices: !!(perms.devices && Db.models.Device) || undefined, } : undefined, settings: true, diff --git a/src/components/layout/drawer/Extras.jsx b/src/components/layout/drawer/Extras.jsx index 62eaa6c59..7e857b6b3 100644 --- a/src/components/layout/drawer/Extras.jsx +++ b/src/components/layout/drawer/Extras.jsx @@ -195,23 +195,20 @@ export default function Extras({ category, subItem, data }) { alignItems="center" justifyContent="flex-end" > - { - setFilters({ - ...filters, - [category]: { - ...filters[category], - confirmed: !filters[category].confirmed, - }, - }) - }} - /> - } - > + + { + setFilters({ + ...filters, + [category]: { + ...filters[category], + confirmed: !filters[category].confirmed, + }, + }) + }} + /> ) @@ -268,10 +265,21 @@ export default function Extras({ category, subItem, data }) { ) { return ( - {['rings', 's14Cells', 's17Cells'].map((item, i) => ( - ( + + 1 ? ( + + {{ level: item.substring(1, 3) }} + + ) : ( + t(i ? 'include_sponsored' : 'poi') + ) + } + /> { @@ -285,21 +293,9 @@ export default function Extras({ category, subItem, data }) { }} disabled={filters[subItem]?.enabled === false} /> - } - > - - {{ level: item.substring(1, 3) }} - - ) : ( - t('poi') - ) - } - /> - - ))} + + ), + )} ) } diff --git a/src/components/tiles/submissionCells/S14Cell.jsx b/src/components/tiles/submissionCells/S14Cell.jsx index 1baf07719..344170723 100644 --- a/src/components/tiles/submissionCells/S14Cell.jsx +++ b/src/components/tiles/submissionCells/S14Cell.jsx @@ -42,7 +42,9 @@ const MemoS14Cell = React.memo( prev.cellColor === next.cellColor && prev.oneStopTillNext === next.oneStopTillNext && prev.twoStopsTillNext === next.twoStopsTillNext && - prev.noMoreGyms === next.noMoreGyms, + prev.noMoreGyms === next.noMoreGyms && + prev.count_gyms === next.count_gyms && + prev.count_pokestops === next.count_pokestops, ) export default MemoS14Cell diff --git a/src/components/tiles/submissionCells/SubmissionCell.jsx b/src/components/tiles/submissionCells/SubmissionCell.jsx index 05d86aea3..8e7244cbe 100644 --- a/src/components/tiles/submissionCells/SubmissionCell.jsx +++ b/src/components/tiles/submissionCells/SubmissionCell.jsx @@ -14,6 +14,8 @@ import PoITile from './PoI' */ const SubmissionCellTile = ({ level14Cells, level17Cells, pois }) => { const poiColor = useStore((s) => s.userSettings.wayfarer.poiColor) + const showcaseColor = useStore((s) => s.userSettings.wayfarer.showcaseColor) + const partnerColor = useStore((s) => s.userSettings.wayfarer.partnerColor) const cellBlocked = useStore((s) => s.userSettings.wayfarer.cellBlocked) const oneStopTillNext = useStore( (s) => s.userSettings.wayfarer.oneStopTillNext, @@ -31,7 +33,17 @@ const SubmissionCellTile = ({ level14Cells, level17Cells, pois }) => { return ( <> {pois?.map((ring) => ( - + ))} {level17Cells?.map((cell) => ( Date: Thu, 2 Nov 2023 14:54:27 -0400 Subject: [PATCH 2/3] fix: translations --- packages/locales/lib/human/en.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/locales/lib/human/en.json b/packages/locales/lib/human/en.json index ace66bcae..97247253b 100644 --- a/packages/locales/lib/human/en.json +++ b/packages/locales/lib/human/en.json @@ -672,5 +672,7 @@ "fast": "Fast", "charged": "Charged", "offline_mode": "Offline Mode", - "include_sponsored": "Include Sponsored" + "include_sponsored": "Include Sponsored", + "showcase_color": "Showcase Color", + "partner_color": "Partner Color" } \ No newline at end of file From d98c6f1ee7aad101b7084429eb0070f97fcd33ba Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:25:55 -0400 Subject: [PATCH 3/3] fix: ensure only enabled make it through --- server/src/models/Gym.js | 23 +++++++++++++++++++---- server/src/models/Pokestop.js | 26 +++++++++++++++++++++----- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/server/src/models/Gym.js b/server/src/models/Gym.js index 6bd88a724..6fda87ddc 100644 --- a/server/src/models/Gym.js +++ b/server/src/models/Gym.js @@ -53,6 +53,18 @@ class Gym extends Model { return 'gym' } + /** + * + * @param {import('objection').QueryBuilder} query + * @param {boolean} isMad + */ + static onlyValid(query, isMad) { + query.andWhere('enabled', true) + if (!isMad) { + query.andWhere('deleted', false) + } + } + static async getAll(perms, args, { isMad, availableSlotsCol }, userId) { const { gyms: gymPerms, @@ -118,7 +130,7 @@ class Gym extends Model { query .whereBetween(isMad ? 'latitude' : 'lat', [args.minLat, args.maxLat]) .andWhereBetween(isMad ? 'longitude' : 'lon', [args.minLon, args.maxLon]) - .andWhere(isMad ? 'enabled' : 'deleted', isMad) + Gym.onlyValid(query, isMad) const raidBosses = new Set() const raidForms = new Set() @@ -459,7 +471,6 @@ class Gym extends Model { 'url', distance, ]) - .where(isMad ? 'enabled' : 'deleted', isMad) .whereRaw(`LOWER(name) LIKE '%${search}%'`) .limit(searchResultsLimit) .orderBy('distance') @@ -469,6 +480,8 @@ class Gym extends Model { if (!getAreaSql(query, areaRestrictions, onlyAreas, isMad)) { return [] } + Gym.onlyValid(query, isMad) + return query } @@ -507,7 +520,6 @@ class Gym extends Model { '>=', isMad ? this.knex().fn.now() : ts, ) - .andWhere(isMad ? 'enabled' : 'deleted', isMad) if (isMad) { query .leftJoin('gymdetails', 'gym.gym_id', 'gymdetails.gym_id') @@ -519,6 +531,8 @@ class Gym extends Model { if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) { return [] } + Gym.onlyValid(query, isMad) + return query } @@ -585,7 +599,6 @@ class Gym extends Model { minLon - wiggle, maxLon + wiggle, ]) - .andWhere(isMad ? 'enabled' : 'deleted', isMad) if (isMad) { query.select(['gym_id AS id', 'latitude AS lat', 'longitude AS lon']) } else { @@ -600,6 +613,8 @@ class Gym extends Model { if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) { return [] } + Gym.onlyValid(query, isMad) + const results = await query return results } diff --git a/server/src/models/Pokestop.js b/server/src/models/Pokestop.js index 2ec4eff04..b7dd90ed2 100644 --- a/server/src/models/Pokestop.js +++ b/server/src/models/Pokestop.js @@ -62,6 +62,18 @@ class Pokestop extends Model { return 'pokestop' } + /** + * + * @param {import('objection').QueryBuilder} query + * @param {boolean} isMad + */ + static onlyValid(query, isMad) { + query.andWhere('enabled', true) + if (!isMad) { + query.andWhere('deleted', false) + } + } + static async getAll( perms, args, @@ -176,7 +188,8 @@ class Pokestop extends Model { query .whereBetween(isMad ? 'latitude' : 'lat', [args.minLat, args.maxLat]) .andWhereBetween(isMad ? 'longitude' : 'lon', [args.minLon, args.maxLon]) - .andWhere(isMad ? 'enabled' : 'deleted', isMad) + + Pokestop.onlyValid(query, isMad) if (!getAreaSql(query, areaRestrictions, onlyAreas, isMad)) { return [] } @@ -1557,13 +1570,13 @@ class Pokestop extends Model { isMad ? 'image AS url' : 'url', distance, ]) - .where(isMad ? 'enabled' : 'deleted', isMad) .whereRaw(`LOWER(name) LIKE '%${search}%'`) .limit(searchResultsLimit) .orderBy('distance') if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) { return [] } + Pokestop.onlyValid(query, isMad) return query } @@ -1606,7 +1619,6 @@ class Pokestop extends Model { isMad ? 'quest_reward AS quest_rewards' : 'quest_rewards', distance, ]) - .where(isMad ? 'enabled' : 'deleted', isMad) .andWhere('quest_timestamp', '>=', midnight || 0) .andWhere((quests) => { quests @@ -1628,6 +1640,8 @@ class Pokestop extends Model { if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) { return [] } + Pokestop.onlyValid(query, isMad) + const results = await query const mapped = results.map((q) => ({ ...q, with_ar: q.with_ar ?? true })) @@ -1697,7 +1711,6 @@ class Pokestop extends Model { : 'lure_expire_timestamp', distance, ]) - .where(isMad ? 'enabled' : 'deleted', isMad) .andWhere( isMad ? 'lure_expiration' : 'lure_expire_timestamp', '>=', @@ -1709,6 +1722,8 @@ class Pokestop extends Model { if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) { return [] } + Pokestop.onlyValid(query, isMad) + const results = await query return results } @@ -1740,7 +1755,6 @@ class Pokestop extends Model { minLon - 0.025, maxLon + 0.025, ]) - .andWhere(isMad ? 'enabled' : 'deleted', isMad) if (isMad) { query.select(['pokestop_id AS id', 'latitude AS lat', 'longitude AS lon']) } else { @@ -1757,6 +1771,8 @@ class Pokestop extends Model { if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) { return [] } + Pokestop.onlyValid(query, isMad) + return query } }