diff options
| author | Sho Sakuma <me@m1sk9.dev> | 2026-03-18 13:45:01 +0900 |
|---|---|---|
| committer | Sho Sakuma <me@m1sk9.dev> | 2026-03-18 13:45:01 +0900 |
| commit | 2be902e6858d59bf02aa72a6702e55e6b371fbc9 (patch) | |
| tree | 396fb7865de65e806faef63339b4c112131b0fb1 | |
| parent | bed6a970165d6aa70473df842606d5f8ed1897e7 (diff) | |
| download | LunaticChat-2be902e6858d59bf02aa72a6702e55e6b371fbc9.tar.gz LunaticChat-2be902e6858d59bf02aa72a6702e55e6b371fbc9.tar.bz2 LunaticChat-2be902e6858d59bf02aa72a6702e55e6b371fbc9.zip | |
test: Add test-case, ignore listener
4 files changed, 47 insertions, 10 deletions
diff --git a/codecov.yml b/codecov.yml index dcf139a..af5cb56 100644 --- a/codecov.yml +++ b/codecov.yml @@ -13,3 +13,4 @@ comment: require_changes: false ignore: - "dokka/**" + - "platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/listener/**" diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt index 463bf24..7e28872 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt @@ -448,7 +448,7 @@ class ChannelManager( /** * Restores the active channel of a player based on their channel membership. - * If the player is a member of any channel, the first one found is set as active. + * If the player is a member of multiple channels, the most recently joined one is selected. * * @param playerId The UUID of the player. * @return The restored ChannelContext, or null if the player is not a member of any channel. @@ -457,12 +457,15 @@ class ChannelManager( // Already has an active channel getPlayerChannelContext(playerId)?.let { return it } - // Find a channel where this player is a member + // Find the most recently joined channel for this player val channelId = membersCache.entries - .firstOrNull { (_, members) -> - members.any { it.playerId == playerId } - }?.key ?: return null + .mapNotNull { (channelId, members) -> + members.find { it.playerId == playerId }?.let { member -> + channelId to member.joinedAt + } + }.maxByOrNull { it.second } + ?.first ?: return null val channel = channelsCache[channelId] ?: return null val members = membersCache[channelId]?.toList() ?: return null diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/listener/PlayerPresenceListener.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/listener/PlayerPresenceListener.kt index 91d2cd9..56cbe59 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/listener/PlayerPresenceListener.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/listener/PlayerPresenceListener.kt @@ -29,11 +29,13 @@ class PlayerPresenceListener( // Send update notification if available if (updateCheckerFlag.get() && player.hasAnyPermission { +LunaticChatPermissionNode.NoticeUpdate }) { lunaticChat.server.asyncScheduler.runDelayed(lunaticChat, { _ -> - player.sendMessage( - MessageFormatter - .format(languageManager.getMessage("general.newUpdateAvailable")) - .clickEvent(ClickEvent.openUrl("https://github.com/m1sk9/LunaticChat/releases/latest")), - ) + if (player.isOnline) { + player.sendMessage( + MessageFormatter + .format(languageManager.getMessage("general.newUpdateAvailable")) + .clickEvent(ClickEvent.openUrl("https://github.com/m1sk9/LunaticChat/releases/latest")), + ) + } }, 3, TimeUnit.SECONDS) } diff --git a/platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManagerTest.kt b/platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManagerTest.kt index 8174a33..239da52 100644 --- a/platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManagerTest.kt +++ b/platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManagerTest.kt @@ -547,6 +547,37 @@ class ChannelManagerTest { } @Test + fun `restorePlayerChannel should select most recently joined channel`() { + val memberId = createTestUUID(3) + val oldMember = + ChannelMember(channelId = "old-ch", playerId = memberId, role = ChannelRole.MEMBER, joinedAt = 1000L) + val newMember = + ChannelMember(channelId = "new-ch", playerId = memberId, role = ChannelRole.MEMBER, joinedAt = 2000L) + val owner1 = createTestUUID(1) + val owner2 = createTestUUID(2) + val oldChannel = createTestChannel(id = "old-ch", name = "Old Channel", ownerId = owner1) + val newChannel = createTestChannel(id = "new-ch", name = "New Channel", ownerId = owner2) + + val data = + ChannelData( + channels = mapOf("old-ch" to oldChannel, "new-ch" to newChannel), + members = + mapOf( + "old-ch" to listOf(oldMember), + "new-ch" to listOf(newMember), + ), + ) + + val (manager, _, _) = createManager(initialData = data) + manager.initialize() + + // Should restore to the most recently joined channel + val context = manager.restorePlayerChannel(memberId) + assertNotNull(context) + assertEquals("new-ch", context.channelId) + } + + @Test fun `saveToDisk should call storage saveToDisk`() { val (manager, storage, _) = createManager() manager.initialize() |
