generated from JetBrains/compose-multiplatform-template
-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for hiding posts in the home screen with blocked words (#824
) * Add blocked words table to the database * Add `isHidden` column to posts table * Add trigger to posts table to hide post after insert if they contain a blocked word in title/description/rawContent * Add trigger to posts table to hide post before update if they contain a blocked word in title/description/rawContent * Add trigger to hide posts containing newly added blocked words * Add trigger to unhide posts containing the removed blocked word * Filter hidden posts when loading them in the home screen * Add `isHidden` to `Post` model * Add `BlockedWordsRepository` * Add local model for `BlockedWord` * Add `BlockedWordsPresenter` * Add empty `BlockedWordsScreen` to navigation graph * Add support for opening blocked words screen from settings screen * Add support for trailing icon for text field in add screen Eventually move this as a separate component * Change before delete trigger to after delete for blocked words table * Ignore hidden posts when counting unread posts * Add blocked words screen * Order blocked words list by rowid * Replace blocked words upsert query with insert or ignore
- Loading branch information
1 parent
d9846f9
commit 9177fa5
Showing
26 changed files
with
716 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
.../src/commonMain/kotlin/dev/sasikanth/rss/reader/data/repository/BlockedWordsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2025 Sasikanth Miriyampalli | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.sasikanth.rss.reader.data.repository | ||
|
||
import app.cash.sqldelight.coroutines.asFlow | ||
import app.cash.sqldelight.coroutines.mapToList | ||
import com.benasher44.uuid.Uuid | ||
import com.benasher44.uuid.uuidFrom | ||
import dev.sasikanth.rss.reader.core.model.local.BlockedWord | ||
import dev.sasikanth.rss.reader.data.database.BlockedWordsQueries | ||
import dev.sasikanth.rss.reader.di.scopes.AppScope | ||
import dev.sasikanth.rss.reader.util.DispatchersProvider | ||
import dev.sasikanth.rss.reader.util.nameBasedUuidOf | ||
import kotlinx.coroutines.withContext | ||
import me.tatarka.inject.annotations.Inject | ||
|
||
@Inject | ||
@AppScope | ||
class BlockedWordsRepository( | ||
private val blockedWordsQueries: BlockedWordsQueries, | ||
dispatchersProvider: DispatchersProvider, | ||
) { | ||
|
||
private val ioDispatcher = dispatchersProvider.io | ||
|
||
suspend fun addWord(word: String) { | ||
withContext(ioDispatcher) { | ||
val uuid = nameBasedUuidOf(word.lowercase()) | ||
blockedWordsQueries.insert(id = uuid.toString(), content = word) | ||
} | ||
} | ||
|
||
suspend fun removeWord(id: Uuid) { | ||
withContext(ioDispatcher) { blockedWordsQueries.remove(id.toString()) } | ||
} | ||
|
||
fun words() = | ||
blockedWordsQueries | ||
.words(mapper = { id, content -> BlockedWord(id = uuidFrom(id), content = content) }) | ||
.asFlow() | ||
.mapToList(ioDispatcher) | ||
} |
Binary file not shown.
40 changes: 40 additions & 0 deletions
40
core/data/src/commonMain/sqldelight/dev/sasikanth/rss/reader/data/database/BlockedWords.sq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
CREATE TABLE blockedWord ( | ||
id TEXT NOT NULL PRIMARY KEY, | ||
content TEXT NOT NULL | ||
); | ||
|
||
CREATE INDEX blocked_word_value_index ON blockedWord(content); | ||
|
||
CREATE TRIGGER hide_posts_with_blocked_words_AFTER_INSERT | ||
AFTER INSERT ON blockedWord | ||
BEGIN | ||
UPDATE OR IGNORE post | ||
SET isHidden = 1 | ||
WHERE | ||
(title LIKE '%' || new.content || '%' OR | ||
description LIKE '%' || new.content || '%' OR | ||
rawContent LIKE '%' || new.content || '%') AND | ||
isHidden = 0; | ||
END; | ||
|
||
CREATE TRIGGER unhide_posts_with_blocked_words_AFTER_DELETE | ||
AFTER DELETE ON blockedWord | ||
BEGIN | ||
UPDATE OR IGNORE post | ||
SET isHidden = 0 | ||
WHERE | ||
(title LIKE '%' || old.content || '%' OR | ||
description LIKE '%' || old.content || '%' OR | ||
rawContent LIKE '%' || old.content || '%') AND | ||
isHidden = 1; | ||
END; | ||
|
||
insert: | ||
INSERT OR IGNORE INTO blockedWord(id, content) | ||
VALUES (?, ?); | ||
|
||
remove: | ||
DELETE FROM blockedWord WHERE id = :id; | ||
|
||
words: | ||
SELECT * FROM blockedWord ORDER BY rowid DESC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
-- Post table | ||
ALTER TABLE post ADD COLUMN isHidden INTEGER NOT NULL DEFAULT 0; | ||
|
||
CREATE INDEX post_is_hidden_index ON post(isHidden); | ||
|
||
-- Blocked words table | ||
CREATE TABLE blockedWord ( | ||
id TEXT NOT NULL PRIMARY KEY, | ||
content TEXT NOT NULL | ||
); | ||
|
||
CREATE INDEX blocked_word_value_index ON blockedWord(content); | ||
|
||
-- Post table triggers | ||
CREATE TRIGGER hide_post_if_blocked_word_is_present_AFTER_INSERT | ||
AFTER INSERT ON post | ||
FOR EACH ROW | ||
WHEN ( | ||
SELECT 1 | ||
FROM blockedWord | ||
WHERE | ||
new.title LIKE '%' || blockedWord.content || '%' OR | ||
new.description LIKE '%' || blockedWord.content || '%' OR | ||
new.rawContent LIKE '%' || blockedWord.content || '%' | ||
) IS NOT NULL | ||
BEGIN | ||
UPDATE post SET isHidden = 1 WHERE id = new.id; | ||
END; | ||
|
||
CREATE TRIGGER hide_post_if_blocked_word_is_present_BEFORE_UPDATE | ||
BEFORE UPDATE ON post | ||
FOR EACH ROW | ||
WHEN ( | ||
SELECT 1 | ||
FROM blockedWord | ||
WHERE | ||
(new.title LIKE '%' || blockedWord.content || '%' OR | ||
new.description LIKE '%' || blockedWord.content || '%' OR | ||
new.rawContent LIKE '%' || blockedWord.content || '%') AND | ||
new.isHidden == 0 | ||
) IS NOT NULL | ||
BEGIN | ||
UPDATE post SET isHidden = 1 WHERE id = new.id; | ||
END; | ||
|
||
-- Blocked words triggers | ||
CREATE TRIGGER hide_posts_with_blocked_words_AFTER_INSERT | ||
AFTER INSERT ON blockedWord | ||
BEGIN | ||
UPDATE OR IGNORE post | ||
SET isHidden = 1 | ||
WHERE | ||
(title LIKE '%' || new.content || '%' OR | ||
description LIKE '%' || new.content || '%' OR | ||
rawContent LIKE '%' || new.content || '%') AND | ||
isHidden = 0; | ||
END; | ||
|
||
CREATE TRIGGER unhide_posts_with_blocked_words_AFTER_DELETE | ||
AFTER DELETE ON blockedWord | ||
BEGIN | ||
UPDATE OR IGNORE post | ||
SET isHidden = 0 | ||
WHERE | ||
(title LIKE '%' || old.content || '%' OR | ||
description LIKE '%' || old.content || '%' OR | ||
rawContent LIKE '%' || old.content || '%') AND | ||
isHidden = 1; | ||
END; |
24 changes: 24 additions & 0 deletions
24
core/model/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/model/local/BlockedWord.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2025 Sasikanth Miriyampalli | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.sasikanth.rss.reader.core.model.local | ||
|
||
import com.benasher44.uuid.Uuid | ||
|
||
data class BlockedWord( | ||
val id: Uuid, | ||
val content: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.