Skip to content

Commit d8e4253

Browse files
committed
[webhooks] add periodic reminders regarding sms:received webhooks
1 parent 719d7e7 commit d8e4253

File tree

3 files changed

+79
-23
lines changed

3 files changed

+79
-23
lines changed

app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebHooksService.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import me.capcom.smsgateway.modules.webhooks.db.WebHooksDao
1313
import me.capcom.smsgateway.modules.webhooks.domain.WebHookDTO
1414
import me.capcom.smsgateway.modules.webhooks.domain.WebHookEvent
1515
import me.capcom.smsgateway.modules.webhooks.domain.WebHookEventDTO
16+
import me.capcom.smsgateway.modules.webhooks.workers.ReviewWebhooksWorker
1617
import me.capcom.smsgateway.modules.webhooks.workers.SendWebhookWorker
1718
import org.koin.core.component.KoinComponent
1819
import org.koin.core.component.get
@@ -29,9 +30,11 @@ class WebHooksService(
2930

3031
fun start(context: Context) {
3132
eventsReceiver.start()
33+
ReviewWebhooksWorker.start(context)
3234
}
3335

3436
fun stop(context: Context) {
37+
ReviewWebhooksWorker.stop(context)
3538
eventsReceiver.stop()
3639
}
3740

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package me.capcom.smsgateway.modules.webhooks.workers
2+
3+
import android.content.Context
4+
import androidx.work.CoroutineWorker
5+
import androidx.work.ExistingPeriodicWorkPolicy
6+
import androidx.work.PeriodicWorkRequestBuilder
7+
import androidx.work.WorkManager
8+
import androidx.work.WorkerParameters
9+
import me.capcom.smsgateway.R
10+
import me.capcom.smsgateway.modules.notifications.NotificationsService
11+
import me.capcom.smsgateway.modules.webhooks.WebHooksService
12+
import me.capcom.smsgateway.modules.webhooks.domain.WebHookEvent
13+
import org.koin.core.component.KoinComponent
14+
import org.koin.core.component.inject
15+
import java.util.concurrent.TimeUnit
16+
17+
class ReviewWebhooksWorker(appContext: Context, params: WorkerParameters) :
18+
CoroutineWorker(appContext, params), KoinComponent {
19+
20+
private val webHooksService: WebHooksService by inject()
21+
private val notificationsService: NotificationsService by inject()
22+
23+
override suspend fun doWork(): Result {
24+
val webhooks = webHooksService.select(null)
25+
val smsReceivedWebhooks = webhooks.filter { it.event == WebHookEvent.SmsReceived }
26+
if (smsReceivedWebhooks.isEmpty()) {
27+
return Result.success()
28+
}
29+
30+
notificationsService.notify(
31+
applicationContext,
32+
NotificationsService.NOTIFICATION_ID_SMS_RECEIVED_WEBHOOK,
33+
applicationContext.getString(
34+
R.string.you_have_sms_received_webhooks_registered_please_review_them_to_avoid_any_security_risks,
35+
smsReceivedWebhooks.size
36+
)
37+
)
38+
39+
return Result.success()
40+
}
41+
42+
companion object {
43+
private const val NAME = "ReviewWebhooksWorker"
44+
45+
fun start(context: Context) {
46+
val work = PeriodicWorkRequestBuilder<ReviewWebhooksWorker>(
47+
30,
48+
TimeUnit.DAYS
49+
)
50+
.build()
51+
WorkManager.getInstance(context)
52+
.enqueueUniquePeriodicWork(
53+
NAME,
54+
ExistingPeriodicWorkPolicy.KEEP,
55+
work
56+
)
57+
}
58+
59+
fun stop(context: Context) {
60+
WorkManager.getInstance(context)
61+
.cancelUniqueWork(NAME)
62+
}
63+
}
64+
}

app/src/main/res/values/strings.xml

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
<string name="app_version_build">App version (build)</string>
77
<string name="battery_optimization">Battery optimization</string>
88
<string name="battery_optimization_already_disabled">Battery optimization already disabled</string>
9-
<string name="battery_optimization_is_not_supported_on_this_device">Battery optimization is not
10-
supported on this device</string>
9+
<string name="battery_optimization_is_not_supported_on_this_device">Battery optimization is not supported on this device</string>
1110
<string name="btn_cancel">Cancel</string>
1211
<string name="btn_continue">Continue</string>
1312
<string name="by_code">By Code</string>
1413
<string name="can_affect_battery_life">can affect battery life</string>
15-
<string
16-
name="click_continue_to_create_an_account_no_personal_information_is_required_nby_continuing_you_agree_to_our_privacy_policy_at_https_docs_sms_gate_app_privacy_policy">Click
17-
Continue to create an account. No personal information is required.\nBy continuing, you
18-
agree to our Privacy Policy at https://docs.sms-gate.app/privacy/policy/</string>
14+
<string name="click_continue_to_create_an_account_no_personal_information_is_required_nby_continuing_you_agree_to_our_privacy_policy_at_https_docs_sms_gate_app_privacy_policy">Click Continue to create an account. No personal information is required.\nBy continuing, you agree to our Privacy Policy at https://docs.sms-gate.app/privacy/policy/</string>
1915
<string name="cloud">Cloud</string>
2016
<string name="cloud_server">Cloud server</string>
2117
<string name="cloud_server_dotdotdot">Cloud server…</string>
@@ -39,8 +35,7 @@
3935
<string name="internet_connection_unavailable">Internet connection: unavailable</string>
4036
<string name="interval_seconds">Interval (seconds)</string>
4137
<string name="invalid_url">Invalid URL</string>
42-
<string name="is_not_a_valid_port_must_be_between_1024_and_65535">%1$s is not a valid port. Must
43-
be between 1024 and 65535</string>
38+
<string name="is_not_a_valid_port_must_be_between_1024_and_65535">%1$s is not a valid port. Must be between 1024 and 65535</string>
4439
<string name="label_password">Password:</string>
4540
<string name="label_username">Username:</string>
4641
<string name="limits">Limits</string>
@@ -59,12 +54,12 @@
5954
<string name="minimum">Minimum</string>
6055
<string name="more_settings">More settings…</string>
6156
<string name="n_a">n/a</string>
57+
<string name="new_sms_received_webhooks_registered">New SMS Received Webhooks registered</string>
6258
<string name="no_webhooks_found">No webhooks configured</string>
6359
<string name="not_registered">not registered</string>
6460
<string name="not_set">Not set</string>
6561
<string name="notification_title">SMS Gateway</string>
66-
<string name="online_status_at_the_cost_of_battery_life">Online status at the cost of battery
67-
life</string>
62+
<string name="online_status_at_the_cost_of_battery_life">Online status at the cost of battery life</string>
6863
<string name="passphrase">Passphrase</string>
6964
<string name="password">Password</string>
7065
<string name="password_changed_successfully">Password changed successfully</string>
@@ -73,8 +68,7 @@
7368
<string name="period">Period</string>
7469
<string name="ping">Ping</string>
7570
<string name="ping_service_is_active">Ping service is active</string>
76-
<string name="please_enter_one_time_code_displayed_on_already_registered_device">Please enter
77-
one-time code displayed on already registered device</string>
71+
<string name="please_enter_one_time_code_displayed_on_already_registered_device">Please enter one-time code displayed on already registered device</string>
7872
<string name="port">Port</string>
7973
<string name="port_credentials_etc">Port, credentials, etc.</string>
8074
<string name="private_token">Private Token</string>
@@ -89,8 +83,7 @@
8983
<string name="server_address">Server address:</string>
9084
<string name="set_maximum_value_to_activate">Set maximum value to activate</string>
9185
<string name="settings_address_is_sms_capcom_me">api.sms-gate.app</string>
92-
<string name="settings_changed_via_api_restart_the_app_to_apply_changes">Settings changed via
93-
API. Restart the app to apply changes.</string>
86+
<string name="settings_changed_via_api_restart_the_app_to_apply_changes">Settings changed via API. Restart the app to apply changes.</string>
9487
<string name="settings_local_address_is">&lt;a href>%1$s:%2$d&lt;/a></string>
9588
<string name="settings_local_address_not_found">Not available</string>
9689
<string name="settings_local_server">Local server</string>
@@ -109,15 +102,11 @@
109102
<string name="tab_text_home">Home</string>
110103
<string name="tab_text_messages">MESSAGES</string>
111104
<string name="tab_text_settings">SETTINGS</string>
112-
<string name="the_webhook_request_will_wait_for_an_internet_connection">The webhook request will
113-
wait for an internet connection</string>
114-
<string name="to_add_a_device_to_an_existing_account_please_fill_in_the_credentials_below">To
115-
add a device to an existing account, please fill in the credentials below.</string>
116-
<string name="to_apply_the_changes_restart_the_app_using_the_button_below">To apply the changes,
117-
restart the app using the button below.</string>
105+
<string name="the_webhook_request_will_wait_for_an_internet_connection">The webhook request will wait for an internet connection</string>
106+
<string name="to_add_a_device_to_an_existing_account_please_fill_in_the_credentials_below">To add a device to an existing account, please fill in the credentials below.</string>
107+
<string name="to_apply_the_changes_restart_the_app_using_the_button_below">To apply the changes, restart the app using the button below.</string>
118108
<string name="use_empty_to_disable">Use empty to disable</string>
119-
<string name="use_this_code_to_sign_in_on_another_device">Use this code to sign in on another
120-
device</string>
109+
<string name="use_this_code_to_sign_in_on_another_device">Use this code to sign in on another device</string>
121110
<string name="username">Username</string>
122111
<string name="username_must_be_at_least_3_characters">Username must be at least 3 characters</string>
123112
<string name="view">View</string>
@@ -126,5 +115,5 @@
126115
<string name="webhook_list_title">Registered Webhooks</string>
127116
<string name="webhooks">Webhooks</string>
128117
<string name="webhooks_dotdotdot">Webhooks…</string>
129-
<string name="new_sms_received_webhooks_registered">New SMS Received Webhooks registered</string>
118+
<string name="you_have_sms_received_webhooks_registered_please_review_them_to_avoid_any_security_risks">You have %1$d SMS received webhooks registered. Please review them to avoid any security risks.</string>
130119
</resources>

0 commit comments

Comments
 (0)