Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…iftui into demo-app-tabbar
  • Loading branch information
martinmitrevski committed Jan 20, 2025
2 parents c384311 + 1effcd5 commit 81ee0bf
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 500 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### 🐞 Fixed
- Fix thread reply action shown when inside a Thread [#717](https://github.com/GetStream/stream-chat-swiftui/pull/717)
### 🔄 Changed
- Deprecate unused `ChatMessage.userDisplayInfo(from:)` which only accessed cached data [#718](https://github.com/GetStream/stream-chat-swiftui/pull/718)

# [4.70.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.70.0)
_January 15, 2025_
Expand Down
16 changes: 3 additions & 13 deletions Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
scrolledId = nil
return true
} else {
let findBaseId: String? = {
if StreamRuntimeCheck._isDatabaseObserverItemReusingEnabled {
return messageId
} else {
return messageId.components(separatedBy: "$").first
}
}()
guard let baseId = findBaseId else {
scrolledId = nil
return true
}
let baseId = messageId
let alreadyLoaded = messages.map(\.id).contains(baseId)
if alreadyLoaded {
if scrolledId == nil {
Expand Down Expand Up @@ -368,8 +358,8 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {

let previous = index - 1
let previousMessage = messages[previous]
let currentAuthorId = messageCachingUtils.authorId(for: message)
let previousAuthorId = messageCachingUtils.authorId(for: previousMessage)
let currentAuthorId = message.author.id
let previousAuthorId = previousMessage.author.id

if currentAuthorId != previousAuthorId {
temp[message.id]?.append(firstMessageKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct VoiceRecordingContainerView<Factory: ViewFactory>: View {
public var body: some View {
VStack(spacing: 0) {
VStack {
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
if let quotedMessage = message.quotedMessage {
factory.makeQuotedMessageView(
quotedMessage: quotedMessage,
fillAvailableSpace: !message.attachmentCounts.isEmpty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import StreamChat
import SwiftUI

public struct FileAttachmentsContainer<Factory: ViewFactory>: View {

@Injected(\.utils) private var utils

var factory: Factory
var message: ChatMessage
var width: CGFloat
Expand All @@ -31,7 +28,7 @@ public struct FileAttachmentsContainer<Factory: ViewFactory>: View {

public var body: some View {
VStack(alignment: message.alignmentInBubble) {
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
if let quotedMessage = message.quotedMessage {
factory.makeQuotedMessageView(
quotedMessage: quotedMessage,
fillAvailableSpace: !message.attachmentCounts.isEmpty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public struct GiphyAttachmentView<Factory: ViewFactory>: View {
@Injected(\.chatClient) private var chatClient
@Injected(\.colors) private var colors
@Injected(\.fonts) private var fonts
@Injected(\.utils) private var utils

let factory: Factory
let message: ChatMessage
Expand All @@ -24,7 +23,7 @@ public struct GiphyAttachmentView<Factory: ViewFactory>: View {
alignment: message.alignmentInBubble,
spacing: 0
) {
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
if let quotedMessage = message.quotedMessage {
factory.makeQuotedMessageView(
quotedMessage: quotedMessage,
fillAvailableSpace: !message.attachmentCounts.isEmpty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import SwiftUI

public struct ImageAttachmentContainer<Factory: ViewFactory>: View {
@Injected(\.colors) private var colors
@Injected(\.utils) private var utils

var factory: Factory
let message: ChatMessage
Expand All @@ -23,7 +22,7 @@ public struct ImageAttachmentContainer<Factory: ViewFactory>: View {
alignment: message.alignmentInBubble,
spacing: 0
) {
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
if let quotedMessage = message.quotedMessage {
factory.makeQuotedMessageView(
quotedMessage: quotedMessage,
fillAvailableSpace: !message.attachmentCounts.isEmpty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import SwiftUI
/// In case of more than one link, only the first link is previewed.
public struct LinkAttachmentContainer<Factory: ViewFactory>: View {
@Injected(\.colors) private var colors
@Injected(\.utils) private var utils

var factory: Factory
var message: ChatMessage
Expand Down Expand Up @@ -38,7 +37,7 @@ public struct LinkAttachmentContainer<Factory: ViewFactory>: View {
alignment: message.alignmentInBubble,
spacing: 0
) {
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
if let quotedMessage = message.quotedMessage {
factory.makeQuotedMessageView(
quotedMessage: quotedMessage,
fillAvailableSpace: !message.attachmentCounts.isEmpty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
} else {
if messageListConfig.messageDisplayOptions.showAvatars(for: channel) {
factory.makeMessageAvatarView(
for: utils.messageCachingUtils.authorInfo(from: message)
for: message.authorDisplayInfo
)
.opacity(showsAllInfo ? 1 : 0)
.offset(y: bottomReactionsShown ? offsetYAvatar : 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ public class DefaultMessageIdBuilder: MessageIdBuilder {
public init() { /* Public init. */ }

public func makeMessageId(for message: ChatMessage) -> String {
if StreamRuntimeCheck._isDatabaseObserverItemReusingEnabled {
return message.id
}
var statesId = "empty"
if message.localState != nil {
statesId = message.uploadingStatesId
}
if message.textUpdatedAt != nil {
statesId = "edited"
}
return message.baseId + statesId + message.reactionScoresId
+ message.repliesCountId + "\(message.updatedAt)" + message.pinStateId
message.id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public struct MessageAuthorAndDateView: View {
/// View that displays the message author.
public struct MessageAuthorView: View {

@Injected(\.utils) private var utils
@Injected(\.fonts) private var fonts
@Injected(\.colors) private var colors

Expand All @@ -44,8 +43,12 @@ public struct MessageAuthorView: View {
self.message = message
}

var authorName: String {
message.author.name ?? message.author.id
}

public var body: some View {
Text(utils.messageCachingUtils.authorName(for: message))
Text(authorName)
.lineLimit(1)
.font(fonts.footnoteBold)
.foregroundColor(Color(colors.textLowEmphasis))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public struct MessageTextView<Factory: ViewFactory>: View {
alignment: message.alignmentInBubble,
spacing: 0
) {
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
if let quotedMessage = message.quotedMessage {
factory.makeQuotedMessageView(
quotedMessage: quotedMessage,
fillAvailableSpace: !message.attachmentCounts.isEmpty,
Expand Down Expand Up @@ -193,11 +193,10 @@ public struct EmojiTextView<Factory: ViewFactory>: View {
var isFirst: Bool

@Injected(\.fonts) private var fonts
@Injected(\.utils) private var utils

public var body: some View {
ZStack {
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
if let quotedMessage = message.quotedMessage {
VStack(spacing: 0) {
factory.makeQuotedMessageView(
quotedMessage: quotedMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import SwiftUI

/// Container showing the quoted message view with the user avatar.
struct QuotedMessageViewContainer<Factory: ViewFactory>: View {

@Injected(\.utils) private var utils

private let avatarSize: CGFloat = 24

var factory: Factory
Expand All @@ -22,7 +19,7 @@ struct QuotedMessageViewContainer<Factory: ViewFactory>: View {
HStack(alignment: .bottom) {
if !quotedMessage.isSentByCurrentUser || forceLeftToRight {
factory.makeQuotedMessageAvatarView(
for: utils.messageCachingUtils.authorInfo(from: quotedMessage),
for: quotedMessage.authorDisplayInfo,
size: CGSize(width: avatarSize, height: avatarSize)
)

Expand All @@ -41,7 +38,7 @@ struct QuotedMessageViewContainer<Factory: ViewFactory>: View {
)

factory.makeQuotedMessageAvatarView(
for: utils.messageCachingUtils.authorInfo(from: quotedMessage),
for: quotedMessage.authorDisplayInfo,
size: CGSize(width: avatarSize, height: avatarSize)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import StreamChat
import SwiftUI

public struct VideoAttachmentsContainer<Factory: ViewFactory>: View {

@Injected(\.utils) private var utils

var factory: Factory
let message: ChatMessage
let width: CGFloat
@Binding var scrolledId: String?

public var body: some View {
VStack(spacing: 0) {
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
if let quotedMessage = message.quotedMessage {
VStack {
factory.makeQuotedMessageView(
quotedMessage: quotedMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
if !messageDisplayInfo.message.isRightAligned &&
utils.messageListConfig.messageDisplayOptions.showAvatars(for: channel) {
factory.makeMessageAvatarView(
for: utils.messageCachingUtils.authorInfo(from: messageDisplayInfo.message)
for: messageDisplayInfo.message.authorDisplayInfo
)
.offset(
x: paddingValue / 2,
Expand Down
Loading

0 comments on commit 81ee0bf

Please sign in to comment.