Skip to content

Commit

Permalink
Merge pull request #1905 from nextcloud/render-performance
Browse files Browse the repository at this point in the history
Render performance
  • Loading branch information
Ivansss authored Dec 6, 2024
2 parents 4ee6432 + 5c17fd3 commit 0991436
Show file tree
Hide file tree
Showing 28 changed files with 214 additions and 192 deletions.
8 changes: 7 additions & 1 deletion NextcloudTalk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
1F205C532CEF91C500AAA673 /* UserAbsence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F205C4F2CEF903000AAA673 /* UserAbsence.swift */; };
1F205C552CEFA01200AAA673 /* OutOfOfficeView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1F205C542CEFA01200AAA673 /* OutOfOfficeView.xib */; };
1F205C572CEFA01900AAA673 /* OutOfOfficeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F205C562CEFA01900AAA673 /* OutOfOfficeView.swift */; };
1F205D412CFC6DD300AAA673 /* AvatarProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F205D402CFC6DCF00AAA673 /* AvatarProtocol.swift */; };
1F205D442CFC70AD00AAA673 /* AvatarProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F205D402CFC6DCF00AAA673 /* AvatarProtocol.swift */; };
1F24B5A228E0648600654457 /* ReferenceGithubView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F24B5A128E0648600654457 /* ReferenceGithubView.swift */; };
1F24B5A428E0649200654457 /* ReferenceGithubView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1F24B5A328E0649200654457 /* ReferenceGithubView.xib */; };
1F35F8E22AEEBAF900044BDA /* InputbarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F5A24322ADA77DA009939FE /* InputbarViewController.swift */; };
Expand Down Expand Up @@ -691,6 +693,7 @@
1F205C4F2CEF903000AAA673 /* UserAbsence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserAbsence.swift; sourceTree = "<group>"; };
1F205C542CEFA01200AAA673 /* OutOfOfficeView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OutOfOfficeView.xib; sourceTree = "<group>"; };
1F205C562CEFA01900AAA673 /* OutOfOfficeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OutOfOfficeView.swift; sourceTree = "<group>"; };
1F205D402CFC6DCF00AAA673 /* AvatarProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarProtocol.swift; sourceTree = "<group>"; };
1F21A0622C77863500ED8C0C /* nb-NO */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "nb-NO"; path = "nb-NO.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
1F21A0632C77863500ED8C0C /* nb-NO */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "nb-NO"; path = "nb-NO.lproj/Localizable.strings"; sourceTree = "<group>"; };
1F21A0642C77863500ED8C0C /* nb-NO */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "nb-NO"; path = "nb-NO.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1683,9 +1686,10 @@
1F1C0D8829AFB89900D17C6D /* VLCKitVideoViewController.swift */,
1F1C0D8629AFB88800D17C6D /* VLCKitVideoViewController.xib */,
1F90DA0329E9A28E00E81E3D /* AvatarManager.swift */,
1F205D402CFC6DCF00AAA673 /* AvatarProtocol.swift */,
1FDCC3EF29ECB4CE00DEB39B /* AvatarButton.swift */,
1FDCC3D329EBF6E700DEB39B /* AvatarImageView.swift */,
2CF338E02CED388B0029CACC /* AvatarView.swift */,
1FDCC3EF29ECB4CE00DEB39B /* AvatarButton.swift */,
1F3C41A229EDF05700F58435 /* AvatarEditView.swift */,
1F3C41A429EDF0B800F58435 /* AvatarEditView.xib */,
2CB997C32A052449003C41AC /* EmojiAvatarPickerViewController.swift */,
Expand Down Expand Up @@ -2860,6 +2864,7 @@
1FEDE3C6257D439500853F79 /* NCChatFileController.m in Sources */,
1FEDE3CE257D43AB00853F79 /* NCMessageFileParameter.m in Sources */,
2C4446DD2658158000DF1DBC /* NCChatBlock.m in Sources */,
1F205D412CFC6DD300AAA673 /* AvatarProtocol.swift in Sources */,
1FDCC3F029ECB4CE00DEB39B /* AvatarButton.swift in Sources */,
2C06BF6720AC647A0031EB46 /* DateHeaderView.m in Sources */,
2CB6ACDA2641483800D3D641 /* NCMessageLocationParameter.m in Sources */,
Expand Down Expand Up @@ -3144,6 +3149,7 @@
2C4446F9265D5A0700DF1DBC /* NotificationCenterNotifications.m in Sources */,
1F35F8ED2AEEBC1600044BDA /* UIView+SLKAdditions.m in Sources */,
1FDFC94F2BA50B9100670DF4 /* UIFontExtension.swift in Sources */,
1F205D442CFC70AD00AAA673 /* AvatarProtocol.swift in Sources */,
1F35F8EA2AEEBC0E00044BDA /* SLKTextViewController.m in Sources */,
2C6955132B0CE1A20070F6E1 /* NCUtils.swift in Sources */,
1F8AAC342C518B8A004DA20A /* SignalingSettings.swift in Sources */,
Expand Down
5 changes: 2 additions & 3 deletions NextcloudTalk/AvatarButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import UIKit
import SDWebImage

@objcMembers class AvatarButton: UIButton {
@objcMembers class AvatarButton: UIButton, AvatarProtocol {

private var currentRequest: SDWebImageCombinedOperation?

Expand Down Expand Up @@ -63,8 +63,7 @@ import SDWebImage

// MARK: - User avatars

public func setActorAvatar(forMessage message: NCChatMessage) {
guard let account = message.account else { return }
public func setActorAvatar(forMessage message: NCChatMessage, withAccount account: TalkAccount) {
self.setActorAvatar(forId: message.actorId, withType: message.actorType, withDisplayName: message.actorDisplayName, withRoomToken: message.token, using: account)
}

Expand Down
5 changes: 2 additions & 3 deletions NextcloudTalk/AvatarImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import UIKit
import SDWebImage

@objcMembers class AvatarImageView: UIImageView {
@objcMembers class AvatarImageView: UIImageView, AvatarProtocol {

private var currentRequest: SDWebImageCombinedOperation?

Expand Down Expand Up @@ -60,8 +60,7 @@ import SDWebImage

// MARK: - User avatars

public func setActorAvatar(forMessage message: NCChatMessage) {
guard let account = message.account else { return }
public func setActorAvatar(forMessage message: NCChatMessage, withAccount account: TalkAccount) {
self.setActorAvatar(forId: message.actorId, withType: message.actorType, withDisplayName: message.actorDisplayName, withRoomToken: message.token, using: account)
}

Expand Down
18 changes: 18 additions & 0 deletions NextcloudTalk/AvatarProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
// SPDX-License-Identifier: GPL-3.0-or-later
//

protocol AvatarProtocol {

func cancelCurrentRequest()

// MARK: - Conversation avatars
func setAvatar(for room: NCRoom)
func setGroupAvatar()

// MARK: - User avatars
func setActorAvatar(forMessage message: NCChatMessage, withAccount account: TalkAccount)
func setActorAvatar(forId actorId: String?, withType actorType: String?, withDisplayName actorDisplayName: String?, withRoomToken roomToken: String?, using account: TalkAccount)

}
10 changes: 7 additions & 3 deletions NextcloudTalk/AvatarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import UIKit
import SDWebImage

@objcMembers class AvatarView: UIView {
@objcMembers class AvatarView: UIView, AvatarProtocol {

private let userStatusSizePercentage = 0.38

Expand Down Expand Up @@ -92,6 +92,10 @@ import SDWebImage
userStatusLabel.text = nil
}

func cancelCurrentRequest() {
self.avatarImageView.cancelCurrentRequest()
}

// MARK: - Conversation avatars

public func setAvatar(for room: NCRoom) {
Expand All @@ -108,8 +112,8 @@ import SDWebImage

// MARK: - User avatars

public func setActorAvatar(forMessage message: NCChatMessage) {
self.avatarImageView.setActorAvatar(forMessage: message)
public func setActorAvatar(forMessage message: NCChatMessage, withAccount account: TalkAccount) {
self.avatarImageView.setActorAvatar(forMessage: message, withAccount: account)
}

public func setActorAvatar(forId actorId: String?, withType actorType: String?, withDisplayName actorDisplayName: String?, withRoomToken roomToken: String?, using account: TalkAccount) {
Expand Down
4 changes: 0 additions & 4 deletions NextcloudTalk/BaseChatTableViewCell+Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,4 @@ extension BaseChatTableViewCell {

messageTextView.attributedText = message.parsedMarkdownForChat()
}

func prepareForReuseMessageCell() {
self.messageTextView?.text = ""
}
}
4 changes: 0 additions & 4 deletions NextcloudTalk/BaseChatTableViewCell+Poll.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ extension BaseChatTableViewCell {
pollMessageView.pollTitleTextView.text = message.parsedMessage().string
}

func prepareForReusePollCell() {
self.pollMessageView?.pollTitleTextView.text = ""
}

@objc func pollViewTapped() {
guard let poll = message?.poll else {
return
Expand Down
25 changes: 8 additions & 17 deletions NextcloudTalk/BaseChatTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions

public var message: NCChatMessage?
public var room: NCRoom?
public var account: TalkAccount?

internal var quotedMessageView: QuotedMessageView?
internal var reactionView: ReactionsView?
Expand Down Expand Up @@ -131,24 +132,16 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
self.quotedMessageView?.avatarView.cancelCurrentRequest()
self.quotedMessageView?.avatarView.image = nil

self.titleLabel.text = ""
self.dateLabel.text = ""

self.headerPart.isHidden = false
self.quotePart.isHidden = true
self.referencePart.isHidden = true
self.reactionPart.isHidden = true

self.statusView.isHidden = false
self.statusView.subviews.forEach { $0.removeFromSuperview() }

self.referenceView?.prepareForReuse()

self.prepareForReuseMessageCell()
self.prepareForReuseFileCell()
self.prepareForReuseLocationCell()
self.prepareForReuseAudioCell()
self.prepareForReusePollCell()

if let replyGestureRecognizer {
self.removeGestureRecognizer(replyGestureRecognizer)
Expand All @@ -157,11 +150,12 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
}

// swiftlint:disable:next cyclomatic_complexity
public func setup(for message: NCChatMessage, inRoom room: NCRoom) {
public func setup(for message: NCChatMessage, inRoom room: NCRoom, withAccount account: TalkAccount) {
self.message = message
self.room = room
self.account = account

self.avatarButton.setActorAvatar(forMessage: message)
self.avatarButton.setActorAvatar(forMessage: message, withAccount: account)
self.avatarButton.menu = self.getDeferredUserMenu()
self.avatarButton.showsMenuAsPrimaryAction = true

Expand Down Expand Up @@ -189,9 +183,6 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions

self.titleLabel.attributedText = titleLabel

guard let account = message.account
else { return }

let shouldShowDeliveryStatus = NCDatabaseManager.sharedInstance().roomHasTalkCapability(kCapabilityChatReadStatus, for: room)
var shouldShowReadStatus = false

Expand All @@ -207,14 +198,14 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
self.quotedMessageView?.messageLabel.text = quoteString
self.quotedMessageView?.actorLabel.attributedText = parent.actor.attributedDisplayName
self.quotedMessageView?.highlighted = parent.isMessage(from: account.userId)
self.quotedMessageView?.avatarView.setActorAvatar(forMessage: parent)
self.quotedMessageView?.avatarView.setActorAvatar(forMessage: parent, withAccount: account)
}

if message.isGroupMessage, message.parent == nil {
self.headerPart.isHidden = true
}

// When `setDeliveryState` is not called, we still need to make sure the placeholder view is removed
// Make sure the status view is empty, when no delivery state should be set
self.statusView.subviews.forEach { $0.removeFromSuperview() }

if message.isDeleting {
Expand Down Expand Up @@ -283,6 +274,8 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
if message.isDeletedMessage {
self.statusView.isHidden = true
self.messageTextView?.textColor = .tertiaryLabel
} else {
self.statusView.isHidden = false
}

NotificationCenter.default.addObserver(self, selector: #selector(didChangeIsDownloading(notification:)), name: NSNotification.Name.NCChatFileControllerDidChangeIsDownloading, object: nil)
Expand Down Expand Up @@ -320,8 +313,6 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
}

func setDeliveryState(to deliveryState: ChatMessageDeliveryState) {
self.statusView.subviews.forEach { $0.removeFromSuperview() }

if deliveryState == .sending || deliveryState == .deleting {
let activityIndicator = MDCActivityIndicator(frame: .init(x: 0, y: 0, width: 20, height: 20))

Expand Down
14 changes: 3 additions & 11 deletions NextcloudTalk/BaseChatTableViewCell.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -70,16 +70,8 @@
<view opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="X2q-XX-H1j" userLabel="ContentPart">
<rect key="frame" x="0.0" y="100" width="422" height="257"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillProportionally" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="TkE-V6-ePd" userLabel="StatusView">
<stackView opaque="NO" contentMode="scaleToFill" placeholderIntrinsicWidth="20" placeholderIntrinsicHeight="20" axis="vertical" distribution="fillProportionally" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="TkE-V6-ePd" userLabel="StatusView">
<rect key="frame" x="15" y="5" width="20" height="20"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="F90-3N-Ecf" userLabel="PlaceholderForInterfaceBuilder">
<rect key="frame" x="0.0" y="0.0" width="20" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="swq-f4-Rot"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstAttribute="width" constant="20" id="kDD-1M-lbC"/>
</constraints>
Expand Down
Loading

0 comments on commit 0991436

Please sign in to comment.