mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: support /switch_account
This commit is contained in:
parent
03d62c55c2
commit
5f0cf952e8
@ -5,6 +5,7 @@ import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.tencent.qphone.base.remote.SimpleAccount;
|
||||
import com.tencent.qphone.base.remote.ToServiceMsg;
|
||||
|
||||
import mqq.app.api.IRuntimeService;
|
||||
@ -72,6 +73,10 @@ public abstract class AppRuntime {
|
||||
public <T extends IRuntimeService> T getRuntimeServiceIPCSync(@NonNull Class<T> cls, String str) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void switchAccount(SimpleAccount simpleAccount, String process) {
|
||||
|
||||
}
|
||||
public String getAccount() {
|
||||
return "";
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ internal object ActionManager {
|
||||
arrayOf(
|
||||
// Framework Info
|
||||
TestHandler, GetLatestEvents, GetSupportedActions, GetStatus, GetVersionInfo, GetSelfInfo, GetLoginInfo,
|
||||
SwitchAccount,
|
||||
|
||||
// UserActions
|
||||
GetProfileCard, GetFriendList, SendLike, GetUid, GetUinByUid, ScanQRCode, SetProfileCard,
|
||||
|
@ -0,0 +1,35 @@
|
||||
package moe.fuqiuluo.shamrock.remote.action.handlers
|
||||
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import moe.fuqiuluo.shamrock.remote.action.ActionSession
|
||||
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
|
||||
import moe.fuqiuluo.shamrock.tools.EmptyJsonString
|
||||
import moe.fuqiuluo.shamrock.xposed.helper.AppRuntimeFetcher
|
||||
import mqq.app.MobileQQ
|
||||
|
||||
internal object SwitchAccount: IActionHandler() {
|
||||
override suspend fun internalHandle(session: ActionSession): String {
|
||||
val userId = session.getString("user_id")
|
||||
return invoke(userId, session.echo)
|
||||
}
|
||||
|
||||
operator fun invoke(
|
||||
userId: String,
|
||||
echo: JsonElement = EmptyJsonString
|
||||
): String {
|
||||
val account = MobileQQ.getMobileQQ().allAccounts.firstOrNull { it.uin == userId }
|
||||
?: return error("账号不存在", echo)
|
||||
val runtime = AppRuntimeFetcher.appRuntime
|
||||
val result = kotlin.runCatching {
|
||||
runtime.switchAccount(account, null)
|
||||
}
|
||||
if (result.isFailure) {
|
||||
return error(result.exceptionOrNull()?.message ?: "切换账号失败", echo)
|
||||
}
|
||||
return ok("切换成功", echo)
|
||||
}
|
||||
|
||||
override val requiredParams: Array<String> = arrayOf("user_id")
|
||||
|
||||
override fun path(): String = "switch_account"
|
||||
}
|
@ -12,6 +12,11 @@ import moe.fuqiuluo.shamrock.tools.*
|
||||
import moe.fuqiuluo.shamrock.utils.PlatformUtils
|
||||
|
||||
fun Routing.userAction() {
|
||||
getOrPost("/switch_account") {
|
||||
val userId = fetchOrThrow("user_id")
|
||||
call.respondText(SwitchAccount(userId), ContentType.Application.Json)
|
||||
}
|
||||
|
||||
getOrPost("/set_group_leave") {
|
||||
val group = fetchOrThrow("group_id")
|
||||
call.respondText(LeaveTroop(group), ContentType.Application.Json)
|
||||
|
@ -104,7 +104,7 @@ internal object GlobalEventTransmitter: BaseSvc() {
|
||||
var nickName = record.sendNickName
|
||||
if (nickName.isNullOrBlank()) {
|
||||
CardSvc.getProfileCard(record.senderUin.toString()).onSuccess {
|
||||
nickName = it.strNick ?: ""
|
||||
nickName = it.strNick ?: record.peerName
|
||||
}
|
||||
}
|
||||
transMessageEvent(record,
|
||||
|
Loading…
x
Reference in New Issue
Block a user