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

Commit

Permalink
Shamrock: 是正メッセージプッシュアイデンティティの取得が遅い
Browse files Browse the repository at this point in the history
  • Loading branch information
whitechi73 committed Feb 15, 2024
1 parent 502956e commit 9608b46
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
23 changes: 19 additions & 4 deletions xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/GroupSvc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import moe.fuqiuluo.shamrock.remote.service.data.EssenceMessage
import moe.fuqiuluo.shamrock.remote.service.data.GroupAnnouncement
import moe.fuqiuluo.shamrock.remote.service.data.GroupAnnouncementMessage
import moe.fuqiuluo.shamrock.remote.service.data.GroupAnnouncementMessageImage
import moe.fuqiuluo.shamrock.remote.service.data.push.MemberRole
import moe.fuqiuluo.shamrock.tools.EmptyJsonArray
import moe.fuqiuluo.shamrock.tools.GlobalClient
import moe.fuqiuluo.shamrock.tools.asInt
Expand Down Expand Up @@ -394,6 +395,20 @@ internal object GroupSvc: BaseSvc() {
.filter { it != 0L }
}

suspend fun getMemberRole(groupId: Long, memberUin: Long): MemberRole {
return when(getTroopMemberInfoByUinViaNt(groupId.toString(), memberUin, 3000).getOrNull()?.role) {
com.tencent.qqnt.kernel.nativeinterface.MemberRole.STRANGER -> MemberRole.Stranger
com.tencent.qqnt.kernel.nativeinterface.MemberRole.MEMBER -> MemberRole.Member
com.tencent.qqnt.kernel.nativeinterface.MemberRole.ADMIN -> MemberRole.Admin
com.tencent.qqnt.kernel.nativeinterface.MemberRole.OWNER -> MemberRole.Owner
com.tencent.qqnt.kernel.nativeinterface.MemberRole.UNSPECIFIED, null -> when (memberUin) {
getOwner(groupId.toString()) -> MemberRole.Owner
in getAdminList(groupId.toString()) -> MemberRole.Admin
else -> MemberRole.Member
}
}
}

fun getOwner(groupId: String): Long {
val groupInfo = getGroupInfo(groupId)
return groupInfo.troopowneruin?.toLong() ?: 0
Expand Down Expand Up @@ -574,7 +589,7 @@ internal object GroupSvc: BaseSvc() {
val service = app.getRuntimeService(ITroopMemberInfoService::class.java, "all")
var info = service.getTroopMember(groupId, uin)
if (refresh || !service.isMemberInCache(groupId, uin) || info == null || info.troopnick == null) {
info = requestTroopMemberInfo(service, groupId.toLong(), uin.toLong()).getOrNull()
info = requestTroopMemberInfo(service, groupId.toLong(), uin.toLong(), timeout = 2000).getOrNull()
}
if (info == null) {
info = getTroopMemberInfoByUinViaNt(groupId, uin.toLong(), timeout = 2000L).getOrNull()?.let {
Expand Down Expand Up @@ -621,7 +636,7 @@ internal object GroupSvc: BaseSvc() {
}
}

private suspend fun getTroopMemberInfoByUinViaNt(
suspend fun getTroopMemberInfoByUinViaNt(
groupId: String,
qq: Long,
timeout: Long = 5000L
Expand Down Expand Up @@ -809,7 +824,7 @@ internal object GroupSvc: BaseSvc() {
}
}

private suspend fun requestTroopMemberInfo(service: ITroopMemberInfoService, groupId: Long, memberUin: Long): Result<TroopMemberInfo> {
private suspend fun requestTroopMemberInfo(service: ITroopMemberInfoService, groupId: Long, memberUin: Long, timeout: Long = 10_000): Result<TroopMemberInfo> {
val info = RefreshTroopMemberInfoLock.withLock {
val groupIdStr = groupId.toString()
val memberUinStr = memberUin.toString()
Expand All @@ -819,7 +834,7 @@ internal object GroupSvc: BaseSvc() {
requestMemberInfoV2(groupId, memberUin)
requestMemberInfo(groupId, memberUin)

withTimeoutOrNull(10000) {
withTimeoutOrNull(timeout) {
while (!service.isMemberInCache(groupIdStr, memberUinStr)) {
delay(200)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ internal object GetTroopMemberInfo : IActionHandler() {
area = info.alias ?: "",
lastSentTime = info.last_active_time,
level = info.level,
role = when {
GroupSvc.getOwner(groupId).toString() == uin -> MemberRole.Owner
uin.toLong() in GroupSvc.getAdminList(groupId) -> MemberRole.Admin
else -> MemberRole.Member
},
role = GroupSvc.getMemberRole(groupId.toLong(), uin.toLong()),
unfriendly = false,
title = info.mUniqueTitle ?: "",
titleExpireTime = info.mUniqueTitleExpire,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ internal object GetTroopMemberList : IActionHandler() {
area = info.alias ?: "",
lastSentTime = info.last_active_time,
level = info.level,
role = when {
role = GroupSvc.getMemberRole(groupId.toLong(), info.memberuin.toLong())
/*when {
GroupSvc.getOwner(groupId)
.toString() == info.memberuin -> MemberRole.Owner
info.memberuin.toLong() in GroupSvc.getAdminList(groupId) -> MemberRole.Admin
else -> MemberRole.Member
},
}*/,
unfriendly = false,
title = info.mUniqueTitle ?: "",
titleExpireTime = info.mUniqueTitleExpire,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ internal object GlobalEventTransmitter: BaseSvc() {
.ifEmpty { record.sendMemberName }
.ifEmpty { record.peerName },
card = record.sendMemberName,
role = when (record.senderUin) {
role = GroupSvc.getMemberRole(record.peerUin, record.senderUin)/*when (record.senderUin) {
GroupSvc.getOwner(record.peerUin.toString()) -> MemberRole.Owner
in GroupSvc.getAdminList(record.peerUin.toString()) -> MemberRole.Admin
else -> MemberRole.Member
},
}*/,
title = "",
level = "",
)
Expand Down Expand Up @@ -194,7 +194,7 @@ internal object GlobalEventTransmitter: BaseSvc() {
userId = record.senderUid.toLong(),
nickname = nickName,
card = record.sendMemberName,
role = MemberRole.Member,
role = MemberRole.Member, // TODO(GUILD ROLE)
title = record.sendNickName,
level = record.roleId.toString(),
tinyId = record.senderUid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ internal data class Anonymous(
internal enum class MemberRole {
@SerialName("owner") Owner,
@SerialName("admin") Admin,
@SerialName("member") Member
@SerialName("member") Member,
@SerialName("stranger") Stranger,
@SerialName("unknown") Unknown
}

@Serializable
Expand Down

0 comments on commit 9608b46

Please sign in to comment.