commit bf49bcbe11bb2bbbcb445ce6447e1cf16e663b7d
parent dca811daf4ba9f3194999494ddf184c5d4ccb31b
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Fri, 28 Jun 2024 13:42:33 +0200
feat(core/mixer_stories): remove suggested stories
Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
Diffstat:
4 files changed, 40 insertions(+), 28 deletions(-)
diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json
@@ -1349,6 +1349,7 @@
},
"disable_story_sections": {
"friends": "Friends",
+ "suggested_stories": "Suggested Stories",
"following": "Following",
"discover": "Discover"
},
diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt
@@ -40,7 +40,7 @@ class Global : ConfigContainer() {
val mediaUploadQualityConfig = container("media_upload_quality", MediaUploadQualityConfig())
val disableConfirmationDialogs = multiple("disable_confirmation_dialogs", "erase_message", "remove_friend", "block_friend", "ignore_friend", "hide_friend", "hide_conversation", "clear_conversation") { requireRestart() }
val disableMetrics = boolean("disable_metrics") { requireRestart() }
- val disableStorySections = multiple("disable_story_sections", "friends", "following", "discover") { requireRestart(); requireCleanCache() }
+ val disableStorySections = multiple("disable_story_sections", "friends", "suggested_stories", "following", "discover") { requireRestart(); requireCleanCache() }
val blockAds = boolean("block_ads")
val disableCustomTabs = boolean("disable_custom_tabs") { requireRestart() }
val disablePermissionRequests = multiple("disable_permission_requests", *permissionMap.values.toTypedArray()) { requireRestart(); addNotices(FeatureNotice.UNSTABLE) }
diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/util/protobuf/ProtoEditor.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/util/protobuf/ProtoEditor.kt
@@ -69,6 +69,12 @@ class EditorContext(
wires.addAll(newWires)
}
+ fun removeIf(id: Int, predicate: (Wire) -> Boolean) {
+ wires[id]?.removeIf {
+ predicate(it)
+ }
+ }
+
override fun toString(): String {
return ProtoWriter().apply {
wires.values.flatten().forEach { addWire(it) }
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/MixerStories.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/MixerStories.kt
@@ -69,40 +69,45 @@ class MixerStories : Feature("MixerStories", loadParams = FeatureLoadParams.INIT
editEach(3) {
val sectionType = firstOrNull(10)?.toReader()?.getVarInt(1)?.toInt() ?: return@editEach
- if (sectionType == MixerStoryType.FRIENDS.index && context.config.experimental.storyLogger.get()) {
- val storyMap = mutableMapOf<String, MutableList<StoryData>>()
+ edit(3) {
+ removeIf(3) { wire ->
+ val reader = wire.toReader()
+ val storySubType = reader.getVarInt(23)
+ val isSuggested = storySubType == 39L
- firstOrNull(3)?.toReader()?.eachBuffer(3) {
- val storySubType = getVarInt(23)
- // ignore friends of friends stories
- if (storySubType == 39L) return@eachBuffer
- followPath(36) {
- eachBuffer(1) data@{
- val userId = getString(8, 1) ?: return@data
+ if (!isSuggested && sectionType == MixerStoryType.FRIENDS.index && context.config.experimental.storyLogger.get()) {
+ val storyMap = mutableMapOf<String, MutableList<StoryData>>()
- storyMap.getOrPut(userId) {
- mutableListOf()
- }.add(StoryData(
- url = getString(2, 2)?.substringBefore("?") ?: return@data,
- postedAt = getVarInt(3) ?: -1L,
- createdAt = getVarInt(27) ?: -1L,
- key = Base64.decode(getString(2, 5) ?: return@data),
- iv = Base64.decode(getString(2, 4) ?: return@data)
- ))
+ reader.followPath(36) {
+ eachBuffer(1) data@{
+ val userId = getString(8, 1) ?: return@data
+
+ storyMap.getOrPut(userId) {
+ mutableListOf()
+ }.add(StoryData(
+ url = getString(2, 2)?.substringBefore("?") ?: return@data,
+ postedAt = getVarInt(3) ?: -1L,
+ createdAt = getVarInt(27) ?: -1L,
+ key = Base64.decode(getString(2, 5) ?: return@data),
+ iv = Base64.decode(getString(2, 4) ?: return@data)
+ ))
+ }
}
- }
- }
- context.coroutineScope.launch {
- storyMap.forEach { (userId, stories) ->
- stories.forEach { story ->
- runCatching {
- context.bridgeClient.getMessageLogger().addStory(userId, story.url, story.postedAt, story.createdAt, story.key, story.iv)
- }.onFailure {
- context.log.error("Failed to log story", it)
+ context.coroutineScope.launch {
+ storyMap.forEach { (userId, stories) ->
+ stories.forEach { story ->
+ runCatching {
+ context.bridgeClient.getMessageLogger().addStory(userId, story.url, story.postedAt, story.createdAt, story.key, story.iv)
+ }.onFailure {
+ context.log.error("Failed to log story", it)
+ }
+ }
}
}
}
+
+ isSuggested && disableDiscoverSections.contains("suggested_stories")
}
}