Browse Source

Documentation

tags/v0.3.1
Chris Smith 5 years ago
parent
commit
1ee6e69673

+ 2
- 0
CHANGELOG View File

@@ -1,5 +1,7 @@
1 1
 vNEXT (in development)
2 2
 
3
+  * Added more documentation to public methods/classes
4
+
3 5
 v0.3.0
4 6
 
5 7
   * Simplified how messages are constructed.

+ 9
- 0
src/main/kotlin/com/dmdirc/ktirc/io/CaseMapping.kt View File

@@ -1,9 +1,15 @@
1 1
 package com.dmdirc.ktirc.io
2 2
 
3
+/**
4
+ * Supported options for mapping between uppercase and lowercase characters.
5
+ */
3 6
 enum class CaseMapping(private val lowerToUpperMapping: Pair<IntRange, IntRange>) {
4 7
 
8
+    /** Standard ASCII mapping, `a-z` is mapped to `A-Z`. */
5 9
     Ascii(97..122 to 65..90),
10
+    /** Mapping probably intended by RFC14159, `a-z{|}~` is mapped to `A-Z[\]^`. */
6 11
     Rfc(97..126 to 65..94),
12
+    /** Mapping according to a strict interpretation of RFC14159, `a-z{|}` is mapped to `A-Z[\]]`. */
7 13
     RfcStrict(97..125 to 65..93);
8 14
 
9 15
     companion object {
@@ -15,6 +21,9 @@ enum class CaseMapping(private val lowerToUpperMapping: Pair<IntRange, IntRange>
15 21
         }
16 22
     }
17 23
 
24
+    /**
25
+     * Determines if the two strings are equivalent under the casemapping rules.
26
+     */
18 27
     fun areEquivalent(string1: String, string2: String): Boolean {
19 28
         return string1.length == string2.length
20 29
                 && string1.zip(string2).all { (c1, c2) -> areEquivalent(c1, c2) }

+ 37
- 0
src/main/kotlin/com/dmdirc/ktirc/model/CapabilitiesState.kt View File

@@ -1,38 +1,75 @@
1 1
 package com.dmdirc.ktirc.model
2 2
 
3
+/**
4
+ * Describes the state of capability negotiation with the server.
5
+ */
3 6
 class CapabilitiesState {
4 7
 
8
+    /** The current negotiation state. */
5 9
     var negotiationState: CapabilitiesNegotiationState = CapabilitiesNegotiationState.AWAITING_LIST
10
+        internal set
6 11
 
12
+    // TODO: These should only be mutable internally
13
+    /** The capabilities that were advertised by the server. */
7 14
     val advertisedCapabilities = HashMap<Capability, String>()
15
+    /** The capabilities that we have agreed to enable. */
8 16
     val enabledCapabilities = HashMap<Capability, String>()
9 17
 
10 18
 }
11 19
 
20
+/**
21
+ * The state of negotiations with the server.
22
+ */
12 23
 enum class CapabilitiesNegotiationState {
24
+
25
+    /**
26
+     * We have requested a list of capabilities and are awaiting a reply.
27
+     */
13 28
     AWAITING_LIST,
29
+
30
+    /**
31
+     * We have sent a list of capabilities to enable, and are awaiting an acknowledgement.
32
+     */
14 33
     AWAITING_ACK,
34
+
35
+    /**
36
+     * Negotiation has completed.
37
+     */
15 38
     FINISHED
39
+
16 40
 }
17 41
 
42
+/**
43
+ * IRCv3 capabilities supported by the client.
44
+ */
18 45
 @Suppress("unused")
19 46
 sealed class Capability(val name: String) {
20 47
     // Capabilities that enable more information in message tags:
48
+    /** Messages are tagged with the server time they originated at. */
21 49
     object ServerTimeMessageTag : Capability("server-time")
50
+    /** Messages are tagged with the sender's account name. */
22 51
     object UserAccountMessageTag : Capability("account-tag")
23 52
 
24 53
     // Capabilities that extend existing commands to supply extra information:
54
+    /** Hosts are included for users in NAMES messages. */
25 55
     object HostsInNamesReply : Capability("userhost-in-names")
56
+    /** Multiple mode prefixes are returned per-user in NAMES messages. */
26 57
     object MultipleUserModePrefixes : Capability("multi-prefix")
58
+    /** The user's account and real name are provided when they join a channel. */
27 59
     object AccountAndRealNameInJoinMessages : Capability("extended-join")
28 60
 
29 61
     // Capabilities that affect how messages are sent/received:
62
+    /** Messages sent by the client are echo'd back on successful delivery. */
30 63
     object EchoMessages : Capability("echo-message")
31 64
 
32 65
     // Capabilities that notify us of changes to other clients:
66
+    /** Receive a notification when a user's account changes. */
33 67
     object AccountChangeMessages : Capability("account-notify") // TODO: Add processor
68
+    /** Receive a notification when a user's away state changes. */
34 69
     object AwayStateMessages : Capability("away-notify") // TODO: Add processor
70
+    /** Receive a notification when a user's host changes, instead of a quit/join. */
35 71
     object HostChangeMessages : Capability("chghost") // TODO: Add processor
72
+
36 73
 }
37 74
 
38 75
 internal val capabilities: Map<String, Capability> by lazy {

+ 9
- 0
src/main/kotlin/com/dmdirc/ktirc/model/CaseInsensitiveSet.kt View File

@@ -22,10 +22,19 @@ class CaseInsensitiveSet(private val caseMappingProvider: () -> CaseMapping) : I
22 22
         items.removeIf { caseMappingProvider().areEquivalent(it, item) }
23 23
     }
24 24
 
25
+    /**
26
+     * Determines if this set contains the given item, case-insensitively.
27
+     */
25 28
     operator fun contains(item: String) = items.any { caseMappingProvider().areEquivalent(it, item) }
26 29
 
30
+    /**
31
+     * Returns a read-only iterator over items in this set.
32
+     */
27 33
     override operator fun iterator() = items.iterator().iterator()
28 34
 
35
+    /**
36
+     * Returns true if this set is empty.
37
+     */
29 38
     fun isEmpty() = items.isEmpty()
30 39
 
31 40
 }

+ 14
- 0
src/main/kotlin/com/dmdirc/ktirc/model/ChannelState.kt View File

@@ -2,11 +2,25 @@ package com.dmdirc.ktirc.model
2 2
 
3 3
 import com.dmdirc.ktirc.io.CaseMapping
4 4
 
5
+/**
6
+ * Describes the state of a channel that the client has joined.
7
+ */
5 8
 class ChannelState(val name: String, caseMappingProvider: () -> CaseMapping) {
6 9
 
10
+    /**
11
+     * Whether or not we are in the process of receiving a user list (which may span many messages).
12
+     */
7 13
     var receivingUserList = false
14
+        internal set
15
+
16
+    /**
17
+     * A map of all users in the channel to their current modes.
18
+     */
8 19
     val users = ChannelUserMap(caseMappingProvider)
9 20
 
10 21
 }
11 22
 
23
+/**
24
+ * Describes a user in a channel, and their modes.
25
+ */
12 26
 data class ChannelUser(var nickname: String, var modes: String = "")

+ 10
- 0
src/main/kotlin/com/dmdirc/ktirc/model/IrcMessage.kt View File

@@ -5,14 +5,19 @@ import com.dmdirc.ktirc.util.currentTimeZoneProvider
5 5
 import java.time.Instant
6 6
 import java.time.LocalDateTime
7 7
 
8
+/**
9
+ * Represents an IRC protocol message.
10
+ */
8 11
 class IrcMessage(val tags: Map<MessageTag, String>, val prefix: ByteArray?, val command: String, val params: List<ByteArray>) {
9 12
 
13
+    /** The time at which the message was sent, or our best guess at it. */
10 14
     val time: LocalDateTime = if (MessageTag.ServerTime in tags) {
11 15
         LocalDateTime.ofInstant(Instant.parse(tags[MessageTag.ServerTime]), currentTimeZoneProvider())
12 16
     } else {
13 17
         currentTimeProvider()
14 18
     }
15 19
 
20
+    /** The user that generated the message, if any. */
16 21
     val sourceUser by lazy {
17 22
         prefix?.asUser()?.apply {
18 23
             tags[MessageTag.AccountName]?.let { account = it }
@@ -21,8 +26,13 @@ class IrcMessage(val tags: Map<MessageTag, String>, val prefix: ByteArray?, val
21 26
 
22 27
 }
23 28
 
29
+/**
30
+ * Supported tags that may be applied to messages
31
+ */
24 32
 sealed class MessageTag(val name: String) {
33
+    /** Specifies the account name of the user, if the `account-tag` capability is negotiated. */
25 34
     object AccountName : MessageTag("account")
35
+    /** Specifies the time the server received the message, if the `server-time` capability is negotiated. */
26 36
     object ServerTime : MessageTag("time")
27 37
 }
28 38
 

+ 11
- 0
src/main/kotlin/com/dmdirc/ktirc/model/Maps.kt View File

@@ -2,10 +2,14 @@ package com.dmdirc.ktirc.model
2 2
 
3 3
 import com.dmdirc.ktirc.io.CaseMapping
4 4
 
5
+/**
6
+ * Provides a case-insensitive mapping from a String to some value, according to the provided [CaseMapping].
7
+ */
5 8
 abstract class CaseInsensitiveMap<T>(private val caseMappingProvider: () -> CaseMapping, private val nameOf: (T) -> String) : Iterable<T> {
6 9
 
7 10
     private val values = HashSet<T>()
8 11
 
12
+    /** Gets the value of the given key, if present. */
9 13
     operator fun get(name: String) = values.find { caseMappingProvider().areEquivalent(nameOf(it), name) }
10 14
 
11 15
     internal operator fun plusAssign(value: T) {
@@ -17,8 +21,10 @@ abstract class CaseInsensitiveMap<T>(private val caseMappingProvider: () -> Case
17 21
         values.removeIf { caseMappingProvider().areEquivalent(nameOf(it), name) }
18 22
     }
19 23
 
24
+    /** Returns true if the given key exists in this map. */
20 25
     operator fun contains(name: String) = get(name) != null
21 26
 
27
+    /** Provides a read-only iterator over the values in this map. */
22 28
     override fun iterator() = values.iterator().iterator()
23 29
 
24 30
     internal fun clear() = values.clear()
@@ -27,6 +33,11 @@ abstract class CaseInsensitiveMap<T>(private val caseMappingProvider: () -> Case
27 33
 
28 34
 }
29 35
 
36
+/** Maps a channel name to a [ChannelState] instance. */
30 37
 class ChannelStateMap(caseMappingProvider: () -> CaseMapping) : CaseInsensitiveMap<ChannelState>(caseMappingProvider, ChannelState::name)
38
+
39
+/** Maps a nickname to a [ChannelUser] instance. */
31 40
 class ChannelUserMap(caseMappingProvider: () -> CaseMapping) : CaseInsensitiveMap<ChannelUser>(caseMappingProvider, ChannelUser::nickname)
41
+
42
+/** Maps a nickname to a [KnownUser] instance. */
32 43
 class UserMap(caseMappingProvider: () -> CaseMapping) : CaseInsensitiveMap<KnownUser>(caseMappingProvider, { it.details.nickname })

+ 1
- 0
src/main/kotlin/com/dmdirc/ktirc/model/Profile.kt View File

@@ -1,3 +1,4 @@
1 1
 package com.dmdirc.ktirc.model
2 2
 
3
+/** Describes the client's profile information that will be provided to a server. */
3 4
 data class Profile(val initialNick: String, val realName: String, val userName: String)

+ 3
- 0
src/main/kotlin/com/dmdirc/ktirc/model/Server.kt View File

@@ -1,3 +1,6 @@
1 1
 package com.dmdirc.ktirc.model
2 2
 
3
+/**
4
+ * Describes a server to connect to.
5
+ */
3 6
 data class Server(val host: String, val port: Int, val tls: Boolean = false, val password: String? = null)

+ 21
- 0
src/main/kotlin/com/dmdirc/ktirc/model/ServerState.kt View File

@@ -27,10 +27,16 @@ class ServerState internal constructor(initialNickname: String) {
27 27
 
28 28
 }
29 29
 
30
+/**
31
+ * Maps known features onto their values, enforcing type safety.
32
+ */
30 33
 class ServerFeatureMap {
31 34
 
32 35
     private val features = HashMap<ServerFeature<*>, Any?>()
33 36
 
37
+    /**
38
+     * Gets the value, or the default value, of the given feature.
39
+     */
34 40
     @Suppress("UNCHECKED_CAST")
35 41
     operator fun <T : Any> get(feature: ServerFeature<T>) = features.getOrDefault(feature, feature.default) as? T? ?: feature.default
36 42
 
@@ -44,20 +50,35 @@ class ServerFeatureMap {
44 50
 
45 51
 }
46 52
 
53
+/**
54
+ * Stores the mapping of mode prefixes received from the server.
55
+ */
47 56
 data class ModePrefixMapping(val modes: String, val prefixes: String) {
48 57
 
58
+    /** Determines whether the given character is a mode prefix (e.g. "@", "+"). */
49 59
     fun isPrefix(char: Char) = prefixes.contains(char)
60
+    /** Gets the mode corresponding to the given prefix (e.g. "@" -> "o"). */
50 61
     fun getMode(prefix: Char) = modes[prefixes.indexOf(prefix)]
62
+    /** Gets the modes corresponding to the given prefixes (e.g. "@+" -> "ov"). */
51 63
     fun getModes(prefixes: String) = String(prefixes.map(this::getMode).toCharArray())
52 64
 
53 65
 }
54 66
 
67
+/**
68
+ * Describes a server feature determined from the 005 response.
69
+ */
55 70
 sealed class ServerFeature<T : Any>(val name: String, val type: KClass<T>, val default: T? = null) {
71
+    /** The case mapping the server uses, defaulting to RFC. */
56 72
     object ServerCaseMapping : ServerFeature<CaseMapping>("CASEMAPPING", CaseMapping::class, CaseMapping.Rfc)
73
+    /** The mode prefixes the server uses, defaulting to ov/@+. */
57 74
     object ModePrefixes : ServerFeature<ModePrefixMapping>("PREFIX", ModePrefixMapping::class, ModePrefixMapping("ov", "@+"))
75
+    /** The maximum number of channels a client may join. */
58 76
     object MaximumChannels : ServerFeature<Int>("MAXCHANNELS", Int::class) // TODO: CHANLIMIT also exists
77
+    /** The modes supported in channels. */
59 78
     object ChannelModes : ServerFeature<String>("CHANMODES", String::class)
79
+    /** The maximum length of a channel name, defaulting to 200. */
60 80
     object MaximumChannelNameLength : ServerFeature<Int>("CHANNELLEN", Int::class, 200)
81
+    /** Whether or not the server supports extended who. */
61 82
     object WhoxSupport : ServerFeature<Boolean>("WHOX", Boolean::class, false)
62 83
 }
63 84
 

+ 4
- 1
src/main/kotlin/com/dmdirc/ktirc/model/User.kt View File

@@ -1,5 +1,8 @@
1 1
 package com.dmdirc.ktirc.model
2 2
 
3
+/**
4
+ * Describes a user on IRC.
5
+ */
3 6
 data class User(
4 7
         var nickname: String,
5 8
         var ident: String? = null,
@@ -8,7 +11,7 @@ data class User(
8 11
         var realName: String? = null,
9 12
         var awayMessage: String? = null
10 13
 ) {
11
-    fun updateFrom(other: User) {
14
+    internal fun updateFrom(other: User) {
12 15
         nickname = other.nickname
13 16
         other.ident?.let { ident = it }
14 17
         other.hostname?.let { hostname = it }

+ 10
- 0
src/main/kotlin/com/dmdirc/ktirc/model/UserState.kt View File

@@ -2,6 +2,9 @@ package com.dmdirc.ktirc.model
2 2
 
3 3
 import com.dmdirc.ktirc.io.CaseMapping
4 4
 
5
+/**
6
+ * Keeps track of all known users that are in a common channel.
7
+ */
5 8
 class UserState(private val caseMappingProvider: () -> CaseMapping): Iterable<KnownUser> {
6 9
 
7 10
     private val users = UserMap(caseMappingProvider)
@@ -12,6 +15,7 @@ class UserState(private val caseMappingProvider: () -> CaseMapping): Iterable<Kn
12 15
     internal operator fun plusAssign(details: User) { users += KnownUser(caseMappingProvider, details) }
13 16
     internal operator fun minusAssign(details: User) { users -= details.nickname }
14 17
 
18
+    /** Provides a read-only iterator of all users. */
15 19
     override operator fun iterator() = users.iterator().iterator()
16 20
 
17 21
     internal fun removeIf(predicate: (KnownUser) -> Boolean) = users.removeIf(predicate)
@@ -30,12 +34,18 @@ class UserState(private val caseMappingProvider: () -> CaseMapping): Iterable<Kn
30 34
 
31 35
 }
32 36
 
37
+/**
38
+ * Describes a user we know about and the channels that caused them to be known.
39
+ */
33 40
 class KnownUser(caseMappingProvider: () -> CaseMapping, val details: User) {
34 41
 
42
+    /** The channels we have in common with the user. */
35 43
     val channels = CaseInsensitiveSet(caseMappingProvider)
36 44
 
37 45
     internal operator fun plusAssign(channel: String) { channels += channel }
38 46
     internal operator fun minusAssign(channel: String) { channels -= channel }
47
+
48
+    /** Determines if the user is in the specified channel. */
39 49
     operator fun contains(channel: String) = channel in channels
40 50
 
41 51
 }

Loading…
Cancel
Save