Skip to content

Commit

Permalink
feat: make sure pattern is valid for message filter
Browse files Browse the repository at this point in the history
Signed-off-by: qwq233 <qwq233@qwq2333.top>
  • Loading branch information
qwq233 committed Jul 10, 2024
1 parent 94d8e1f commit 5494d95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion TMessagesProj/src/main/java/top/qwq2333/nullgram/UI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.content.Context
import android.util.TypedValue
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import org.telegram.messenger.AndroidUtilities
import org.telegram.messenger.LocaleController
import org.telegram.messenger.R
Expand All @@ -33,6 +34,7 @@ import org.telegram.ui.Components.EditTextBoldCursor
import org.telegram.ui.Components.LayoutHelper
import top.qwq2333.gen.Config
import top.qwq2333.nullgram.activity.ChatSettingActivity
import java.util.regex.Pattern

fun ChatSettingActivity.createMessageFilterSetter(context: Context, resourcesProvider: Theme.ResourcesProvider? = null) {
AlertDialog.Builder(context, resourcesProvider).apply {
Expand Down Expand Up @@ -86,7 +88,13 @@ fun ChatSettingActivity.createMessageFilterSetter(context: Context, resourcesPro

setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null)
setPositiveButton(LocaleController.getString("Save", R.string.Save)) { _, _ ->
Config.messageFilter = editText.text.toString()
runCatching {
if (!editText.text.isNullOrEmpty()) Pattern.compile(editText.text.toString())
}.onSuccess {
Config.messageFilter = editText.text.toString()
}.onFailure {
Toast.makeText(context, LocaleController.getString("InvalidPattern", R.string.InvalidPattern), Toast.LENGTH_SHORT).show()
}
}
}.show()
}
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings_nullgram.xml
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,5 @@
<string name="SaveToDownloadCount_few">Saving %1$d files to Download</string>
<string name="SaveToDownloadCount_many">Saving %1$d files to Download</string>
<string name="SaveToDownloadCount_other">Saving %1$d files to Download</string>
<string name="InvalidPattern">Invalid Pattern</string>
</resources>

0 comments on commit 5494d95

Please sign in to comment.