forked from GetStream/stream-chat-swiftui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomAttachment.swift
65 lines (54 loc) · 1.68 KB
/
CustomAttachment.swift
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
//
// Copyright © 2024 Stream.io Inc. All rights reserved.
//
import StreamChat
import StreamChatSwiftUI
import SwiftUI
class CustomMessageResolver: MessageTypeResolving {
func hasCustomAttachment(message: ChatMessage) -> Bool {
let messageComponents = message.text.components(separatedBy: CharacterSet.whitespacesAndNewlines)
return !messageComponents.filter { component in
isValidEmail(component)
}
.isEmpty
}
private func isValidEmail(_ email: String) -> Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let emailPred = NSPredicate(format: "SELF MATCHES %@", emailRegEx)
return emailPred.evaluate(with: email)
}
}
struct CustomAttachmentView: View {
let message: ChatMessage
let width: CGFloat
let isFirst: Bool
var body: some View {
HStack {
Image(systemName: "envelope")
Text(message.text)
}
.padding()
.frame(maxWidth: width)
.messageBubble(for: message, isFirst: isFirst)
}
}
struct CustomMessageTextView: View {
@Injected(\.colors) var colors
@Injected(\.fonts) var fonts
var message: ChatMessage
var isFirst: Bool
public var body: some View {
Text(message.text)
.padding()
.messageBubble(for: message, isFirst: isFirst)
.foregroundColor(Color.blue)
.font(fonts.bodyBold)
.overlay(
BottomRightView {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.green)
.offset(x: 1, y: -1)
}
)
}
}