Skip to content

Commit

Permalink
Making Sendable conformances conditional for Swift 5.2-5.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Feb 24, 2022
1 parent bc209e1 commit 9c91772
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 42 deletions.
8 changes: 6 additions & 2 deletions Sources/TwitchIRC/IncomingMessage/1- IncomingMessage.swift
@@ -1,6 +1,6 @@

/// A message coming from Twitch.
public enum IncomingMessage: Sendable {
public enum IncomingMessage {
/// A type of message sent after successful connection to Twitch.
case connectionNotice(ConnectionNotice)
/// A type of message sent after entering a channel.
Expand Down Expand Up @@ -173,5 +173,9 @@ public enum IncomingMessage: Sendable {
return nil
}
}

}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension IncomingMessage: Sendable { }
#endif
7 changes: 6 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/Capabilities.swift
@@ -1,6 +1,6 @@

/// A Twitch `ACK` message.
public struct Capabilities: Sendable {
public struct Capabilities {

public var capabilities: [Capability] = []

Expand All @@ -21,3 +21,8 @@ public struct Capabilities: Sendable {
}
}
}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension Capabilities: Sendable { }
#endif
7 changes: 6 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/ChannelEntrance.swift
@@ -1,6 +1,6 @@

/// Notices sent after entering a channel.
public struct ChannelEntrance: Sendable {
public struct ChannelEntrance {

/// The Twitch message accompanying the notice.
public var message = String()
Expand Down Expand Up @@ -35,3 +35,8 @@ public struct ChannelEntrance: Sendable {
self.joinedChannel = joinedChannel
}
}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension ChannelEntrance: Sendable { }
#endif
7 changes: 6 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/ClearChat.swift
@@ -1,6 +1,6 @@

/// A Twitch `CLEARCHAT` message.
public struct ClearChat: Sendable {
public struct ClearChat {

/// The channel's lowercased name.
public var channel = String()
Expand Down Expand Up @@ -36,3 +36,8 @@ public struct ClearChat: Sendable {
}
}
}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension ClearChat: Sendable { }
#endif
7 changes: 6 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/ClearMessage.swift
@@ -1,6 +1,6 @@

/// A Twitch `CLEARMESSAGE` message.
public struct ClearMessage: Sendable {
public struct ClearMessage {

/// The channel's lowercased name.
public var channel = String()
Expand Down Expand Up @@ -46,3 +46,8 @@ public struct ClearMessage: Sendable {
self.parsingLeftOvers = parser.getLeftOvers()
}
}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension ClearMessage: Sendable { }
#endif
7 changes: 6 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/ConnectionNotice.swift
@@ -1,6 +1,6 @@

/// A notice of connection to Twitch.
public struct ConnectionNotice: Sendable {
public struct ConnectionNotice {

/// The Twitch message accompanying the notice.
public var message = String()
Expand All @@ -21,3 +21,8 @@ public struct ConnectionNotice: Sendable {
self.number = number
}
}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension ConnectionNotice: Sendable { }
#endif
7 changes: 6 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/GlobalUserState.swift
@@ -1,6 +1,6 @@

/// A Twitch `GLOBALUSERSTATE` message.
public struct GlobalUserState: Sendable {
public struct GlobalUserState {

/// Badge info.
public var badgeInfo = [String]()
Expand Down Expand Up @@ -35,3 +35,8 @@ public struct GlobalUserState: Sendable {
)
}
}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension GlobalUserState: Sendable { }
#endif
10 changes: 8 additions & 2 deletions Sources/TwitchIRC/IncomingMessage/HostTarget.swift
@@ -1,8 +1,8 @@

/// A Twitch `HOSTTARGET` message.
public struct HostTarget: Sendable {
public struct HostTarget {

public enum Action: Sendable {
public enum Action {
case start(
/// The lowercased name of the channel that is going to be hosted.
hostedChannel: String
Expand Down Expand Up @@ -47,3 +47,9 @@ public struct HostTarget: Sendable {
}
}
}

// - MARK: Sendable conformances
#if swift(>=5.5)
extension HostTarget: Sendable { }
extension HostTarget.Action: Sendable { }
#endif
7 changes: 6 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/Join.swift
@@ -1,6 +1,6 @@

/// A Twitch `JOIN` message.
public struct Join: Sendable {
public struct Join {

/// The channel's lowercased name.
public var channel = String()
Expand Down Expand Up @@ -31,3 +31,8 @@ public struct Join: Sendable {
self.userLogin = String(name1)
}
}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension Join: Sendable { }
#endif
13 changes: 10 additions & 3 deletions Sources/TwitchIRC/IncomingMessage/Notice.swift
@@ -1,8 +1,8 @@

/// A Twitch `NOTICE` message.
public struct Notice: Sendable {
public struct Notice {

public enum MessageID: String, CaseIterable, Sendable {
public enum MessageID: String, CaseIterable {
/// <user> is already banned in this channel.
case alreadyBanned = "alreadybanned"
/// This room is not in emote-only mode.
Expand Down Expand Up @@ -335,7 +335,7 @@ public struct Notice: Sendable {
}
}

public enum Kind: Sendable {
public enum Kind {
case global(
/// The notice's message.
message: String
Expand Down Expand Up @@ -377,3 +377,10 @@ public struct Notice: Sendable {
}
}
}

// - MARK: Sendable conformances
#if swift(>=5.5)
extension Notice: Sendable { }
extension Notice.MessageID: Sendable { }
extension Notice.Kind: Sendable { }
#endif
13 changes: 10 additions & 3 deletions Sources/TwitchIRC/IncomingMessage/ParsingLeftOvers.swift
@@ -1,12 +1,12 @@

public struct ParsingLeftOvers: Sendable {
public struct ParsingLeftOvers {

public struct UnusedPair: Sendable {
public struct UnusedPair {
let key: String
let value: String
}

public struct UnparsedKey: Sendable {
public struct UnparsedKey {
let key: String
let type: String
}
Expand All @@ -24,3 +24,10 @@ public struct ParsingLeftOvers: Sendable {
&& self.unparsedKeys.isEmpty
}
}

// - MARK: Sendable conformances
#if swift(>=5.5)
extension ParsingLeftOvers: Sendable { }
extension ParsingLeftOvers.UnusedPair: Sendable { }
extension ParsingLeftOvers.UnparsedKey: Sendable { }
#endif
7 changes: 6 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/Part.swift
@@ -1,6 +1,6 @@

/// A Twitch `PART` message.
public struct Part: Sendable {
public struct Part {

/// The channel's lowercased name.
public var channel = String()
Expand Down Expand Up @@ -31,3 +31,8 @@ public struct Part: Sendable {
self.userLogin = String(name1)
}
}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension Part: Sendable { }
#endif
22 changes: 17 additions & 5 deletions Sources/TwitchIRC/IncomingMessage/PrivateMessage.swift
@@ -1,8 +1,8 @@

/// A Twitch `PRIVMSG` message.
public struct PrivateMessage: Sendable {
public struct PrivateMessage {

public struct ReplyParent: Sendable {
public struct ReplyParent {
/// Replied user's display name with upper/lower-case letters.
public var displayName: String = ""
/// Replied user's lowercased name.
Expand Down Expand Up @@ -96,9 +96,16 @@ public struct PrivateMessage: Sendable {
/// Remove `.unicodeScalars` and run tests to find out.
self.message = String(message.unicodeScalars.dropFirst())

guard let (infoPart, _) = contentLhs.componentsOneSplit(separatedBy: " :") else {
guard let (infoPart, userLoginPart) = contentLhs.componentsOneSplit(separatedBy: " :") else {
return nil
} /// separates " :senderName!senderName@senderName." from what is behind it.
} /// separates "senderName!senderName@senderName." from what is behind it.

guard let (userLogin1, theRest) = userLoginPart.dropLast().componentsOneSplit(separatedBy: "!"),
let (userLogin2, userLogin3) = theRest.componentsOneSplit(separatedBy: "@"),
userLogin1 == userLogin2, userLogin2 == userLogin3 else {
return nil
}
self.userLogin = String(userLogin1)

var parser = ParametersParser(String(infoPart.dropFirst()))

Expand All @@ -107,7 +114,6 @@ public struct PrivateMessage: Sendable {
self.bits = parser.string(for: "bits")
self.color = parser.string(for: "color")
self.displayName = parser.string(for: "display-name")
self.userLogin = self.displayName.lowercased()
self.emotes = parser.array(for: "emotes")
self.emoteOnly = parser.bool(for: "emote-only")
self.flags = parser.array(for: "flags")
Expand Down Expand Up @@ -137,3 +143,9 @@ public struct PrivateMessage: Sendable {
)
}
}

// - MARK: Sendable conformances
#if swift(>=5.5)
extension PrivateMessage: Sendable { }
extension PrivateMessage.ReplyParent: Sendable { }
#endif
7 changes: 6 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/RoomState.swift
@@ -1,6 +1,6 @@

/// A Twitch `ROOMSTATE` message.
public struct RoomState: Sendable {
public struct RoomState {

/// The channel's lowercased name.
public var channel = String()
Expand Down Expand Up @@ -45,3 +45,8 @@ public struct RoomState: Sendable {
)
}
}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension RoomState: Sendable { }
#endif
7 changes: 6 additions & 1 deletion Sources/TwitchIRC/IncomingMessage/UnknownCommand.swift
@@ -1,6 +1,6 @@

/// A Twitch message indicating usage of an unknown command.
public struct UnknownCommand: Sendable {
public struct UnknownCommand {

/// The lowercased Twitch account username that sent the message.
public var username = String()
Expand All @@ -21,3 +21,8 @@ public struct UnknownCommand: Sendable {
self.message = message
}
}

// - MARK: Sendable conformance
#if swift(>=5.5)
extension UnknownCommand: Sendable { }
#endif

0 comments on commit 9c91772

Please sign in to comment.