Skip to content

Commit 73eb481

Browse files
committed
Support joinTimestamp and lastSpeakTimestamp, fix #865, fix #394
1 parent 4467f69 commit 73eb481

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

mirai-core-api/src/commonMain/kotlin/contact/NormalMember.kt

+14
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ public interface NormalMember : Member {
6363
*/
6464
public val muteTimeRemaining: Int
6565

66+
/**
67+
* 入群时间. 单位为秒.
68+
*
69+
* @since 2.1
70+
*/
71+
public val joinTimestamp: Int
72+
73+
/**
74+
* 最后发言时间. 单位为秒.
75+
*
76+
* @since 2.1
77+
*/
78+
public val lastSpeakTimestamp: Int
79+
6680
/**
6781
* 解除禁言.
6882
*

mirai-core-api/src/commonMain/kotlin/data/MemberInfo.kt

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020 Mamoe Technologies and contributors.
2+
* Copyright 2019-2021 Mamoe Technologies and contributors.
33
*
44
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
55
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@@ -23,4 +23,14 @@ public interface MemberInfo : UserInfo {
2323
public val muteTimestamp: Int
2424

2525
public val anonymousId: String? get() = null
26+
27+
/**
28+
* 入群时间 秒
29+
*/
30+
public val joinTimestamp: Int
31+
32+
/**
33+
* 上次发言时间 秒
34+
*/
35+
public val lastSpeakTimestamp: Int
2636
}

mirai-core/src/commonMain/kotlin/contact/MemberInfoImpl.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020 Mamoe Technologies and contributors.
2+
* Copyright 2019-2021 Mamoe Technologies and contributors.
33
*
44
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
55
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@@ -12,6 +12,7 @@ package net.mamoe.mirai.internal.contact
1212
import net.mamoe.mirai.contact.MemberPermission
1313
import net.mamoe.mirai.data.MemberInfo
1414
import net.mamoe.mirai.internal.network.protocol.data.jce.StTroopMemberInfo
15+
import net.mamoe.mirai.utils.currentTimeSeconds
1516

1617
internal class MemberInfoImpl(
1718
override val uin: Long,
@@ -22,6 +23,8 @@ internal class MemberInfoImpl(
2223
override val specialTitle: String,
2324
override val muteTimestamp: Int,
2425
override val anonymousId: String?,
26+
override val joinTimestamp: Int = currentTimeSeconds().toInt(),
27+
override var lastSpeakTimestamp: Int = 0
2528
) : MemberInfo, UserInfoImpl(uin, nick, remark) {
2629
constructor(
2730
jceInfo: StTroopMemberInfo,
@@ -39,5 +42,7 @@ internal class MemberInfoImpl(
3942
specialTitle = jceInfo.sSpecialTitle.orEmpty(),
4043
muteTimestamp = jceInfo.dwShutupTimestap?.toInt() ?: 0,
4144
anonymousId = null,
45+
joinTimestamp = jceInfo.dwJoinTime?.toInt() ?: 0,
46+
lastSpeakTimestamp = jceInfo.dwLastSpeakTime?.toInt() ?: 0
4247
)
4348
}

mirai-core/src/commonMain/kotlin/contact/NormalMemberImpl.kt

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ internal class NormalMemberImpl constructor(
4343
@Suppress("unused") // false positive
4444
val lastMessageSequence: AtomicInt = atomic(-1)
4545

46+
override val joinTimestamp: Int get() = info.joinTimestamp
47+
override val lastSpeakTimestamp: Int get() = info.lastSpeakTimestamp
48+
4649
override fun toString(): String = "NormalMember($id)"
4750

4851
@Suppress("UNCHECKED_CAST")

mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020 Mamoe Technologies and contributors.
2+
* Copyright 2019-2021 Mamoe Technologies and contributors.
33
*
44
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
55
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@@ -103,6 +103,10 @@ internal object OnlinePushPbPushGroupMsg : IncomingPacketFactory<Packet?>("Onlin
103103
name = findSenderName(extraInfo, msgHead.groupInfo) ?: sender.nameCardOrNick
104104
}
105105

106+
sender.info?.castOrNull<MemberInfoImpl>()?.run {
107+
lastSpeakTimestamp = currentTimeSeconds().toInt()
108+
}
109+
106110
if (isFromSelfAccount) {
107111
return GroupMessageSyncEvent(
108112
message = msgs.toMessageChain(

0 commit comments

Comments
 (0)