feat(composer_hooks): show first created username
This commit is contained in:
@@ -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'))
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user