eladnava / redalert-android

An Android app that provides real-time emergency alerts for Israeli citizens.
Apache License 2.0
91 stars 22 forks source link

Where are the city selections saved? #49

Closed Yossiohayo closed 11 months ago

Yossiohayo commented 11 months ago

Hi, when I select a city where is my selection saved?

After I have chosen a city and there is an alarm in the city I have chosen, how does the system know to send me the push notification?

And how does the system avoid sending me a push notification when it is not the city I chose?

I would appreciate it if you would attach here a link to lines of code that do the actions I asked here 🙂

eladnava commented 11 months ago

Hi @Yossiohayo, I'd be glad to clarify.

1) City/region selections are saved in the SharedPreferences: https://github.com/eladnava/redalert-android/blob/1462bc21cf6df9b4ef3458c6515d250ab7e89bb6/app/src/main/res/xml/settings.xml#L23-L40

2) The system subscribes you to push notification Pub/Sub topics based on the selected regions and cities (e.g. /topics/tel_aviv_center): https://github.com/eladnava/redalert-android/blob/1462bc21cf6df9b4ef3458c6515d250ab7e89bb6/app/src/main/java/com/red/alert/activities/settings/General.java#L849-L852

3) The RedAlert backend servers publish notifications via topic whenever HFC issues an alert for that city.

Yossiohayo commented 11 months ago

@eladnava Sorry, I can't understand if I signed up for Ashkelon (topics/ashkelon) So the topic I am associated with is Ashkelon. But if I changed to Ashdod, then it moves me to the subject of Ashdod (topics/ashdod). My question is where are these topics located? There are over 1000 subjects, did you enter them manually or does the scanner know how to recognize the user's choice?

eladnava commented 11 months ago

Hi @Yossiohayo, The topic names are the English city names from cities.json: https://github.com/eladnava/redalert-android/blob/master/app/src/main/res/raw/cities.json#L2023

The English city name gets sanitized to be compliant with FCM Pub/Sub topic regex [a-zA-Z0-9-_.~%]{1,900}: https://github.com/eladnava/redalert-android/blob/dc03c90bc2b0425ee3df5c34dbebc72873671b8b/app/src/main/java/com/red/alert/utils/metadata/LocationData.java#L288-L291

So "Ashkelon - South" becomes ashkelon_south.

Yossiohayo commented 11 months ago

Thank you

Yossiohayo commented 11 months ago

Where can you find the https://redalert.me server?

eladnava commented 11 months ago

The backend source code is not publicly available due to obvious cyber security concerns.