Merge pull request #55 from ikechan8370/master

fix: グループイベントが正しく通知されない問題
This commit is contained in:
白池 2023-11-17 19:32:28 +08:00 committed by GitHub
commit 472b17f744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 134 additions and 17 deletions

View File

@ -311,6 +311,27 @@ internal object GlobalEventTransmitter: BaseSvc() {
)) ))
return true 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, selfId = app.longAccountUin,
postType = PostType.Notice, postType = PostType.Notice,
type = NoticeType.FriendRecall, type = NoticeType.FriendRecall,
subType = NoticeSubType.Poke,
operatorId = operation, operatorId = operation,
userId = operation, userId = operation,
msgId = msgHashId, msgId = msgHashId,
@ -346,6 +366,19 @@ internal object GlobalEventTransmitter: BaseSvc() {
)) ))
return true 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 @ShamrockDsl

View File

@ -10,7 +10,9 @@ internal enum class NoticeType {
@SerialName("group_decrease") GroupMemDecrease, @SerialName("group_decrease") GroupMemDecrease,
@SerialName("group_increase") GroupMemIncrease, @SerialName("group_increase") GroupMemIncrease,
@SerialName("group_recall") GroupRecall, @SerialName("group_recall") GroupRecall,
@SerialName("group_apply") GroupApply,
@SerialName("friend_recall") FriendRecall, @SerialName("friend_recall") FriendRecall,
@SerialName("friend_add") FriendApply,
@SerialName("notify") Notify, @SerialName("notify") Notify,
@SerialName("group_upload") GroupUpload, @SerialName("group_upload") GroupUpload,
@SerialName("private_upload") PrivateUpload @SerialName("private_upload") PrivateUpload
@ -26,6 +28,7 @@ internal enum class NoticeSubType {
@SerialName("set") Set, @SerialName("set") Set,
@SerialName("un_set") UnSet, @SerialName("un_set") UnSet,
@SerialName("add") Add,
@SerialName("invite") Invite, @SerialName("invite") Invite,
@SerialName("approve") Approve, @SerialName("approve") Approve,
@SerialName("leave") Leave, @SerialName("leave") Leave,

View File

@ -47,23 +47,34 @@ internal object PrimitiveListener {
if ( if (
!pb.has(1, 3) !pb.has(1, 3)
|| !pb.has(1, 2) || !pb.has(1, 2)
|| !pb.has(1, 2, 2) // || !pb.has(1, 2, 2)
|| !pb.has(1, 2, 6) || !pb.has(1, 2, 6)
) return ) return
val msgType = pb[1, 2, 1].asInt 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 val msgTime = pb[1, 2, 6].asLong
when(msgType) { when(msgType) {
33 -> onGroupMemIncreased(msgTime, pb) 33 -> onGroupMemIncreased(msgTime, pb)
34 -> onGroupMemberDecreased(msgTime, pb) 34 -> onGroupMemberDecreased(msgTime, pb)
44 -> onGroupAdminChange(msgTime, pb) 44 -> onGroupAdminChange(msgTime, pb)
84 -> onGroupApply(msgTime, pb)
528 -> when(subType) { 528 -> when(subType) {
35 -> onFriendApply(msgTime, pb)
// invite
68 -> onGroupApply(msgTime, pb)
138 -> onC2CRecall(msgTime, pb) 138 -> onC2CRecall(msgTime, pb)
290 -> onC2cPoke(msgTime, pb) 290 -> onC2cPoke(msgTime, pb)
} }
732 -> when(subType) { 732 -> when(subType) {
12 -> onGroupBan(msgTime, pb) 12 -> onGroupBan(msgTime, pb)
17 -> onGroupRecall(msgTime, pb) 17 -> {
onGroupRecall(msgTime, pb)
// invite
onGroupMemIncreased(msgTime, pb)
}
20 -> onGroupPoke(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) { private suspend fun onGroupPoke(time: Long, pb: ProtoMap) {
val groupCode1 = pb[1, 1, 1].asULong val groupCode1 = pb[1, 1, 1].asULong
@ -155,12 +182,36 @@ internal object PrimitiveListener {
} }
private suspend fun onGroupMemIncreased(time: Long, pb: ProtoMap) { private suspend fun onGroupMemIncreased(time: Long, pb: ProtoMap) {
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")
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 groupCode = pb[1, 3, 2, 1].asULong
val targetUid = pb[1, 3, 2, 3].asUtf8String val targetUid = pb[1, 3, 2, 3].asUtf8String
val type = pb[1, 3, 2, 4].asInt val type = pb[1, 3, 2, 4].asInt
val operation = ContactHelper.getUinByUidAsync(pb[1, 3, 2, 5].asUtf8String).toLong() val operation = ContactHelper.getUinByUidAsync(pb[1, 3, 2, 5].asUtf8String).toLong()
val target = ContactHelper.getUinByUidAsync(targetUid).toLong() val target = ContactHelper.getUinByUidAsync(targetUid).toLong()
LogCenter.log("群成员增加($groupCode): $target, type = $type") LogCenter.log("群成员增加($groupCode): $target, type = $type")
if(!GlobalEventTransmitter.GroupNoticeTransmitter if(!GlobalEventTransmitter.GroupNoticeTransmitter
@ -172,6 +223,8 @@ internal object PrimitiveListener {
LogCenter.log("群成员增加推送失败!", Level.WARN) LogCenter.log("群成员增加推送失败!", Level.WARN)
} }
} }
}
}
private suspend fun onGroupMemberDecreased(time: Long, pb: ProtoMap) { private suspend fun onGroupMemberDecreased(time: Long, pb: ProtoMap) {
val groupCode = pb[1, 3, 2, 1].asULong val groupCode = pb[1, 3, 2, 1].asULong
@ -263,4 +316,32 @@ internal object PrimitiveListener {
readPacket.release() 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)
}
}
}
}
} }