Skip to content
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

Pass room object to cell #1835

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 7 additions & 11 deletions NextcloudTalk/BaseChatTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
@IBOutlet weak var referencePart: UIView!

public var message: NCChatMessage?
public var messageId: Int = 0
public var room: NCRoom?

internal var quotedMessageView: QuotedMessageView?
internal var reactionView: ReactionsView?
Expand Down Expand Up @@ -157,9 +157,9 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
}

// swiftlint:disable:next cyclomatic_complexity
public func setup(for message: NCChatMessage, withLastCommonReadMessage lastCommonRead: Int) {
public func setup(for message: NCChatMessage, inRoom room: NCRoom) {
self.message = message
self.messageId = message.messageId
self.room = room

self.avatarButton.setActorAvatar(forMessage: message)
self.avatarButton.menu = self.getDeferredUserMenu()
Expand Down Expand Up @@ -190,15 +190,11 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
self.titleLabel.attributedText = titleLabel

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

if let room = NCDatabaseManager.sharedInstance().room(withToken: message.token, forAccountId: activeAccount.accountId) {
shouldShowDeliveryStatus = NCDatabaseManager.sharedInstance().roomHasTalkCapability(kCapabilityChatReadStatus, for: room)

if let roomCapabilities = NCDatabaseManager.sharedInstance().roomTalkCapabilities(for: room) {
shouldShowReadStatus = !(roomCapabilities.readStatusPrivacy)
}
if let roomCapabilities = NCDatabaseManager.sharedInstance().roomTalkCapabilities(for: room) {
shouldShowReadStatus = !(roomCapabilities.readStatusPrivacy)
}

// This check is just a workaround to fix the issue with the deleted parents returned by the API.
Expand Down Expand Up @@ -226,7 +222,7 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
} else if message.isTemporary {
self.setDeliveryState(to: .sending)
} else if message.isMessage(from: activeAccount.userId), shouldShowDeliveryStatus {
if lastCommonRead >= message.messageId, shouldShowReadStatus {
if room.lastCommonReadMessage >= message.messageId, shouldShowReadStatus {
self.setDeliveryState(to: .read)
} else {
self.setDeliveryState(to: .sent)
Expand Down
10 changes: 5 additions & 5 deletions NextcloudTalk/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@

func sendStartedTypingMessage(to sessionId: String) {
// Workaround: TypingPrivacy should be checked locally, not from the remote server, use serverCapabilities for now
// TODO: Remove workaround for federated typing indicators.

Check warning on line 1150 in NextcloudTalk/BaseChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (Remove workaround for federate...) (todo)
guard let serverCapabilities = NCDatabaseManager.sharedInstance().serverCapabilities(forAccountId: self.room.accountId)
else { return }

Expand Down Expand Up @@ -2586,7 +2586,7 @@

if let cell = self.tableView?.dequeueReusableCell(withIdentifier: cellIdentifier) as? BaseChatTableViewCell {
cell.delegate = self
cell.setup(for: message, withLastCommonReadMessage: self.room.lastCommonReadMessage)
cell.setup(for: message, inRoom: self.room)

if let playerAudioFileStatus = self.playerAudioFileStatus,
let voiceMessagesPlayer = self.voiceMessagesPlayer {
Expand All @@ -2609,7 +2609,7 @@

if let cell = self.tableView?.dequeueReusableCell(withIdentifier: cellIdentifier) as? BaseChatTableViewCell {
cell.delegate = self
cell.setup(for: message, withLastCommonReadMessage: self.room.lastCommonReadMessage)
cell.setup(for: message, inRoom: self.room)

return cell
}
Expand All @@ -2620,7 +2620,7 @@

if let cell = self.tableView?.dequeueReusableCell(withIdentifier: cellIdentifier) as? BaseChatTableViewCell {
cell.delegate = self
cell.setup(for: message, withLastCommonReadMessage: self.room.lastCommonReadMessage)
cell.setup(for: message, inRoom: self.room)

return cell
}
Expand All @@ -2631,7 +2631,7 @@

if let cell = self.tableView?.dequeueReusableCell(withIdentifier: cellIdentifier) as? BaseChatTableViewCell {
cell.delegate = self
cell.setup(for: message, withLastCommonReadMessage: self.room.lastCommonReadMessage)
cell.setup(for: message, inRoom: self.room)

return cell
}
Expand All @@ -2647,7 +2647,7 @@

if let cell = self.tableView?.dequeueReusableCell(withIdentifier: cellIdentifier) as? BaseChatTableViewCell {
cell.delegate = self
cell.setup(for: message, withLastCommonReadMessage: self.room.lastCommonReadMessage)
cell.setup(for: message, inRoom: self.room)

return cell
}
Expand Down Expand Up @@ -3346,7 +3346,7 @@

// MARK: - NCChatFileControllerDelegate

public func fileControllerDidLoadFile(_ fileController: NCChatFileController, with fileStatus: NCChatFileStatus) {

Check warning on line 3349 in NextcloudTalk/BaseChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 11 (cyclomatic_complexity)
if fileController.messageType == kMessageTypeVoiceMessage {
if fileController.actionType == actionTypeTranscribeVoiceMessage {
self.transcribeVoiceMessage(with: fileStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ final class UnitBaseChatTableViewCellTest: TestBaseRealm {
}

let deckCell: BaseChatTableViewCell = .fromNib()
deckCell.setup(for: deckMessage, withLastCommonReadMessage: 0)
deckCell.setup(for: deckMessage, inRoom: room)

let quoteCell: BaseChatTableViewCell = .fromNib()
quoteCell.setup(for: quoteMessage, withLastCommonReadMessage: 0)
quoteCell.setup(for: quoteMessage, inRoom: room)
}

}
Loading