Skip to content

Commit

Permalink
Correctly show file captions with urls
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Feb 4, 2024
1 parent b2c76d7 commit 95e52df
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
3 changes: 2 additions & 1 deletion NextcloudTalk/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2716,7 +2716,8 @@ import QuickLook
height += 40 // reactionsView(40)
}

if message.containsURL() {
// File cells currently can't show the reference view
if message.containsURL(), message.file() == nil {
height += 105
}

Expand Down
6 changes: 6 additions & 0 deletions NextcloudTalk/FileMessageTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ - (void)setupForMessage:(NCChatMessage *)message withLastCommonReadMessage:(NSIn
self.messageId = message.messageId;
self.message = message;

if ([message.message isEqualToString:@"{file}"]) {
self.bodyTextView.dataDetectorTypes = UIDataDetectorTypeNone;
} else {
self.bodyTextView.dataDetectorTypes = UIDataDetectorTypeAll;
}

NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:message.timestamp];
self.dateLabel.text = [NCUtils getTimeFromDate:date];

Expand Down
68 changes: 44 additions & 24 deletions NextcloudTalkTests/Unit/UnitChatCellTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ final class UnitChatCellTest: TestBaseRealm {
var baseController: BaseChatViewController!
var testMessage: NCChatMessage!

let fileMessageParameters = """
{
"actor": {
"type": "user",
"id": "admin",
"name": "admin"
},
"file": {
"type": "file",
"id": "9",
"name": "photo-1517603250781-c4eac1449a80.jpeg",
"size": 444676,
"path": "Media/photo-1517603250781-c4eac1449a80.jpeg",
"link": "https://nextcloud-mm.local/index.php/f/9",
"etag": "60fb4ececc370787b1cdc5623ff4a189",
"permissions": 27,
"mimetype": "image/jpeg",
"preview-available": "yes",
"width": 1491,
"height": 837
}
}
"""

override func setUpWithError() throws {
try super.setUpWithError()

Expand Down Expand Up @@ -154,35 +178,31 @@ final class UnitChatCellTest: TestBaseRealm {
}

func testCellWithFileHeight() {
testMessage.messageParametersJSONString = """
{
"actor": {
"type": "user",
"id": "admin",
"name": "admin"
},
"file": {
"type": "file",
"id": "9",
"name": "photo-1517603250781-c4eac1449a80.jpeg",
"size": 444676,
"path": "Media/photo-1517603250781-c4eac1449a80.jpeg",
"link": "https://nextcloud-mm.local/index.php/f/9",
"etag": "60fb4ececc370787b1cdc5623ff4a189",
"permissions": 27,
"mimetype": "image/jpeg",
"preview-available": "yes",
"width": 1491,
"height": 837
}
}
"""

// Test without file caption
testMessage.messageParametersJSONString = fileMessageParameters
testMessage.message = "{file}"
XCTAssertEqual(baseController.getCellHeight(for: testMessage, with: 300), 190.0)
}

func testCellWithFileCaptionHeight() {
testMessage.messageParametersJSONString = fileMessageParameters
testMessage.message = "File caption..."
XCTAssertEqual(baseController.getCellHeight(for: testMessage, with: 300), 210.0)
}

func testCellWithFileCaptionUrlHeight() {
updateCapabilities { cap in
cap.referenceApiSupported = true
}

testMessage.messageParametersJSONString = fileMessageParameters
testMessage.message = "File caption... https://nextcloud.com"
XCTAssertEqual(baseController.getCellHeight(for: testMessage, with: 300), 210.0)
}

func testCellWithFileAndQuoteHeight() {
testMessage.messageParametersJSONString = fileMessageParameters
testMessage.message = "File caption..."

// Add an existing message to the database
let existingMessage = NCChatMessage()
Expand Down

0 comments on commit 95e52df

Please sign in to comment.