Skip to content

Commit c8766bf

Browse files
Merge pull request #96 from SLNE-Development/feat/remove-cloud-and-update-with-after-cloud-stuff
Feat/remove cloud and update with after cloud stuff
2 parents c946e76 + 6fa2dfc commit c8766bf

File tree

144 files changed

+2103
-2279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+2103
-2279
lines changed

surf-chat-api/src/main/kotlin/dev/slne/surf/chat/api/DenylistAction.kt

Lines changed: 0 additions & 38 deletions
This file was deleted.

surf-chat-api/src/main/kotlin/dev/slne/surf/chat/api/SurfChatApi.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ interface SurfChatApi {
5757
*/
5858
fun getUser(uuid: UUID): User?
5959

60-
/**
61-
* Creates a new user in the system.
62-
*
63-
* @param name The name of the user.
64-
* @param uuid The UUID of the user.
65-
* @return The created user object.
66-
*/
67-
fun createUser(name: String, uuid: UUID): User
6860

6961
/**
7062
* Looks up chat history based on a filter.

surf-chat-api/src/main/kotlin/dev/slne/surf/chat/api/channel/Channel.kt

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.slne.surf.chat.api.channel
22

3-
import dev.slne.surf.chat.api.entity.ChannelMember
43
import dev.slne.surf.chat.api.entity.User
4+
import dev.slne.surf.chat.api.surfChatApi
55
import it.unimi.dsi.fastutil.objects.ObjectSet
66
import java.util.*
77

@@ -16,21 +16,23 @@ import java.util.*
1616
* @property visibility The visibility status of the channel.
1717
* @property createdAt The timestamp (in milliseconds since epoch) when the channel was created.
1818
*/
19-
interface Channel {
20-
val channelUuid: UUID
21-
val channelName: String
22-
val members: ObjectSet<ChannelMember>
23-
val bannedPlayers: ObjectSet<User>
24-
val invitedPlayers: ObjectSet<User>
25-
var visibility: ChannelVisibility
19+
data class Channel(
20+
val channelUuid: UUID,
21+
val channelName: String,
22+
val members: ObjectSet<ChannelMember>,
23+
val bannedPlayers: ObjectSet<UUID>,
24+
val invitedPlayers: ObjectSet<UUID>,
25+
var visibility: ChannelVisibility,
2626
val createdAt: Long
27-
27+
) {
2828
/**
2929
* Allows a user to join the channel.
3030
*
3131
* @param user The user attempting to join the channel.
3232
*/
33-
fun join(user: User)
33+
fun join(user: User) {
34+
members.add(ChannelMember(user.uuid, user.name, ChannelRole.MEMBER))
35+
}
3436

3537
/**
3638
* Removes a member from the channel.
@@ -71,82 +73,135 @@ interface Channel {
7173
*
7274
* @param member The member to transfer ownership to.
7375
*/
74-
fun transfer(member: ChannelMember)
76+
fun transfer(member: ChannelMember) {
77+
members.removeIf { it.role == ChannelRole.OWNER }
78+
members.removeIf { it.uuid == member.uuid }
79+
members.add(ChannelMember(member.uuid, member.name, ChannelRole.OWNER))
80+
}
7581

7682
/**
7783
* Leaves the channel and transfers ownership to another member.
7884
*
7985
* @param member The member to transfer ownership to.
8086
*/
81-
fun leaveAndTransfer(member: ChannelMember)
87+
fun leaveAndTransfer(member: ChannelMember) {
88+
if (this.isOwner(member)) {
89+
var nextOwner =
90+
this.members.firstOrNull { it.hasModeratorPermissions() && it.uuid != member.uuid }
91+
92+
if (nextOwner == null) {
93+
nextOwner = this.members.firstOrNull { it.uuid != member.uuid }
94+
}
95+
96+
if (nextOwner == null) {
97+
surfChatApi.deleteChannel(this)
98+
return
99+
}
100+
101+
this.transfer(nextOwner)
102+
}
103+
104+
this.removeMember(member)
105+
}
82106

83107
/**
84108
* Checks if a user is invited to the channel.
85109
*
86110
* @param user The user to check.
87111
* @return `true` if the user is invited, otherwise `false`.
88112
*/
89-
fun isInvited(user: User) = invitedPlayers.contains(user)
113+
fun isInvited(user: User) = invitedPlayers.contains(user.uuid)
90114

91115
/**
92116
* Invites a user to the channel.
93117
*
94118
* @param user The user to invite.
95119
* @return `true` if the user was successfully invited, otherwise `false`.
96120
*/
97-
fun invite(user: User) = invitedPlayers.add(user)
121+
fun invite(user: User) = invitedPlayers.add(user.uuid)
98122

99123
/**
100124
* Revokes an invitation for a user.
101125
*
102126
* @param user The user whose invitation is to be revoked.
103127
* @return `true` if the invitation was successfully revoked, otherwise `false`.
104128
*/
105-
fun revoke(user: User) = invitedPlayers.remove(user)
129+
fun revoke(user: User) = invitedPlayers.remove(user.uuid)
106130

107131
/**
108132
* Promotes a member to a higher role in the channel.
109133
*
110134
* @param member The member to promote.
111135
* @return `true` if the promotion was successful, otherwise `false`.
112136
*/
113-
fun promote(member: ChannelMember): Boolean
137+
fun promote(member: ChannelMember): Boolean {
138+
if (member.role == ChannelRole.MODERATOR) {
139+
return false
140+
}
141+
142+
member.role = ChannelRole.MODERATOR
143+
144+
members.remove(member)
145+
return members.add(member)
146+
}
114147

115148
/**
116149
* Demotes a member to a lower role in the channel.
117150
*
118151
* @param member The member to demote.
119152
* @return `true` if the demotion was successful, otherwise `false`.
120153
*/
121-
fun demote(member: ChannelMember): Boolean
154+
fun demote(member: ChannelMember): Boolean {
155+
if (member.role == ChannelRole.MEMBER) {
156+
return false
157+
}
158+
159+
member.role = ChannelRole.MEMBER
160+
161+
members.remove(member)
162+
return members.add(member)
163+
}
122164

123165
/**
124166
* Bans a user from the channel.
125167
*
126168
* @param user The user to ban.
127169
*/
128-
fun ban(user: User)
170+
fun ban(user: User) {
171+
if (this.isBanned(user)) {
172+
return
173+
}
174+
175+
members.removeIf { it.uuid == user.uuid }
176+
bannedPlayers.add(user.uuid)
177+
}
129178

130179
/**
131180
* Unbans a user from the channel.
132181
*
133182
* @param user The user to unban.
134183
* @return `true` if the user was successfully unbanned, otherwise `false`.
135184
*/
136-
fun unban(user: User) = bannedPlayers.remove(user)
185+
fun unban(user: User) = bannedPlayers.remove(user.uuid)
137186

138187
/**
139188
* Checks if a user is banned from the channel.
140189
*
141190
* @param user The user to check.
142191
* @return `true` if the user is banned, otherwise `false`.
143192
*/
144-
fun isBanned(user: User): Boolean = bannedPlayers.contains(user)
193+
fun isBanned(user: User): Boolean = bannedPlayers.contains(user.uuid)
145194

146195
/**
147196
* Kicks a member from the channel.
148197
*
149198
* @param member The member to kick.
150199
*/
151-
fun kick(member: ChannelMember)
200+
fun kick(member: ChannelMember) {
201+
if (!members.contains(member)) {
202+
return
203+
}
204+
205+
leaveAndTransfer(member)
206+
}
152207
}

surf-chat-api/src/main/kotlin/dev/slne/surf/chat/api/entity/ChannelMember.kt renamed to surf-chat-api/src/main/kotlin/dev/slne/surf/chat/api/channel/ChannelMember.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package dev.slne.surf.chat.api.entity
1+
package dev.slne.surf.chat.api.channel
22

3-
import dev.slne.surf.chat.api.channel.ChannelRole
43
import java.util.*
54

65
/**
@@ -10,11 +9,11 @@ import java.util.*
109
* @property name The name of the channel member.
1110
* @property role The role of the channel member in the chat channel.
1211
*/
13-
interface ChannelMember {
14-
val uuid: UUID // The unique ID of the member
15-
val name: String // The name of the member
16-
var role: ChannelRole // The role of the member in the channel
17-
12+
data class ChannelMember(
13+
val uuid: UUID,
14+
val name: String,
15+
var role: ChannelRole
16+
) {
1817
/**
1918
* Checks if the member has moderator permissions.
2019
*
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package dev.slne.surf.chat.api.denylist
2+
3+
/**
4+
* Represents an action to be applied to a user in the denylist system.
5+
* This action is typically used for enforcement of chat rules
6+
* and allows specifying the type of action, its duration, and the reason for it.
7+
*/
8+
data class DenylistAction(
9+
val name: String,
10+
val actionType: DenylistActionType,
11+
val reason: String,
12+
val duration: Long
13+
)

surf-chat-api/src/main/kotlin/dev/slne/surf/chat/api/entry/DenylistActionType.kt renamed to surf-chat-api/src/main/kotlin/dev/slne/surf/chat/api/denylist/DenylistActionType.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dev.slne.surf.chat.api.entry
1+
package dev.slne.surf.chat.api.denylist
22

33
/**
44
* Represents the type of action to be taken for a denylist entry.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package dev.slne.surf.chat.api.denylist
2+
3+
/**
4+
* Represents an entry in the denylist system.
5+
*
6+
* This interface defines the structure and details associated with a denylist entry.
7+
* It includes information about the word triggering the denylist, the reason for
8+
* its presence in the denylist, and metadata about who added it and when it was added.
9+
* The associated action specifies the type of moderation enforcement to apply when
10+
* the denylist entry is triggered.
11+
*/
12+
data class DenylistEntry(
13+
val word: String,
14+
val reason: String,
15+
val addedBy: String,
16+
val addedAt: Long,
17+
val action: DenylistAction
18+
)
Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,24 @@
11
package dev.slne.surf.chat.api.entity
22

3-
import dev.slne.surf.chat.api.channel.Channel
3+
import dev.slne.surf.chat.api.entry.IgnoreListEntry
4+
import kotlinx.serialization.Contextual
5+
import kotlinx.serialization.Serializable
46
import java.util.*
57

8+
@Serializable
69
/**
710
* Represents a user in the chat system.
811
*
912
* @property name The name of the user.
1013
* @property uuid The unique identifier of the user.
1114
*/
12-
interface User {
13-
val name: String
14-
val uuid: UUID
15+
data class User(
16+
val name: String,
17+
val uuid: @Contextual UUID,
1518

16-
/**
17-
* Checks if the user has a specific permission.
18-
*
19-
* @param permission The permission to check.
20-
* @return `true` if the user has the specified permission, otherwise `false`.
21-
*/
22-
fun hasPermission(permission: String): Boolean
19+
var directMessagesEnabled: Boolean = true,
20+
var channelInviteMessagesEnabled: Boolean = true,
21+
var chatPingsEnabled: Boolean = true,
2322

24-
/**
25-
* Provides a configurable interface for the user.
26-
*
27-
* @return An instance of `ConfigurableUser` to manage user settings.
28-
*/
29-
fun configure(): ConfigurableUser
30-
31-
/**
32-
* Retrieves the user's membership in a specific channel.
33-
*
34-
* @param channel The channel to check membership for.
35-
* @return An instance of `ChannelMember` if the user is a member of the channel, otherwise `null`.
36-
*/
37-
fun channelMember(channel: Channel): ChannelMember?
38-
}
23+
val ignorelist: MutableList<IgnoreListEntry> = mutableListOf()
24+
)

0 commit comments

Comments
 (0)