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

Active account improvements #1802

Merged
merged 8 commits into from
Nov 18, 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
7 changes: 6 additions & 1 deletion NextcloudTalk/AddParticipantsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}

cell.labelTitle.text = participant.name;
[cell.contactImage setActorAvatarForId:participant.userId withType:participant.source withDisplayName:participant.name withRoomToken:_room.token];

TalkAccount *account = self->_room.account;

if (account) {
[cell.contactImage setActorAvatarForId:participant.userId withType:participant.source withDisplayName:participant.name withRoomToken:_room.token using:account];
}

UIImage *selectionImage = [UIImage systemImageNamed:@"circle"];
UIColor *selectionImageColor = [UIColor tertiaryLabelColor];
Expand Down
9 changes: 3 additions & 6 deletions NextcloudTalk/AvatarButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,11 @@ import SDWebImage
// MARK: - User avatars

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

public func setActorAvatar(forId actorId: String?, withType actorType: String?, withDisplayName actorDisplayName: String?, withRoomToken roomToken: String?) {
self.setActorAvatar(forId: actorId, withType: actorType, withDisplayName: actorDisplayName, withRoomToken: roomToken, using: nil)
}

public func setActorAvatar(forId actorId: String?, withType actorType: String?, withDisplayName actorDisplayName: String?, withRoomToken roomToken: String?, using account: TalkAccount?) {
public func setActorAvatar(forId actorId: String?, withType actorType: String?, withDisplayName actorDisplayName: String?, withRoomToken roomToken: String?, using account: TalkAccount) {
self.cancelCurrentRequest()

self.currentRequest = AvatarManager.shared.getActorAvatar(forId: actorId, withType: actorType, withDisplayName: actorDisplayName, withRoomToken: roomToken, withStyle: self.traitCollection.userInterfaceStyle, usingAccount: account) { image in
Expand Down
9 changes: 3 additions & 6 deletions NextcloudTalk/AvatarImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,11 @@ import SDWebImage
// MARK: - User avatars

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

public func setActorAvatar(forId actorId: String?, withType actorType: String?, withDisplayName actorDisplayName: String?, withRoomToken roomToken: String?) {
self.setActorAvatar(forId: actorId, withType: actorType, withDisplayName: actorDisplayName, withRoomToken: roomToken, using: nil)
}

public func setActorAvatar(forId actorId: String?, withType actorType: String?, withDisplayName actorDisplayName: String?, withRoomToken roomToken: String?, using account: TalkAccount?) {
public func setActorAvatar(forId actorId: String?, withType actorType: String?, withDisplayName actorDisplayName: String?, withRoomToken roomToken: String?, using account: TalkAccount) {
self.cancelCurrentRequest()

self.currentRequest = AvatarManager.shared.getActorAvatar(forId: actorId, withType: actorType, withDisplayName: actorDisplayName, withRoomToken: roomToken, withStyle: self.traitCollection.userInterfaceStyle, usingAccount: account) { image in
Expand Down
14 changes: 5 additions & 9 deletions NextcloudTalk/AvatarManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SDWebImage
// MARK: - Conversation avatars

public func getAvatar(for room: NCRoom, with style: UIUserInterfaceStyle, completionBlock: @escaping (_ image: UIImage?) -> Void) -> SDWebImageCombinedOperation? {
if room.accountId != nil, NCDatabaseManager.sharedInstance().serverHasTalkCapability(kCapabilityConversationAvatars, forAccountId: room.accountId) {
if NCDatabaseManager.sharedInstance().serverHasTalkCapability(kCapabilityConversationAvatars, forAccountId: room.accountId) {
// Server supports conversation avatars -> try to get the avatar using this API

return NCAPIController.sharedInstance().getAvatarFor(room, with: style) { image, _ in
Expand Down Expand Up @@ -50,7 +50,7 @@ import SDWebImage
} else {
switch room.type {
case .oneToOne:
let account = NCDatabaseManager.sharedInstance().talkAccount(forAccountId: room.accountId)
guard let account = room.account else { return nil }
return self.getUserAvatar(forId: room.name, withStyle: style, usingAccount: account, completionBlock: completionBlock)
case .formerOneToOne:
completionBlock(UIImage(named: "user-avatar", in: nil, compatibleWith: traitCollection))
Expand All @@ -71,7 +71,7 @@ import SDWebImage
// MARK: - Actor avatars

// swiftlint:disable:next function_parameter_count
public func getActorAvatar(forId actorId: String?, withType actorType: String?, withDisplayName actorDisplayName: String?, withRoomToken roomToken: String?, withStyle style: UIUserInterfaceStyle, usingAccount account: TalkAccount?, completionBlock: @escaping (_ image: UIImage?) -> Void) -> SDWebImageCombinedOperation? {
public func getActorAvatar(forId actorId: String?, withType actorType: String?, withDisplayName actorDisplayName: String?, withRoomToken roomToken: String?, withStyle style: UIUserInterfaceStyle, usingAccount account: TalkAccount, completionBlock: @escaping (_ image: UIImage?) -> Void) -> SDWebImageCombinedOperation? {
if let actorId {
if actorType == "bots" {
return getBotsAvatar(forId: actorId, withStyle: style, completionBlock: completionBlock)
Expand Down Expand Up @@ -123,9 +123,7 @@ import SDWebImage
return NCUtils.getImage(withString: "X", withBackgroundColor: .systemGray3, withBounds: self.avatarDefaultSize, isCircular: true)
}

private func getUserAvatar(forId actorId: String, withStyle style: UIUserInterfaceStyle, usingAccount account: TalkAccount?, completionBlock: @escaping (_ image: UIImage?) -> Void) -> SDWebImageCombinedOperation? {
let account = account ?? NCDatabaseManager.sharedInstance().activeAccount()

private func getUserAvatar(forId actorId: String, withStyle style: UIUserInterfaceStyle, usingAccount account: TalkAccount, completionBlock: @escaping (_ image: UIImage?) -> Void) -> SDWebImageCombinedOperation? {
return NCAPIController.sharedInstance().getUserAvatar(forUser: actorId, using: account, with: style) { image, _ in
if image != nil {
completionBlock(image)
Expand All @@ -138,9 +136,7 @@ import SDWebImage
}
}

private func getFederatedUserAvatar(forId actorId: String, withRoomToken roomToken: String?, withStyle style: UIUserInterfaceStyle, usingAccount account: TalkAccount?, completionBlock: @escaping (_ image: UIImage?) -> Void) -> SDWebImageCombinedOperation? {
let account = account ?? NCDatabaseManager.sharedInstance().activeAccount()

private func getFederatedUserAvatar(forId actorId: String, withRoomToken roomToken: String?, withStyle style: UIUserInterfaceStyle, usingAccount account: TalkAccount, completionBlock: @escaping (_ image: UIImage?) -> Void) -> SDWebImageCombinedOperation? {
return NCAPIController.sharedInstance().getFederatedUserAvatar(forUser: actorId, inRoom: roomToken, using: account, with: style) { image, _ in
if image != nil {
completionBlock(image)
Expand Down
8 changes: 2 additions & 6 deletions NextcloudTalk/BannedActorTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
}

func getData() {
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()

NCAPIController.sharedInstance().listBans(for: activeAccount.accountId, in: room.token) { [weak self] bannedActors in
NCAPIController.sharedInstance().listBans(for: room.accountId, in: room.token) { [weak self] bannedActors in
guard let self else { return }

self.bannedActors = bannedActors ?? []
Expand Down Expand Up @@ -105,9 +103,7 @@
self.showActivityIndicator()
cell.setDisabledState()

let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()

NCAPIController.sharedInstance().unbanActor(for: activeAccount.accountId, in: self.room.token, with: bannedActor.banId) { [weak self] success in
NCAPIController.sharedInstance().unbanActor(for: room.accountId, in: self.room.token, with: bannedActor.banId) { [weak self] success in
if !success {
NotificationPresenter.shared().present(text: NSLocalizedString("Failed to unban selected entry", comment: ""), dismissAfterDelay: 5.0, includedStyle: .error)
}
Expand Down
21 changes: 11 additions & 10 deletions NextcloudTalk/BaseChatTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions

self.titleLabel.attributedText = titleLabel

let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
guard let account = message.account
else { return }

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

Expand All @@ -204,7 +206,7 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
let quoteString = parent.parsedMarkdownForChat()?.string ?? ""
self.quotedMessageView?.messageLabel.text = quoteString
self.quotedMessageView?.actorLabel.attributedText = parent.actor.attributedDisplayName
self.quotedMessageView?.highlighted = parent.isMessage(from: activeAccount.userId)
self.quotedMessageView?.highlighted = parent.isMessage(from: account.userId)
self.quotedMessageView?.avatarView.setActorAvatar(forMessage: parent)
}

Expand All @@ -221,7 +223,7 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
self.setDeliveryState(to: .failed)
} else if message.isTemporary {
self.setDeliveryState(to: .sending)
} else if message.isMessage(from: activeAccount.userId), shouldShowDeliveryStatus {
} else if message.isMessage(from: account.userId), shouldShowDeliveryStatus {
if room.lastCommonReadMessage >= message.messageId, shouldShowReadStatus {
self.setDeliveryState(to: .read)
} else {
Expand Down Expand Up @@ -269,7 +271,7 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
self.setupForPollCell(with: message)
} else if message.file() != nil {
// File message
self.setupForFileCell(with: message, with: activeAccount)
self.setupForFileCell(with: message, with: account)
} else if message.geoLocation() != nil {
// Location message
self.setupForLocationCell(with: message)
Expand Down Expand Up @@ -461,11 +463,10 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
// MARK: - Avatar User Menu

func getDeferredUserMenu() -> UIMenu? {
guard let message = self.message else { return nil }

let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
guard let message = self.message, let account = message.account
else { return nil }

if message.actorType != "users" || message.actorId == activeAccount.userId {
if message.actorType != "users" || message.actorId == account.userId {
return nil
}

Expand All @@ -480,9 +481,9 @@ class BaseChatTableViewCell: UITableViewCell, AudioPlayerViewDelegate, Reactions
}

func getMenuUserAction(for message: NCChatMessage, completionBlock: @escaping ([UIMenuElement]) -> Void) {
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
guard let account = message.account else { return }

NCAPIController.sharedInstance().getUserActions(forUser: message.actorId, using: activeAccount) { userActionsRaw, error in
NCAPIController.sharedInstance().getUserActions(forUser: message.actorId, using: account) { userActionsRaw, error in
guard error == nil,
let userActionsDict = userActionsRaw as? [String: AnyObject],
let userActions = userActionsDict["actions"] as? [[String: String]],
Expand Down
Loading
Loading