diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt index 6cb6bc4..f710077 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt @@ -311,6 +311,27 @@ internal object GlobalEventTransmitter: BaseSvc() { )) return true } + + suspend fun transGroupApply( + time: Long, + operator: Long, + reason: String, + groupCode: Long, + subType: NoticeSubType + ): Boolean { + pushNotice(NoticeEvent( + time = time, + selfId = app.longAccountUin, + postType = PostType.Notice, + type = NoticeType.GroupApply, + operatorId = operator, + tip = reason, + groupId = groupCode, + subType = subType + )) + return true + } + } /** @@ -338,7 +359,6 @@ internal object GlobalEventTransmitter: BaseSvc() { selfId = app.longAccountUin, postType = PostType.Notice, type = NoticeType.FriendRecall, - subType = NoticeSubType.Poke, operatorId = operation, userId = operation, msgId = msgHashId, @@ -346,6 +366,19 @@ internal object GlobalEventTransmitter: BaseSvc() { )) return true } + + suspend fun transFriendApply(time: Long, operation: Long, tipText: String): Boolean { + pushNotice(NoticeEvent( + time = time, + selfId = app.longAccountUin, + postType = PostType.Notice, + type = NoticeType.FriendApply, + operatorId = operation, + userId = operation, + tip = tipText + )) + return true + } } @ShamrockDsl diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/data/push/NoticeEvent.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/data/push/NoticeEvent.kt index f9ec9f8..da95bb1 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/data/push/NoticeEvent.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/data/push/NoticeEvent.kt @@ -10,7 +10,9 @@ internal enum class NoticeType { @SerialName("group_decrease") GroupMemDecrease, @SerialName("group_increase") GroupMemIncrease, @SerialName("group_recall") GroupRecall, + @SerialName("group_apply") GroupApply, @SerialName("friend_recall") FriendRecall, + @SerialName("friend_add") FriendApply, @SerialName("notify") Notify, @SerialName("group_upload") GroupUpload, @SerialName("private_upload") PrivateUpload @@ -26,6 +28,7 @@ internal enum class NoticeSubType { @SerialName("set") Set, @SerialName("un_set") UnSet, + @SerialName("add") Add, @SerialName("invite") Invite, @SerialName("approve") Approve, @SerialName("leave") Leave, diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/listener/PrimitiveListener.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/listener/PrimitiveListener.kt index 26c8d24..c51257a 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/listener/PrimitiveListener.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/listener/PrimitiveListener.kt @@ -47,23 +47,34 @@ internal object PrimitiveListener { if ( !pb.has(1, 3) || !pb.has(1, 2) - || !pb.has(1, 2, 2) +// || !pb.has(1, 2, 2) || !pb.has(1, 2, 6) ) return val msgType = pb[1, 2, 1].asInt - val subType = pb[1, 2, 2].asInt + var subType = 0 + if (pb.has(1, 2, 3)) { + subType = pb[1, 2, 2].asInt + } val msgTime = pb[1, 2, 6].asLong when(msgType) { 33 -> onGroupMemIncreased(msgTime, pb) 34 -> onGroupMemberDecreased(msgTime, pb) 44 -> onGroupAdminChange(msgTime, pb) + 84 -> onGroupApply(msgTime, pb) 528 -> when(subType) { + 35 -> onFriendApply(msgTime, pb) + // invite + 68 -> onGroupApply(msgTime, pb) 138 -> onC2CRecall(msgTime, pb) 290 -> onC2cPoke(msgTime, pb) } 732 -> when(subType) { 12 -> onGroupBan(msgTime, pb) - 17 -> onGroupRecall(msgTime, pb) + 17 -> { + onGroupRecall(msgTime, pb) + // invite + onGroupMemIncreased(msgTime, pb) + } 20 -> onGroupPoke(msgTime, pb) } } @@ -95,6 +106,22 @@ internal object PrimitiveListener { } } + private suspend fun onFriendApply(msgTime: Long, pb: ProtoMap) { + val applierUid = pb[1, 3, 2, 1, 2].asUtf8String + val msg = pb[1, 3, 2, 1, 10].asUtf8String + val source = pb[1, 3, 2, 1, 11].asUtf8String + var applier = ContactHelper.getUinByUidAsync(applierUid).toLong() + if (applier == 0L) { + applier = pb[4, 3, 8].asLong + } + LogCenter.log("来自$applier 的好友申请:$msg ($source)") + if(!GlobalEventTransmitter.PrivateNoticeTransmitter + .transFriendApply(msgTime, applier, msg)) { + LogCenter.log("好友申请推送失败!", Level.WARN) + } + } + + private suspend fun onGroupPoke(time: Long, pb: ProtoMap) { val groupCode1 = pb[1, 1, 1].asULong @@ -155,21 +182,47 @@ internal object PrimitiveListener { } private suspend fun onGroupMemIncreased(time: Long, pb: ProtoMap) { - val groupCode = pb[1, 3, 2, 1].asULong - val targetUid = pb[1, 3, 2, 3].asUtf8String - val type = pb[1, 3, 2, 4].asInt - val operation = ContactHelper.getUinByUidAsync(pb[1, 3, 2, 5].asUtf8String).toLong() - val target = ContactHelper.getUinByUidAsync(targetUid).toLong() + when(pb[1, 2, 1].asInt) { + 732 -> { + // invite + val groupCode = pb[1, 3, 2, 4].asULong + lateinit var target: String + lateinit var operation: String + pb[1, 3, 2, 26, 7].asList + .value + .forEach { + val value = it[2].asUtf8String + when (it[1].asUtf8String) { + "invitee" -> operation = value + "invitor" -> target = value + } + } + val type = 131 + LogCenter.log("群成员增加($groupCode): $target, type = $type") - LogCenter.log("群成员增加($groupCode): $target, type = $type") + if(!GlobalEventTransmitter.GroupNoticeTransmitter + .transGroupMemberNumChanged(time, target.toLong(), groupCode, operation.toLong(), NoticeType.GroupMemIncrease, NoticeSubType.Invite)) { + LogCenter.log("群成员增加推送失败!", Level.WARN) + } + } + 33 -> { + // approve + val groupCode = pb[1, 3, 2, 1].asULong + val targetUid = pb[1, 3, 2, 3].asUtf8String + val type = pb[1, 3, 2, 4].asInt + val operation = ContactHelper.getUinByUidAsync(pb[1, 3, 2, 5].asUtf8String).toLong() + val target = ContactHelper.getUinByUidAsync(targetUid).toLong() + LogCenter.log("群成员增加($groupCode): $target, type = $type") - if(!GlobalEventTransmitter.GroupNoticeTransmitter - .transGroupMemberNumChanged(time, target, groupCode, operation, NoticeType.GroupMemIncrease, when(type) { - 130 -> NoticeSubType.Approve - 131 -> NoticeSubType.Invite - else -> NoticeSubType.Approve - })) { - LogCenter.log("群成员增加推送失败!", Level.WARN) + if(!GlobalEventTransmitter.GroupNoticeTransmitter + .transGroupMemberNumChanged(time, target, groupCode, operation, NoticeType.GroupMemIncrease, when(type) { + 130 -> NoticeSubType.Approve + 131 -> NoticeSubType.Invite + else -> NoticeSubType.Approve + })) { + LogCenter.log("群成员增加推送失败!", Level.WARN) + } + } } } @@ -263,4 +316,32 @@ internal object PrimitiveListener { readPacket.release() } } + + private suspend fun onGroupApply(time: Long, pb: ProtoMap) { + when(pb[1, 2, 1].asInt) { + 84 -> { + val groupCode = pb[1, 3, 2, 1].asULong + val applierUid = pb[1, 3, 2, 3].asUtf8String + val reason = pb[1, 3, 2, 5].asUtf8String + val applier = ContactHelper.getUinByUidAsync(applierUid).toLong() + LogCenter.log("入群申请($groupCode) $applier: \"$reason\"") + + if(!GlobalEventTransmitter.GroupNoticeTransmitter + .transGroupApply(time, applier, reason, groupCode, NoticeSubType.Add)) { + LogCenter.log("入群申请推送失败!", Level.WARN) + } + } + 528 -> { + val groupCode = pb[1, 3, 2, 2, 3].asULong + val applierUid = pb[1, 3, 2, 2, 5].asUtf8String + val applier = ContactHelper.getUinByUidAsync(applierUid).toLong() + LogCenter.log("邀请入群申请($groupCode): $applier") + + if(!GlobalEventTransmitter.GroupNoticeTransmitter + .transGroupApply(time, applier, "", groupCode, NoticeSubType.Invite)) { + LogCenter.log("邀请入群申请推送失败!", Level.WARN) + } + } + } + } } \ No newline at end of file