Skip to content

Add local types #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apple/InlineIOS/Chat/ChatView+Views.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Combine
import InlineKit
import InlineUI
import SwiftUI
import Auth

extension ChatView {
var isCurrentUser: Bool {
Expand Down
16 changes: 13 additions & 3 deletions apple/InlineIOS/Chat/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Combine
import InlineKit
import InlineUI
import Logger
import RealtimeAPI
import SwiftUI

struct ChatView: View {
Expand All @@ -14,11 +15,12 @@ struct ChatView: View {
@EnvironmentStateObject var fullChatViewModel: FullChatViewModel
@EnvironmentObject var nav: Navigation
@EnvironmentObject var data: DataManager
@EnvironmentObject var ws: WebSocketManager

@Environment(\.appDatabase) var database
@Environment(\.scenePhase) var scenePhase

@Environment(\.realtime) var realtime

@ObservedObject var composeActions: ComposeActions = .shared

func currentComposeAction() -> ApiComposeAction? {
Expand All @@ -27,6 +29,8 @@ struct ChatView: View {

@State var currentTime = Date()

@State var apiState: RealtimeAPIState = .connecting

let timer = Timer.publish(
every: 60, // 1 minute
on: .main,
Expand Down Expand Up @@ -56,8 +60,8 @@ struct ChatView: View {

var subtitle: String {
// TODO: support threads
if ws.connectionState == .connecting {
"connecting..."
if realtime.apiState != .connected {
getStatusText(realtime.apiState)
} else if let composeAction = currentComposeAction() {
composeAction.rawValue
} else if let online = fullChatViewModel.peerUser?.online {
Expand Down Expand Up @@ -144,6 +148,12 @@ struct ChatView: View {
.foregroundStyle(.secondary)
}
}
.onAppear {
apiState = realtime.apiState
}
.onReceive(realtime.apiStatePublisher, perform: { nextApiState in
apiState = nextApiState
})
}

func fetch() async {
Expand Down
1 change: 1 addition & 0 deletions apple/InlineIOS/Chat/ComposeEmbedView.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Auth
import InlineKit
import UIKit

Expand Down
93 changes: 93 additions & 0 deletions apple/InlineIOS/Chat/MessageAttachmentEmbed.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import InlineKit
import UIKit

class MessageAttachmentEmbed: UIView {
private enum Constants {
static let cornerRadius: CGFloat = 12
static let rectangleWidth: CGFloat = 4
static let contentSpacing: CGFloat = 6
static let verticalPadding: CGFloat = 8
static let horizontalPadding: CGFloat = 6
}

static let height = 28.0
private var outgoing: Bool = false

private lazy var circleImageView: UIImageView = {
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
let config = UIImage.SymbolConfiguration(pointSize: 14, weight: .regular)
imageView.image = UIImage(systemName: "circle", withConfiguration: config)
imageView.contentMode = .scaleAspectFit
return imageView
}()

private lazy var messageLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = .systemFont(ofSize: 17)
label.numberOfLines = 1
return label
}()

override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
setupLayer()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
setupViews()
setupLayer()
}

func configure(userName: String, outgoing: Bool) {
self.outgoing = outgoing
messageLabel.text = "\(userName) will do"
updateColors()
}
}

private extension MessageAttachmentEmbed {
func setupViews() {
addSubview(circleImageView)
addSubview(messageLabel)

NSLayoutConstraint.activate([
circleImageView.leadingAnchor.constraint(
equalTo: leadingAnchor,
constant: Constants.horizontalPadding
),
circleImageView.centerYAnchor.constraint(equalTo: centerYAnchor),
circleImageView.widthAnchor.constraint(equalToConstant: 16),
circleImageView.heightAnchor.constraint(equalToConstant: 16),

messageLabel.leadingAnchor.constraint(
equalTo: circleImageView.trailingAnchor,
constant: Constants.contentSpacing
),
messageLabel.trailingAnchor.constraint(
equalTo: trailingAnchor,
constant: -Constants.horizontalPadding
),
messageLabel.centerYAnchor.constraint(equalTo: centerYAnchor),

heightAnchor.constraint(equalToConstant: MessageAttachmentEmbed.height),
])
}

func setupLayer() {
layer.cornerRadius = Constants.cornerRadius
layer.masksToBounds = true
}

func updateColors() {
let textColor: UIColor = outgoing ? .white : .label
let bgAlpha: CGFloat = outgoing ? 0.13 : 0.08
backgroundColor = outgoing ? .white.withAlphaComponent(bgAlpha) : .systemGray.withAlphaComponent(bgAlpha)

messageLabel.textColor = textColor
circleImageView.tintColor = textColor
}
}
1 change: 1 addition & 0 deletions apple/InlineIOS/Chat/MessagesCollectionView.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Auth
import InlineKit
import Nuke
import NukeUI
Expand Down
Loading