Compare commits

..

No commits in common. "beb7af003bda096e426101612fa113db008f242e" and "90f75aba6f2ffd969bff7e40daeafae7e8c33954" have entirely different histories.

2 changed files with 13 additions and 190 deletions

View File

@ -148,7 +148,7 @@ struct PrivateChatView: View {
private var messagesList: some View {
ScrollView {
LazyVStack(alignment: .leading, spacing: 0) {
LazyVStack(alignment: .leading, spacing: 12) {
Color.clear
.frame(height: 1)
.id(bottomAnchorId)
@ -162,13 +162,13 @@ struct PrivateChatView: View {
.scaleEffect(x: 1, y: -1, anchor: .center)
}
ForEach(decoratedMessages.reversed()) { decoratedMessage in
messageRow(for: decoratedMessage)
.id(decoratedMessage.id)
ForEach(viewModel.messages.reversed()) { message in
messageRow(for: message)
.id(message.id)
.scaleEffect(x: 1, y: -1, anchor: .center)
.onAppear {
guard hasPositionedToBottom else { return }
viewModel.loadMoreIfNeeded(for: decoratedMessage.message)
viewModel.loadMoreIfNeeded(for: message)
}
}
@ -183,7 +183,7 @@ struct PrivateChatView: View {
.scaleEffect(x: 1, y: -1, anchor: .center)
}
}
.padding(.vertical, 8)
.padding(.vertical, 12)
}
.scaleEffect(x: 1, y: -1, anchor: .center)
.simultaneousGesture(
@ -236,39 +236,21 @@ struct PrivateChatView: View {
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
private func messageRow(for decoratedMessage: DecoratedMessage) -> some View {
let message = decoratedMessage.message
private func messageRow(for message: MessageItem) -> some View {
let isCurrentUser = currentUserId.map { $0 == message.senderId } ?? false
let hasDecorations = decoratedMessage.showHorns || decoratedMessage.showLegs
let topPadding: CGFloat = decoratedMessage.showHorns ? 5 : -12
let verticalPadding: CGFloat = hasDecorations ? 0 : 0
return HStack(alignment: .bottom, spacing: 8) {
return HStack(alignment: .bottom, spacing: 12) {
if isCurrentUser { Spacer(minLength: 32) }
messageBubble(
for: message,
decorations: decoratedMessage,
isCurrentUser: isCurrentUser
)
messageBubble(for: message, isCurrentUser: isCurrentUser)
if !isCurrentUser { Spacer(minLength: 32) }
}
.padding(.horizontal, 8)
.padding(.top, topPadding)
.padding(.vertical, verticalPadding)
.padding(.horizontal, 16)
}
private func messageBubble(
for message: MessageItem,
decorations: DecoratedMessage,
isCurrentUser: Bool
) -> some View {
private func messageBubble(for message: MessageItem, isCurrentUser: Bool) -> some View {
let timeText = timestamp(for: message)
let bubbleColor = isCurrentUser ? Color.accentColor : Color(.secondarySystemBackground)
return VStack(alignment: isCurrentUser ? .trailing : .leading, spacing: 4) {
Text(contentText(for: message))
.font(.body)
@ -283,13 +265,8 @@ struct PrivateChatView: View {
}
.padding(.vertical, 10)
.padding(.horizontal, 12)
.background(
MessageBubbleShape(
showHornsRaw: decorations.showHorns,
showLegsRaw: decorations.showLegs
)
.fill(bubbleColor)
)
.background(isCurrentUser ? Color.accentColor : Color(.secondarySystemBackground))
.clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
.frame(maxWidth: messageBubbleMaxWidth, alignment: isCurrentUser ? .trailing : .leading)
.fixedSize(horizontal: false, vertical: true)
}
@ -325,31 +302,6 @@ struct PrivateChatView: View {
return content
}
private var decoratedMessages: [DecoratedMessage] {
let messages = viewModel.messages
guard !messages.isEmpty else { return [] }
var result: [DecoratedMessage] = []
result.reserveCapacity(messages.count)
for (index, message) in messages.enumerated() {
let previousSender = index > 0 ? messages[index - 1].senderId : nil
let nextSender = index < messages.count - 1 ? messages[index + 1].senderId : nil
let showHorns = previousSender != message.senderId
let showLegs = nextSender != message.senderId
result.append(
DecoratedMessage(
message: message,
showHorns: showHorns,
showLegs: showLegs
)
)
}
return result
}
private func errorBanner(message: String) -> some View {
HStack {
Image(systemName: "exclamationmark.triangle.fill")
@ -813,133 +765,6 @@ private var headerPlaceholderAvatar: some View {
}
/// Helper model that stores a message alongside horn/leg flags for grouping sequences.
private struct DecoratedMessage: Identifiable {
let message: MessageItem
let showHorns: Bool
let showLegs: Bool
var id: MessageItem.ID { message.id }
}
/// Decorative bubble with two horns on top and two legs on bottom to mimic cartoon-style speech clouds.
private struct MessageBubbleShape: Shape {
var cornerRadius: CGFloat = 18
var hornHeight: CGFloat = 10
var hornWidth: CGFloat = 16
var hornSpacing: CGFloat = 12
var legHeight: CGFloat = 6
var legWidth: CGFloat = 18
var legSpacing: CGFloat = 14
var showHornsRaw: Bool = true
var showLegsRaw: Bool = true
// Фактические флаги отрисовки
var showHorns: Bool {
AppConfig.ENABLE_CHAT_BUBBLE_DECORATIONS && showHornsRaw
}
var showLegs: Bool {
AppConfig.ENABLE_CHAT_BUBBLE_DECORATIONS && showLegsRaw
}
func path(in rect: CGRect) -> Path {
var path = Path()
guard rect.width > 0, rect.height > 0 else { return path }
let radius = min(cornerRadius, min(rect.width, rect.height) / 2)
let innerTop = rect.minY + hornHeight
let innerBottom = rect.maxY - legHeight
let left = rect.minX
let right = rect.maxX
let horizontalSpan = max(0, rect.width - 2 * radius)
let hornsEnabled = showHorns && horizontalSpan > 0.5
let legsEnabled = showLegs && horizontalSpan > 0.5
let effectiveHornWidth = hornsEnabled ? min(hornWidth, horizontalSpan / 2) : 0
let effectiveLegWidth = legsEnabled ? min(legWidth, horizontalSpan / 2) : 0
let hornSpacingCandidate = max(horizontalSpan - effectiveHornWidth * 2, 0) / 2
let legSpacingCandidate = max(horizontalSpan - effectiveLegWidth * 2, 0) / 2
let effectiveHornSpacing = hornsEnabled ? min(hornSpacing, hornSpacingCandidate) : 0
let effectiveLegSpacing = legsEnabled ? min(legSpacing, legSpacingCandidate) : 0
let leftHornStart = left + radius + effectiveHornSpacing
let rightHornStart = right - radius - effectiveHornSpacing - effectiveHornWidth
let leftLegStart = left + radius + effectiveLegSpacing
let rightLegStart = right - radius - effectiveLegSpacing - effectiveLegWidth
path.move(to: CGPoint(x: left + radius, y: innerTop))
path.addQuadCurve(to: CGPoint(x: left, y: innerTop + radius), control: CGPoint(x: left, y: innerTop))
path.addLine(to: CGPoint(x: left, y: innerBottom - radius))
path.addQuadCurve(to: CGPoint(x: left + radius, y: innerBottom), control: CGPoint(x: left, y: innerBottom))
if legsEnabled {
path.addLine(to: CGPoint(x: leftLegStart, y: innerBottom))
path.addQuadCurve(
to: CGPoint(x: leftLegStart + effectiveLegWidth / 2, y: innerBottom + legHeight),
control: CGPoint(x: leftLegStart + effectiveLegWidth * 0.15, y: innerBottom + legHeight)
)
path.addQuadCurve(
to: CGPoint(x: leftLegStart + effectiveLegWidth, y: innerBottom),
control: CGPoint(x: leftLegStart + effectiveLegWidth * 0.85, y: innerBottom + legHeight)
)
path.addLine(to: CGPoint(x: rightLegStart, y: innerBottom))
path.addQuadCurve(
to: CGPoint(x: rightLegStart + effectiveLegWidth / 2, y: innerBottom + legHeight),
control: CGPoint(x: rightLegStart + effectiveLegWidth * 0.15, y: innerBottom + legHeight)
)
path.addQuadCurve(
to: CGPoint(x: rightLegStart + effectiveLegWidth, y: innerBottom),
control: CGPoint(x: rightLegStart + effectiveLegWidth * 0.85, y: innerBottom + legHeight)
)
}
path.addLine(to: CGPoint(x: right - radius, y: innerBottom))
path.addQuadCurve(to: CGPoint(x: right, y: innerBottom - radius), control: CGPoint(x: right, y: innerBottom))
path.addLine(to: CGPoint(x: right, y: innerTop + radius))
path.addQuadCurve(to: CGPoint(x: right - radius, y: innerTop), control: CGPoint(x: right, y: innerTop))
if hornsEnabled {
let hornOutset = effectiveHornWidth * 0.45
let hornTipY = rect.minY - hornHeight * 0.35
// Right horn leans outward to the right
path.addLine(to: CGPoint(x: rightHornStart + effectiveHornWidth, y: innerTop))
path.addQuadCurve(
to: CGPoint(x: rightHornStart + effectiveHornWidth + hornOutset, y: hornTipY),
control: CGPoint(x: rightHornStart + effectiveHornWidth + hornOutset * 0.65, y: innerTop - hornHeight * 0.35)
)
path.addQuadCurve(
to: CGPoint(x: rightHornStart, y: innerTop),
control: CGPoint(x: rightHornStart + hornOutset * 0.25, y: innerTop - hornHeight)
)
// Move across the top between horns and draw the left horn leaning outward
path.addLine(to: CGPoint(x: leftHornStart + effectiveHornWidth, y: innerTop))
path.addQuadCurve(
to: CGPoint(x: leftHornStart - hornOutset, y: hornTipY),
control: CGPoint(x: leftHornStart + effectiveHornWidth - hornOutset * 0.65, y: innerTop - hornHeight * 0.35)
)
path.addQuadCurve(
to: CGPoint(x: leftHornStart, y: innerTop),
control: CGPoint(x: leftHornStart - hornOutset * 0.25, y: innerTop - hornHeight)
)
}
path.addLine(to: CGPoint(x: left + radius, y: innerTop))
path.closeSubpath()
return path
}
}
#if canImport(UIKit)
private struct LegacyMultilineTextView: UIViewRepresentable {
@Binding var text: String

View File

@ -13,8 +13,6 @@ struct AppConfig {
static let APP_VERSION = "0.1"
static let DISABLE_DB = false
/// Temporary flag to toggle whimsical chat bubble horns/legs rendering.
static let ENABLE_CHAT_BUBBLE_DECORATIONS = true
/// Controls whether incoming chat opens as a modal sheet (`true`) or navigates to Chats tab (`false`).
static let PRESENT_CHAT_AS_SHEET = false
/// Fallback SQLCipher key used until the user sets an application password.