forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_review_config.py
More file actions
71 lines (53 loc) · 2.59 KB
/
Copy pathapp_review_config.py
File metadata and controls
71 lines (53 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Server-driven config for toggling subscription-surface visibility per
platform and app version.
Stored in Firestore so the flag can be flipped without a redeploy:
Collection: app_review_config
Document ID: ios | android | macos
Fields:
hidden_versions: list[str] # e.g. ["1.0.531", "1.0.531+607"]
reviewer_uids: list[str] # specific UIDs to always hide for
A version in `hidden_versions` matches the app version using the same
semantic-vs-build comparison the announcements module already uses, so an
entry like "1.0.531" matches every build of that semantic version.
"""
from typing import Any, Optional, cast
from database._client import db
from database.announcements import compare_versions
from database.cache import get_memory_cache
_CACHE_KEY_PREFIX = "app_review_config:"
_CACHE_TTL_SECONDS = 60 # short so flag flips propagate within a minute
def _fetch_review_config(platform: str) -> dict[str, Any]:
doc = db.collection("app_review_config").document(platform).get()
if not getattr(doc, "exists", False):
return {}
raw: object = doc.to_dict()
return cast(dict[str, Any], raw) if isinstance(raw, dict) else {}
def get_review_config(platform: str) -> dict[str, Any]:
"""Return the review-config doc for a platform, cached for 60s."""
cache_key = f"{_CACHE_KEY_PREFIX}{platform}"
fetched = get_memory_cache().get_or_fetch(cache_key, lambda: _fetch_review_config(platform), ttl=_CACHE_TTL_SECONDS)
return cast(dict[str, Any], fetched) if isinstance(fetched, dict) else {}
_SUPPORTED_PLATFORMS = {"ios", "macos"}
def should_hide_subscription_ui(uid: str, platform: Optional[str], app_version: Optional[str]) -> bool:
"""True when subscription surfaces should be hidden for this caller."""
normalized = (platform or "").lower()
if normalized not in _SUPPORTED_PLATFORMS:
return False
cfg = get_review_config(normalized) or {}
if uid:
reviewer_uids_raw = cfg.get("reviewer_uids")
reviewer_uids: list[object] = (
cast(list[object], reviewer_uids_raw) if isinstance(reviewer_uids_raw, list) else []
)
if uid in [r for r in reviewer_uids if isinstance(r, str)]:
return True
if app_version:
hidden_versions_raw = cfg.get("hidden_versions")
hidden_versions: list[object] = (
cast(list[object], hidden_versions_raw) if isinstance(hidden_versions_raw, list) else []
)
for hidden in [v for v in hidden_versions if isinstance(v, str)]:
if compare_versions(app_version, hidden) == 0:
return True
return False