Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Shamrock: support /switch_account
Browse files Browse the repository at this point in the history
  • Loading branch information
whitechi73 committed Nov 23, 2023
1 parent 03d62c5 commit 5f0cf95
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions qqinterface/src/main/java/mqq/app/AppRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import androidx.annotation.NonNull;

import com.tencent.qphone.base.remote.SimpleAccount;
import com.tencent.qphone.base.remote.ToServiceMsg;

import mqq.app.api.IRuntimeService;
Expand Down Expand Up @@ -72,6 +73,10 @@ public <T extends IRuntimeService> T getRuntimeService(Class<T> cls, String name
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 "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5f0cf95

Please sign in to comment.