-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMisc.swift
More file actions
116 lines (97 loc) · 3.06 KB
/
Misc.swift
File metadata and controls
116 lines (97 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import Ably
import AblyChat
final class MockMessagesPaginatedResult: PaginatedResult {
typealias Item = Message
let clientID: String
let roomName: String
let numberOfMockMessages: Int
var items: [Item] {
Array(repeating: 0, count: numberOfMockMessages).map { _ in
Message(
serial: "\(Date().timeIntervalSince1970)",
action: .create,
clientID: self.clientID,
text: MockStrings.randomPhrase(),
metadata: [:],
headers: [:],
version: .init(
serial: "",
timestamp: Date(),
),
timestamp: Date(),
)
}
}
var hasNext: Bool { fatalError("Not implemented") }
var isLast: Bool { fatalError("Not implemented") }
var next: Self? { fatalError("Not implemented") }
var first: Self { fatalError("Not implemented") }
var current: Self { fatalError("Not implemented") }
init(clientID: String, roomName: String, numberOfMockMessages: Int = 3) {
self.clientID = clientID
self.roomName = roomName
self.numberOfMockMessages = numberOfMockMessages
}
static func == (_: MockMessagesPaginatedResult, _: MockMessagesPaginatedResult) -> Bool {
fatalError("Not implemented")
}
}
enum MockStrings {
static let names = ["Alice", "Bob", "Charlie", "Dave", "Eve"]
static func randomWord(length: Int = Int.random(in: 1 ... 10)) -> String {
var word = ""
for _ in 0 ..< length {
let char = String(format: "%c", Int.random(in: 97 ..< 123))
word += char
}
return word
}
static func randomPhrase(length: Int = Int.random(in: 1 ... 10)) -> String {
var phrase = ""
for _ in 0 ..< length {
phrase += randomWord() + " "
}
phrase += Int.random(in: 1 ... 100) % 5 == 0 ? "😆" : ""
return phrase.count % 33 == 0 ? "Bingo! 😂" : phrase
}
}
enum ReactionName: String, CaseIterable {
case like, dislike, lol, rofl, ok, idk
var emoji: String {
switch self {
case .like:
"👍"
case .dislike:
"👎"
case .lol:
"😆"
case .rofl:
"😂"
case .ok:
"👌"
case .idk:
"🤷♀️"
}
}
}
extension RoomReaction {
var displayedText: String {
name
}
}
enum Emoji {
static func random() -> String {
let emojiRange = 0x1F600 ... 0x1F64F // All Emoticons
// let emojiRange = 0x1F600...0x1F607 // Smiles
let randomScalar = UnicodeScalar(Int.random(in: emojiRange))!
return String(randomScalar)
}
static func all() -> [String] {
let emojiRange = 0x1F600 ... 0x1F64F // All emoticons
return emojiRange.map { String(UnicodeScalar($0)!) }
}
static func smiles() -> [String] {
let emojiRange = 0x1F600 ... 0x1F607 // Smiles
return emojiRange.map { String(UnicodeScalar($0)!) }
}
}