Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import me.capcom.smsgateway.helpers.SubscriptionsHelper
import me.capcom.smsgateway.modules.incoming.db.IncomingMessage
import me.capcom.smsgateway.modules.incoming.db.IncomingMessageType
import me.capcom.smsgateway.modules.incoming.repositories.IncomingMessagesRepository
import me.capcom.smsgateway.modules.incoming.workers.IncomingLogTruncateWorker
import me.capcom.smsgateway.modules.logs.LogsService
import me.capcom.smsgateway.modules.logs.db.LogEntry
import me.capcom.smsgateway.modules.receiver.data.InboxMessage

class IncomingMessagesService(
private val context: Context,
private val settings: IncomingMessagesSettings,
private val repository: IncomingMessagesRepository,
private val logsService: LogsService,
) {
Expand Down Expand Up @@ -78,6 +80,19 @@ class IncomingMessagesService(
return getById(buildId(message)) != null
}

fun start(context: Context) {
IncomingLogTruncateWorker.start(context)
}

fun stop(context: Context) {
IncomingLogTruncateWorker.stop(context)
}

suspend fun truncateLog() {
val lifetime = settings.lifetimeDays ?: return
repository.truncate(System.currentTimeMillis() - lifetime * 86400000L)
}

private fun buildId(message: InboxMessage): String {
val prefix = when (message) {
is InboxMessage.Data -> "data:"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.capcom.smsgateway.modules.incoming

import me.capcom.smsgateway.modules.settings.Exporter
import me.capcom.smsgateway.modules.settings.Importer
import me.capcom.smsgateway.modules.settings.KeyValueStorage
import me.capcom.smsgateway.modules.settings.get

class IncomingMessagesSettings(
private val storage: KeyValueStorage,
) : Exporter, Importer {
val lifetimeDays: Int?
get() = storage.get<Int?>(LIFETIME_DAYS)?.takeIf { it > 0 }

override fun export(): Map<String, *> {
return mapOf(
LIFETIME_DAYS to lifetimeDays,
)
}

override fun import(data: Map<String, *>): Boolean {
return data.map { (key, value) ->
when (key) {
LIFETIME_DAYS -> {
val lifetimeDays = value?.toString()?.toFloat()?.toInt()
if (lifetimeDays != null && lifetimeDays < 1) {
throw IllegalArgumentException("Log lifetime days must be >= 1")
}

val changed = this.lifetimeDays != lifetimeDays
storage.set(key, lifetimeDays?.toString())
Comment thread
capcom6 marked this conversation as resolved.

changed
}

else -> false
}
}.any { it }
}

companion object {
private const val LIFETIME_DAYS = "lifetime_days"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ interface IncomingMessagesDao {
fun delete(from: Long, to: Long, types: Set<IncomingMessageType>)

@Query("DELETE FROM incoming_messages WHERE createdAt < :until")
fun truncate(until: Long)
suspend fun truncate(until: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ class IncomingMessagesRepository(private val dao: IncomingMessagesDao) {
fun insert(message: IncomingMessage) = dao.insert(message)

fun delete(from: Long, to: Long, types: Set<IncomingMessageType>) = dao.delete(from, to, types)
fun truncate(until: Long) = dao.truncate(until)
suspend fun truncate(until: Long) = dao.truncate(until)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package me.capcom.smsgateway.modules.incoming.workers

import android.content.Context
import androidx.work.Constraints
import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.WorkerParameters
import kotlinx.coroutines.CancellationException
import me.capcom.smsgateway.modules.incoming.IncomingMessagesService
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import java.util.concurrent.TimeUnit

class IncomingLogTruncateWorker(appContext: Context, params: WorkerParameters) : CoroutineWorker(
appContext,
params
), KoinComponent {
private val incomingSvc: IncomingMessagesService by inject()

override suspend fun doWork(): Result = try {
incomingSvc.truncateLog()
Result.success()
} catch (e: CancellationException) {
throw e
} catch (e: Throwable) {
e.printStackTrace()
Result.retry()
}
Comment thread
capcom6 marked this conversation as resolved.

companion object {
private const val NAME = "IncomingLogTruncateWorker"

fun start(context: Context) {
val work = PeriodicWorkRequestBuilder<IncomingLogTruncateWorker>(1L, TimeUnit.DAYS)
.setConstraints(
Constraints.Builder()
.setRequiresBatteryNotLow(true)
.build()
)
.build()

WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(
NAME,
ExistingPeriodicWorkPolicy.KEEP,
work
)
}

fun stop(context: Context) {
WorkManager.getInstance(context)
.cancelUniqueWork(NAME)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import me.capcom.smsgateway.helpers.SettingsHelper
import me.capcom.smsgateway.helpers.SubscriptionsHelper
import me.capcom.smsgateway.modules.gateway.GatewayService
import me.capcom.smsgateway.modules.incoming.IncomingMessagesService
import me.capcom.smsgateway.modules.localserver.LocalServerService
import me.capcom.smsgateway.modules.logs.LogsService
import me.capcom.smsgateway.modules.logs.db.LogEntry
Expand All @@ -16,6 +17,7 @@ import me.capcom.smsgateway.modules.webhooks.payload.AppStartedPayload

class OrchestratorService(
private val messagesSvc: MessagesService,
private val incomingSvc: IncomingMessagesService,
private val gatewaySvc: GatewayService,
private val localServerSvc: LocalServerService,
private val webHooksSvc: WebHooksService,
Expand All @@ -31,6 +33,7 @@ class OrchestratorService(

logsSvc.start(context)
messagesSvc.start(context)
incomingSvc.start(context)
webHooksSvc.start(context)
gatewaySvc.start(context)

Expand Down Expand Up @@ -71,6 +74,7 @@ class OrchestratorService(
gatewaySvc.stop(context)
webHooksSvc.stop(context)
messagesSvc.stop(context)
incomingSvc.stop(context)
logsSvc.stop(context)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.preference.PreferenceManager
import me.capcom.smsgateway.helpers.SettingsHelper
import me.capcom.smsgateway.modules.encryption.EncryptionSettings
import me.capcom.smsgateway.modules.gateway.GatewaySettings
import me.capcom.smsgateway.modules.incoming.IncomingMessagesSettings
import me.capcom.smsgateway.modules.localserver.LocalServerSettings
import me.capcom.smsgateway.modules.logs.LogsSettings
import me.capcom.smsgateway.modules.messages.MessagesSettings
Expand Down Expand Up @@ -46,6 +47,11 @@ val settingsModule = module {
PreferencesStorage(get(), "ping")
)
}
factory {
IncomingMessagesSettings(
PreferencesStorage(get(), "incoming")
)
}
factory {
LogsSettings(
PreferencesStorage(get(), "logs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import me.capcom.smsgateway.R
import me.capcom.smsgateway.modules.encryption.EncryptionSettings
import me.capcom.smsgateway.modules.gateway.GatewaySettings
import me.capcom.smsgateway.modules.incoming.IncomingMessagesSettings
import me.capcom.smsgateway.modules.logs.LogsSettings
import me.capcom.smsgateway.modules.messages.MessagesSettings
import me.capcom.smsgateway.modules.notifications.NotificationsService
Expand All @@ -15,6 +16,7 @@ class SettingsService(
private val notificationsService: NotificationsService,
encryptionSettings: EncryptionSettings,
gatewaySettings: GatewaySettings,
incomingMessagesSettings: IncomingMessagesSettings,
messagesSettings: MessagesSettings,
pingSettings: PingSettings,
logsSettings: LogsSettings,
Expand All @@ -23,6 +25,7 @@ class SettingsService(
private val settings = mapOf(
"encryption" to encryptionSettings,
"gateway" to gatewaySettings,
"incoming" to incomingMessagesSettings,
"messages" to messagesSettings,
"ping" to pingSettings,
"logs" to logsSettings,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.capcom.smsgateway.ui.settings

import android.os.Bundle
import android.text.InputType
import androidx.preference.EditTextPreference
import androidx.preference.Preference
import me.capcom.smsgateway.R

class InboxSettingsFragment : BasePreferenceFragment() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.inbox_preferences, rootKey)
}

override fun onDisplayPreferenceDialog(preference: Preference) {
when (preference.key) {
"incoming.lifetime_days" -> {
(preference as EditTextPreference).setOnBindEditTextListener {
Comment thread
capcom6 marked this conversation as resolved.
it.inputType = InputType.TYPE_CLASS_NUMBER
it.setSelectAllOnFocus(true)
it.selectAll()
}
}
}

super.onDisplayPreferenceDialog(preference)
}
}

This file was deleted.

5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_inbox.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="?attr/colorControlNormal" android:pathData="M19,3L4.99,3c-1.11,0 -1.98,0.9 -1.98,2L3,19c0,1.1 0.88,2 1.99,2L19,21c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM19,15h-4c0,1.66 -1.35,3 -3,3s-3,-1.34 -3,-3L4.99,15L4.99,5L19,5v10zM16,10h-2L14,7h-4v3L8,10l4,4 4,-4z"/>
</vector>
5 changes: 1 addition & 4 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<string name="btn_continue">استمرار</string>
<string name="by_code">بواسطة الكود</string>
<string name="can_affect_battery_life">يمكن أن يؤثر على عمر البطارية</string>
<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">انقر
<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">انقر
فوق استمرار لإنشاء حساب. لا يلزم تقديم معلومات شخصية.\nمن خلال الاستمرار، فإنك توافق على
سياسة الخصوصية الخاصة بنا على https://docs.sms-gate.app/privacy/policy/</string>
<string name="cloud_server_dotdotdot">خادم السحاب…</string>
Expand Down Expand Up @@ -60,15 +59,13 @@
<string name="messages_header">الرسائل</string>
<string name="messages">الرسائل…</string>
<string name="minimum">الحد الأدنى</string>
<string name="more_settings">مزيد من الإعدادات…</string>
<string name="n_a">غير متاح</string>
<string name="new_sms_received_webhooks_registered">تم تسجيل ويب هوك جديد للرسائل المستلمة</string>
<string name="no_webhooks_found">لم يتم تكوين ويب هوك</string>
<string name="not_registered">غير مسجل</string>
<string name="not_set">لم يحدد</string>
<string name="notification_title">SMSGate</string>
<string name="notification_channel">قناة الإشعارات</string>
<string name="notifications">الإشعارات</string>
<string name="online_status_at_the_cost_of_battery_life">حالة الاتصال بالإنترنت على حساب عمر
البطارية</string>
<string name="passphrase">كلمة السر</string>
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<string name="btn_continue">Продолжить</string>
<string name="by_code">По коду</string>
<string name="can_affect_battery_life">может влиять на время работы батареи</string>
<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">Нажмите
<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">Нажмите
\"Продолжить\", чтобы создать аккаунт. Личная информация не требуется.\nПродолжая, вы
соглашаетесь с Политикой конфиденциальности по адресу
https://docs.sms-gate.app/privacy/policy/</string>
Expand Down Expand Up @@ -61,7 +60,6 @@
<string name="messages_header">Сообщения</string>
<string name="messages">Сообщения…</string>
<string name="minimum">Минимум</string>
<string name="more_settings">Другие настройки…</string>
<string name="n_a">н/д</string>
<string name="new_sms_received_webhooks_registered">Зарегистрирован новый вебхук для входящих
сообщений</string>
Expand All @@ -70,7 +68,6 @@
<string name="not_set">Не задано</string>
<string name="notification_title">SMSGate</string>
<string name="notification_channel">Канал уведомлений</string>
<string name="notifications">Уведомления</string>
<string name="online_status_at_the_cost_of_battery_life">Время автономной работы может быть
снижено</string>
<string name="passphrase">Ключ шифрования</string>
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<string name="btn_continue">继续</string>
<string name="by_code">通过验证码</string>
<string name="can_affect_battery_life">可能影响电池寿命</string>
<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">点击"继续"创建账户,无需提供个人信息。\n继续即表示您同意我们的隐私政策,详情见
<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">点击"继续"创建账户,无需提供个人信息。\n继续即表示您同意我们的隐私政策,详情见
https://docs.sms-gate.app/privacy/policy/</string>
<string name="cloud_server_dotdotdot">云服务器…</string>
<string name="cloud_server">云服务器</string>
Expand Down Expand Up @@ -56,15 +55,13 @@
<string name="messages_header">消息</string>
<string name="messages">消息…</string>
<string name="minimum">最小值</string>
<string name="more_settings">更多设置…</string>
<string name="n_a">无数据</string>
<string name="new_sms_received_webhooks_registered">已注册新短信接收 Webhook</string>
<string name="no_webhooks_found">未配置 Webhook</string>
<string name="not_registered">未注册</string>
<string name="not_set">未设置</string>
<string name="notification_title">短信网关</string>
<string name="notification_channel">通知渠道</string>
<string name="notifications">通知</string>
<string name="online_status_at_the_cost_of_battery_life">保持在线状态(可能消耗更多电量)</string>
<string name="passphrase">密码短语</string>
<string name="password_changed_successfully">密码修改成功</string>
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<string name="btn_continue">Continue</string>
<string name="by_code">By Code</string>
<string name="can_affect_battery_life">can affect battery life</string>
<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
<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>
<string name="cloud_server_dotdotdot">Cloud server…</string>
Expand Down Expand Up @@ -61,15 +60,13 @@
<string name="messages_header">Messages</string>
<string name="messages">Messages…</string>
<string name="minimum">Minimum</string>
<string name="more_settings">More settings…</string>
<string name="n_a">n/a</string>
<string name="new_sms_received_webhooks_registered">New SMS Received Webhooks registered</string>
<string name="no_webhooks_found">No webhooks configured</string>
<string name="not_registered">not registered</string>
<string name="not_set">Not set</string>
<string name="notification_title">SMSGate</string>
<string name="notification_channel">Notification channel</string>
<string name="notifications">Notifications</string>
<string name="online_status_at_the_cost_of_battery_life">Online status at the cost of battery
life</string>
<string name="passphrase">Passphrase</string>
Expand Down Expand Up @@ -146,8 +143,6 @@
</plurals>
<string name="processing">Processing</string>
<string name="processing_order_title">Processing order</string>
<string name="receiver">Receiver</string>
<string name="receiver_summary">Content provider monitoring, fallback, etc.</string>
<string name="receiver_content_provider_monitoring">Content Provider Monitoring</string>
<string name="receiver_content_provider_monitoring_summary">Also detect incoming SMS via content
provider</string>
Expand Down Expand Up @@ -181,4 +176,7 @@
<string name="language">Language</string>
<string name="language_system">System default</string>
<string name="password_must_not_be_empty">Password must not be empty</string>
<string name="inbox_dotdotdot">Inbox…</string>
<string name="inbox_settings_summary">Content provider monitoring, retention, etc.</string>
<string name="inbox">Inbox</string>
</resources>
Loading
Loading