Skip to content

feat: Improve collapse - WPB-17259 #2961

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 23 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public extension PrivateUserDefaults {
storage.removeObject(forKey: scopeKey(key))
}

func stringArray(forKey key: Key) -> [String]? {
storage.stringArray(forKey: scopeKey(key))
}
}

public protocol DefaultsKey {
Expand Down Expand Up @@ -131,6 +134,8 @@ public protocol UserDefaultsProtocol {

func removeObject(forKey defaultName: String)
func dictionaryRepresentation() -> [String: Any]

func stringArray(forKey defaultName: String) -> [String]?
}

public extension UserDefaultsProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public extension UIView {
return self
}

@discardableResult
func minHeightConstraint(_ value: CGFloat) -> Self {
translatesAutoresizingMaskIntoConstraints = false

heightAnchor.constraint(greaterThanOrEqualToConstant: 38).isActive = true
return self
}

@discardableResult
func setTranslatesAutoresizingMaskIntoConstraints(_ value: Bool) -> Self {
translatesAutoresizingMaskIntoConstraints = value
Expand Down Expand Up @@ -115,4 +123,28 @@ public extension UIView {

return view
}

/// Returns a container view which is specifically useful not to stretch its content.
func wrapInViewWithFlexibleTopAndBottom() -> UIView {
let view = UIView()
view.clipsToBounds = false
translatesAutoresizingMaskIntoConstraints = false
view.addSubview(self)

let bottomConstraint = view.bottomAnchor.constraint(equalTo: bottomAnchor)
bottomConstraint.priority = .defaultLow

let topConstraint = view.topAnchor.constraint(equalTo: topAnchor)
topConstraint.priority = .defaultLow

NSLayoutConstraint.activate([
leadingAnchor.constraint(equalTo: view.leadingAnchor),
view.trailingAnchor.constraint(equalTo: trailingAnchor),
topConstraint,
bottomConstraint
])

return view
}

}
10 changes: 10 additions & 0 deletions wire-ios-data-model/Source/Model/Message/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
textMessageData != nil
}

var isTextWithNoLinks: Bool {
isText && !hasLinks
}

var isImage: Bool {
imageMessageData != nil || (fileMessageData != nil && fileMessageData!.v3_isImage)
}
Expand Down Expand Up @@ -64,6 +68,12 @@
systemMessageData != nil
}

// Checks if message has link preview or link attachment
// Does not check if there is Markdown links
var hasLinks: Bool {
textMessageData?.linkPreview != nil || linkAttachments?.first != nil
}

var isNormal: Bool {
isText
|| isImage
Expand All @@ -75,7 +85,7 @@
}

var isConnectionRequest: Bool {
guard isSystem else { return false }

Check warning on line 88 in wire-ios-data-model/Source/Model/Message/Message.swift

View workflow job for this annotation

GitHub Actions / Test Results

'connectionRequest' is deprecated: deprecated

'connectionRequest' is deprecated: deprecated

Check warning on line 88 in wire-ios-data-model/Source/Model/Message/Message.swift

View workflow job for this annotation

GitHub Actions / Test Results

'connectionRequest' is deprecated: deprecated

'connectionRequest' is deprecated: deprecated
return systemMessageData!.systemMessageType == .connectionRequest
}

Expand Down
28 changes: 28 additions & 0 deletions wire-ios/Tests/Mocks/MockMessage+Creation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,34 @@ enum MockMessageFactory {
return message
}

static func textMessageWithLinkAttachment(
withText text: String? = "Just a random text message",
sender: UserType? = nil,
conversation: Conversation? = nil,
includingRichMedia shouldIncludeRichMedia: Bool = false
) -> MockMessage {
let message: MockMessage = MockMessageFactory.messageTemplate(
sender: sender,
conversation: conversation
)

let textMessageData = MockTextMessageData()
textMessageData
.messageText = shouldIncludeRichMedia ?
"Check this 500lb squirrel! -> https://www.youtube.com/watch?v=0so5er4X3dc" : text!
message.backingTextMessageData = textMessageData

message.linkAttachments = [LinkAttachment(
type: .youTubeVideo,
title: "Lagar mat med Fernando Di Luca",
permalink: URL(string: "https://www.youtube.com/watch?v=l7aqpSTa234")!,
thumbnails: [],
originalRange: NSRange(location: 0, length: 5)
)]

return message
}

static func linkMessage() -> MockMessage {
let message = MockMessageFactory.messageTemplate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,38 @@ final class ConversationCollapsedMessageCellSnapshotTests: ConversationMessageSn
"location": MockMessageFactory.locationMessage(),
"text": MockMessageFactory
.textMessage(
withText: "Long long long Long long long Long long long Long long long Long long long Long long long"
withText:
"""
Long long long Long long long Long long long Long long long Long long long Long long long\n
Long long long Long long long Long long long Long long long Long long long Long long long
Long long long Long long long Long long long Long long long Long long long Long long long
"""
)
]
messages.forEach { verify(message: $0.value, named: $0.key) }
}

func testTextCollapsed() {
let messages: [String: MockMessage] = [
"singleLineText": MockMessageFactory.textMessage(withText: "Single Line text"),
"twoLineText": MockMessageFactory.textMessage(withText: "First Line text\n Second line"),
"threeLineText": MockMessageFactory.textMessage(
withText: "Long long long Long long long Long long long Long long long Long long long Long long long"
),
"moreThenThreeLineText": MockMessageFactory
.textMessage(
withText:
"""
Long long long Long long long Long long long Long long long Long long long Long long long\n
Long long long Long long long Long long long Long long long Long long long Long long long
Long long long Long long long Long long long Long long long Long long long Long long long
"""
)
]
messages.forEach { verify(message: $0.value, named: $0.key) }

}

func testUploadedCell_fromThisDevice_collapseOwnMessagesDisabled() {
message.backingFileMessageData.transferState = .uploaded
message.backingFileMessageData.fileURL = Bundle.main.bundleURL
Expand Down
Loading
Loading