commit 69e5ca74eead5e531cccbd6917f0387358fd6d30
parent 8bb3e1521c1c300c55a01700801a8d3e80b7bf40
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Wed, 24 Apr 2024 10:29:52 +0200

feat(composer_hooks): show first created username

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 4++++
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Experimental.kt | 1+
Mcore/src/main/assets/composer/loader.js | 38++++++++++++++++++++++++++++++++++++++
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/database/DatabaseAccess.kt | 11+++++++++++
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/ComposerHooks.kt | 38+++++++++++++++++++++++++-------------
5 files changed, 79 insertions(+), 13 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -774,6 +774,10 @@ "name": "Composer Hooks", "description": "Injects code into the Composer cross-platform UI framework", "properties": { + "show_first_created_username": { + "name": "Show First Created Username", + "description": "Shows the first created username next to the current username in the profile page" + }, "bypass_camera_roll_limit": { "name": "Bypass Camera Roll Limit", "description": "Increases the maximum amount of media you can send from the camera roll" diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Experimental.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Experimental.kt @@ -10,6 +10,7 @@ class Experimental : ConfigContainer() { } class ComposerHooksConfig: ConfigContainer(hasGlobalState = true) { + val showFirstCreatedUsername = boolean("show_first_created_username") val bypassCameraRollLimit = boolean("bypass_camera_roll_limit") val composerConsole = boolean("composer_console") val composerLogs = boolean("composer_logs") diff --git a/core/src/main/assets/composer/loader.js b/core/src/main/assets/composer/loader.js @@ -19,3 +19,41 @@ if (config.bypassCameraRollLimit) { }); })(require('memories_ui/src/clickhandlers/MultiSelectClickHandler')) } + +(module => { + function onComponentPreRender(component, viewModel) { + const componentName = component.constructor.name; + + if (componentName == "ProfileIdentityView" && config.showFirstCreatedUsername) { + let userInfo = callExport("getFriendInfoByUsername", viewModel.username); + + if (userInfo) { + let userInfoJson = JSON.parse(userInfo); + let firstCreatedUsername = userInfoJson.username.split("|")[0]; + if (firstCreatedUsername != viewModel.username) { + viewModel.username += " (" + firstCreatedUsername + ")"; + } + } + } + + return false + } + + function onComponentPostRender(component, viewModel) { + } + + module.Component = new Proxy(module.Component, { + construct: function(target, args, newTarget) { + let component = Reflect.construct(target, args, newTarget); + component.onRender = new Proxy(component.onRender, { + apply: function(target, thisArg, argumentsList) { + if (onComponentPreRender(component, thisArg.viewModel || {})) return; + let result = Reflect.apply(target, thisArg, argumentsList); + onComponentPostRender(component, thisArg.viewModel || {}); + return result; + } + }); + return component; + } + }) +})(require('composer_core/src/Component')) diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/database/DatabaseAccess.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/database/DatabaseAccess.kt @@ -202,6 +202,17 @@ class DatabaseAccess( } } + fun getFriendInfoByUsername(username: String): FriendInfo? { + return useDatabase(DatabaseType.MAIN)?.performOperation { + readDatabaseObject( + FriendInfo(), + "FriendWithUsername", + "usernameForSorting = ?", + arrayOf(username) + ) + } + } + fun getAllFriends(): List<FriendInfo> { return useDatabase(DatabaseType.MAIN)?.performOperation { safeRawQuery( diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/ComposerHooks.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/ComposerHooks.kt @@ -130,25 +130,36 @@ class ComposerHooks: Feature("ComposerHooks", loadParams = FeatureLoadParams.ACT } } + private fun getConfig(): Map<String, Any> { + return HashMap<String, Any>().apply { + put("bypassCameraRollLimit", config.bypassCameraRollLimit.get()) + put("showFirstCreatedUsername", config.showFirstCreatedUsername.get()) + put("composerConsole", config.composerConsole.get()) + put("composerLogs", config.composerLogs.get()) + } + } + private fun handleExportCall(composerMarshaller: ComposerMarshaller): Boolean { val argc = composerMarshaller.getSize() if (argc < 1) return false val action = composerMarshaller.getUntyped(0) as? String ?: return false when (action) { - "getConfig" -> { - composerMarshaller.pushUntyped( - HashMap<String, Any>().apply { - put("bypassCameraRollLimit", config.bypassCameraRollLimit.get()) - put("composerConsole", config.composerConsole.get()) - put("composerLogs", config.composerLogs.get()) - } - ) - } + "getConfig" -> composerMarshaller.pushUntyped(getConfig()) "showToast" -> { if (argc < 2) return false - val message = composerMarshaller.getUntyped(1) as? String ?: return false - context.shortToast(message) + context.shortToast(composerMarshaller.getUntyped(1) as? String ?: return false) + } + "getFriendInfoByUsername" -> { + if (argc < 2) return false + val username = composerMarshaller.getUntyped(1) as? String ?: return false + runCatching { + composerMarshaller.pushUntyped(context.database.getFriendInfoByUsername(username)?.let { + context.gson.toJson(it) + }) + }.onFailure { + composerMarshaller.pushUntyped(null) + } } "log" -> { if (argc < 3) return false @@ -167,9 +178,10 @@ class ComposerHooks: Feature("ComposerHooks", loadParams = FeatureLoadParams.ACT } "eval" -> { if (argc < 2) return false - val code = composerMarshaller.getUntyped(1) as? String ?: return false runCatching { - composerMarshaller.pushUntyped(context.native.composerEval(code)) + composerMarshaller.pushUntyped(context.native.composerEval( + composerMarshaller.getUntyped(1) as? String ?: return false + )) }.onFailure { composerMarshaller.pushUntyped(it.toString()) }