Skip to content

Commit

Permalink
Merge pull request #1407 from nextcloud/file-captions
Browse files Browse the repository at this point in the history
File captions
  • Loading branch information
Ivansss authored Nov 3, 2023
2 parents 86d0e1b + e9c55e6 commit 434d243
Show file tree
Hide file tree
Showing 32 changed files with 1,398 additions and 1,212 deletions.
92 changes: 78 additions & 14 deletions NextcloudTalk.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions NextcloudTalk/AutoCompletionTableViewCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @copyright Copyright (c) 2020 Ivan Sein <[email protected]>
*
* @author Ivan Sein <[email protected]>
*
* @license GNU GPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#import <UIKit/UIKit.h>

static CGFloat kAutoCompletionCellHeight = 50.0;
static NSString *AutoCompletionCellIdentifier = @"AutoCompletionCellIdentifier";

@class AvatarButton;

@interface AutoCompletionTableViewCell : UITableViewCell

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) AvatarButton *avatarButton;
@property (nonatomic, strong) UIImageView *userStatusImageView;

+ (CGFloat)defaultFontSize;
- (void)setUserStatus:(NSString *)userStatus;

@end
152 changes: 152 additions & 0 deletions NextcloudTalk/AutoCompletionTableViewCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/**
* @copyright Copyright (c) 2020 Ivan Sein <[email protected]>
*
* @author Ivan Sein <[email protected]>
*
* @license GNU GPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#import "AutoCompletionTableViewCell.h"

#import "SLKUIConstants.h"

#import "NextcloudTalk-Swift.h"

#import "NCAPIController.h"
#import "NCAppBranding.h"
#import "NCDatabaseManager.h"
#import "NCUtils.h"

@implementation AutoCompletionTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [NCAppBranding backgroundColor];
[self configureSubviews];
}
return self;
}

- (void)configureSubviews
{
_avatarButton = [[AvatarButton alloc] initWithFrame:CGRectMake(0, 0, kChatCellAvatarHeight, kChatCellAvatarHeight)];
_avatarButton.translatesAutoresizingMaskIntoConstraints = NO;
_avatarButton.backgroundColor = [NCAppBranding placeholderColor];
_avatarButton.layer.cornerRadius = kChatCellAvatarHeight/2.0;
_avatarButton.layer.masksToBounds = YES;
_avatarButton.showsMenuAsPrimaryAction = YES;
_avatarButton.imageView.contentMode = UIViewContentModeScaleToFill;

[self.contentView addSubview:_avatarButton];

_userStatusImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 12, 12)];
_userStatusImageView.translatesAutoresizingMaskIntoConstraints = NO;
_userStatusImageView.userInteractionEnabled = NO;
[self.contentView addSubview:_userStatusImageView];

[self.contentView addSubview:self.titleLabel];

NSDictionary *views = @{
@"avatarButton": self.avatarButton,
@"userStatusImageView": self.userStatusImageView,
@"titleLabel": self.titleLabel
};

NSDictionary *metrics = @{
@"avatarSize": @(kChatCellAvatarHeight),
@"right": @10
};

[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-right-[avatarButton(avatarSize)]-right-[titleLabel]-right-|" options:0 metrics:metrics views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[titleLabel]|" options:0 metrics:metrics views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-32-[userStatusImageView(12)]-(>=0)-|" options:0 metrics:metrics views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-32-[userStatusImageView(12)]-(>=0)-|" options:0 metrics:metrics views:views]];
self.backgroundColor = [UIColor secondarySystemBackgroundColor];
self.titleLabel.textColor = [UIColor labelColor];

[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[avatarButton(avatarSize)]-(>=0)-|" options:0 metrics:metrics views:views]];
}

- (void)prepareForReuse
{
[super prepareForReuse];

CGFloat pointSize = [AutoCompletionTableViewCell defaultFontSize];

self.titleLabel.font = [UIFont systemFontOfSize:pointSize];
self.titleLabel.text = @"";

[self.avatarButton cancelCurrentRequest];
[self.avatarButton setImage:nil forState:UIControlStateNormal];

self.userStatusImageView.image = nil;
self.userStatusImageView.backgroundColor = [UIColor clearColor];
}

#pragma mark - Getters

- (UILabel *)titleLabel
{
if (!_titleLabel) {
_titleLabel = [UILabel new];
_titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.userInteractionEnabled = NO;
_titleLabel.numberOfLines = 1;
_titleLabel.font = [UIFont systemFontOfSize:[AutoCompletionTableViewCell defaultFontSize]];
_titleLabel.textColor = [UIColor secondaryLabelColor];
}
return _titleLabel;
}

- (void)setUserStatus:(NSString *)userStatus
{
UIImage *statusImage = nil;
if ([userStatus isEqualToString:@"online"]) {
statusImage = [UIImage imageNamed:@"user-status-online-10"];
} else if ([userStatus isEqualToString:@"away"]) {
statusImage = [UIImage imageNamed:@"user-status-away-10"];
} else if ([userStatus isEqualToString:@"dnd"]) {
statusImage = [UIImage imageNamed:@"user-status-dnd-10"];
}

if (statusImage) {
[_userStatusImageView setImage:statusImage];
_userStatusImageView.contentMode = UIViewContentModeCenter;
_userStatusImageView.layer.cornerRadius = 6;
_userStatusImageView.clipsToBounds = YES;

// When a background color is set directly to the cell it seems that there is no background configuration.
// In this class, even when no background color is set, the background configuration is nil.
_userStatusImageView.backgroundColor = (self.backgroundColor) ? self.backgroundColor : [[self backgroundConfiguration] backgroundColor];
}
}

+ (CGFloat)defaultFontSize
{
CGFloat pointSize = 16.0;

// NSString *contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
// pointSize += SLKPointSizeDifferenceForCategory(contentSizeCategory);

return pointSize;
}


@end
21 changes: 4 additions & 17 deletions NextcloudTalk/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -507,19 +507,6 @@ import QuickLook
return unmanagedTemporaryMessage
}

internal func replaceMentionsDisplayNamesWithMentionsKeysInMessage(message: String, parameters: String) -> String {
var resultMessage = message.trimmingCharacters(in: .whitespacesAndNewlines)

guard let messageParametersDict = NCMessageParameter.messageParametersDict(fromJSONString: parameters) else { return resultMessage }

for (parameterKey, parameter) in messageParametersDict {
let parameterKeyString = "{\(parameterKey)}"
resultMessage = resultMessage.replacingOccurrences(of: parameter.mentionDisplayName, with: parameterKeyString)
}

return resultMessage
}

internal func replaceMessageMentionsKeysWithMentionsDisplayNames(message: String, parameters: String) -> String {
var resultMessage = message.trimmingCharacters(in: .whitespacesAndNewlines)

Expand Down Expand Up @@ -1223,7 +1210,7 @@ import QuickLook
internal func createShareConfirmationViewController() -> (shareConfirmationVC: ShareConfirmationViewController, navController: NCNavigationController) {
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
let serverCapabilities = NCDatabaseManager.sharedInstance().serverCapabilities(forAccountId: activeAccount.accountId)
let shareConfirmationVC = ShareConfirmationViewController(room: self.room, account: activeAccount, serverCapabilities: serverCapabilities)
let shareConfirmationVC = ShareConfirmationViewController(room: self.room, account: activeAccount, serverCapabilities: serverCapabilities)!
shareConfirmationVC.delegate = self
shareConfirmationVC.isModal = true
let navigationController = NCNavigationController(rootViewController: shareConfirmationVC)
Expand Down Expand Up @@ -2555,7 +2542,7 @@ import QuickLook

public override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if tableView == self.autoCompletionView {
return kChatMessageCellMinimumHeight
return super.tableView(tableView, heightForRowAt: indexPath)
}

if let message = self.message(for: indexPath) {
Expand Down Expand Up @@ -2654,8 +2641,8 @@ import QuickLook

// if the message is a media file, reduce the message height by the bodyTextView height to hide it since it usually just contains an autogenerated file name (e.g. IMG_1234.jpg)
if NCUtils.isImageFileType(file.mimetype) || NCUtils.isVideoFileType(file.mimetype) {
// Only hide the filename if there's a preview available
if file.previewAvailable {
// Only hide the filename if there's a preview available and we didn't receive a file caption
if file.previewAvailable && message.message == "{file}" {
height -= ceil(bodyBounds.height)
}
}
Expand Down
2 changes: 1 addition & 1 deletion NextcloudTalk/CCCertificate.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@property (weak) id<CCCertificateDelegate> delegate;

+ (id)sharedManager;
+ (CCCertificate *)sharedManager;

- (BOOL)checkTrustedChallenge:(NSURLAuthenticationChallenge *)challenge;
- (BOOL)acceptCertificate;
Expand Down
2 changes: 1 addition & 1 deletion NextcloudTalk/CCCertificate.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ @implementation CCCertificate
NSString *const appCertificates = @"Library/Application Support/Certificates";

//Singleton
+ (id)sharedManager {
+ (CCCertificate *)sharedManager {
static CCCertificate *CCCertificate = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand Down
1 change: 0 additions & 1 deletion NextcloudTalk/ChatMessageTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ static CGFloat kChatMessageCellMinimumHeight = 50.0;

static NSString *ChatMessageCellIdentifier = @"ChatMessageCellIdentifier";
static NSString *ReplyMessageCellIdentifier = @"ReplyMessageCellIdentifier";
static NSString *AutoCompletionCellIdentifier = @"AutoCompletionCellIdentifier";

@class QuotedMessageView;
@class AvatarButton;
Expand Down
15 changes: 3 additions & 12 deletions NextcloudTalk/ChatMessageTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ - (void)configureSubviews
UITapGestureRecognizer *quoteTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(quoteTapped:)];
[self.quoteContainerView addGestureRecognizer:quoteTap];
}

if (![self.reuseIdentifier isEqualToString:AutoCompletionCellIdentifier]) {
[self.contentView addSubview:self.reactionsView];
[self.contentView addSubview:self.referenceView];
}

[self.contentView addSubview:self.reactionsView];
[self.contentView addSubview:self.referenceView];

NSDictionary *views = @{@"avatarButton": self.avatarButton,
@"userStatusImageView": self.userStatusImageView,
Expand Down Expand Up @@ -135,13 +133,6 @@ - (void)configureSubviews
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[dateLabel(avatarSize)]-(>=0)-|" options:0 metrics:metrics views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[quotedMessageView(quoteContainerView)]|" options:0 metrics:nil views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[titleLabel(avatarSize)]-left-[quoteContainerView]-left-[statusView(statusSize)]-(>=0)-|" options:0 metrics:metrics views:views]];
} else if ([self.reuseIdentifier isEqualToString:AutoCompletionCellIdentifier]) {
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-right-[avatarButton(avatarSize)]-right-[titleLabel]-right-|" options:0 metrics:metrics views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[titleLabel]|" options:0 metrics:metrics views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-32-[userStatusImageView(12)]-(>=0)-|" options:0 metrics:metrics views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-32-[userStatusImageView(12)]-(>=0)-|" options:0 metrics:metrics views:views]];
self.backgroundColor = [UIColor secondarySystemBackgroundColor];
self.titleLabel.textColor = [UIColor labelColor];
}

[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[avatarButton(avatarSize)]-(>=0)-|" options:0 metrics:metrics views:views]];
Expand Down
12 changes: 0 additions & 12 deletions NextcloudTalk/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1634,15 +1634,3 @@ import UIKit
self.dismissKeyboard(true)
}
}

extension Notification.Name {
static let NCChatViewControllerReplyPrivatelyNotification = Notification.Name(rawValue: "NCChatViewControllerReplyPrivatelyNotification")
static let NCChatViewControllerForwardNotification = Notification.Name(rawValue: "NCChatViewControllerForwardNotification")
static let NCChatViewControllerTalkToUserNotification = Notification.Name(rawValue: "NCChatViewControllerTalkToUserNotification")
}

@objc extension NSNotification {
public static let NCChatViewControllerReplyPrivatelyNotification = Notification.Name.NCChatViewControllerReplyPrivatelyNotification
public static let NCChatViewControllerForwardNotification = Notification.Name.NCChatViewControllerForwardNotification
public static let NCChatViewControllerTalkToUserNotification = Notification.Name.NCChatViewControllerTalkToUserNotification
}
34 changes: 34 additions & 0 deletions NextcloudTalk/ChatViewControllerExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) 2023 Marcel Müller <[email protected]>
//
// Author Marcel Müller <[email protected]>
//
// GNU GPL version 3 or any later version
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

import Foundation

extension Notification.Name {
static let NCChatViewControllerReplyPrivatelyNotification = Notification.Name(rawValue: "NCChatViewControllerReplyPrivatelyNotification")

Check warning on line 25 in NextcloudTalk/ChatViewControllerExtension.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Identifier Name Violation: Variable name 'NCChatViewControllerReplyPrivatelyNotification' should be between 0 and 40 characters long (identifier_name)
static let NCChatViewControllerForwardNotification = Notification.Name(rawValue: "NCChatViewControllerForwardNotification")
static let NCChatViewControllerTalkToUserNotification = Notification.Name(rawValue: "NCChatViewControllerTalkToUserNotification")

Check warning on line 27 in NextcloudTalk/ChatViewControllerExtension.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Identifier Name Violation: Variable name 'NCChatViewControllerTalkToUserNotification' should be between 0 and 40 characters long (identifier_name)
}

@objc extension NSNotification {
public static let NCChatViewControllerReplyPrivatelyNotification = Notification.Name.NCChatViewControllerReplyPrivatelyNotification

Check warning on line 31 in NextcloudTalk/ChatViewControllerExtension.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Identifier Name Violation: Variable name 'NCChatViewControllerReplyPrivatelyNotification' should be between 0 and 40 characters long (identifier_name)
public static let NCChatViewControllerForwardNotification = Notification.Name.NCChatViewControllerForwardNotification
public static let NCChatViewControllerTalkToUserNotification = Notification.Name.NCChatViewControllerTalkToUserNotification

Check warning on line 33 in NextcloudTalk/ChatViewControllerExtension.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Identifier Name Violation: Variable name 'NCChatViewControllerTalkToUserNotification' should be between 0 and 40 characters long (identifier_name)
}
2 changes: 1 addition & 1 deletion NextcloudTalk/FileMessageTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ - (void)prepareForReuse
- (void)setupForMessage:(NCChatMessage *)message withLastCommonReadMessage:(NSInteger)lastCommonRead
{
self.titleLabel.text = message.actorDisplayName;
self.bodyTextView.attributedText = message.parsedMessage;
self.bodyTextView.attributedText = message.parsedMarkdownForChat;
self.messageId = message.messageId;
self.message = message;

Expand Down
Loading

0 comments on commit 434d243

Please sign in to comment.