Skip to content

Commit

Permalink
fix(user): update most uses of username to match Discord username update
Browse files Browse the repository at this point in the history
fix(currentUser): show username instead of discrim if account is migrated, in user footer
  • Loading branch information
cryptoAlgorithm committed Oct 5, 2023
1 parent 87aae42 commit 71cf78d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Swiftcord/Utils/Extensions/DiscordAPI/Channel+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import DiscordKitCore
extension Channel {
func label(_ users: [Snowflake: User] = [:]) -> String? {
name ?? recipient_ids?
.compactMap { users[$0]?.username }
.compactMap { users[$0]?.displayName }
.joined(separator: ", ")
}
}
Expand Down
15 changes: 15 additions & 0 deletions Swiftcord/Utils/Extensions/DiscordAPI/User+displayName.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// User+displayName.swift
// Swiftcord
//
// Created by Vincent Kwok on 5/10/23.
//

import Foundation
import DiscordKitCore

extension User {
var displayName: String {
global_name ?? username
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct MessageView: View, Equatable {
VStack(alignment: .leading, spacing: Self.lineSpacing) {
if !shrunk {
HStack(spacing: 6) {
Text(message.member?.nick ?? message.author.username)
Text(message.member?.nick ?? message.author.displayName)
.font(.system(size: 15))
.fontWeight(.medium)
if message.author.bot ?? false || message.webhook_id != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct ReferenceMessageView: View {
)

Group {
Text(quotedMsg.author.username)
Text(quotedMsg.author.displayName)
.font(.system(size: 14))
.opacity(0.9)

Expand Down
4 changes: 2 additions & 2 deletions Swiftcord/Views/Message/MessagesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ struct MessagesView: View {
}
.overlay {
let typingMembers = ctx.typingStarted[channel.id]?
.map { $0.member?.nick ?? $0.member?.user?.username ?? "" } ?? []
.map { $0.member?.nick ?? $0.member?.user?.displayName ?? "" } ?? []

if !typingMembers.isEmpty {
HStack {
// The dimensions are quite arbitrary
// FIXME: The animation broke, will have to fix it
LottieView(name: "typing-animatiokn", play: .constant(true), width: 160, height: 160)
LottieView(name: "typing-animation", play: .constant(true), width: 160, height: 160)
.lottieLoopMode(.loop)
.frame(width: 32, height: 24)
Group {
Expand Down
4 changes: 2 additions & 2 deletions Swiftcord/Views/User/CurrentUserFooter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ struct CurrentUserFooter: View {
.controlSize(.small)

VStack(alignment: .leading, spacing: 0) {
Text(user.username).font(.headline)
Text(user.global_name ?? user.username).font(.headline)
Group {
if let customStatus = customStatus {
Text(customStatus.state ?? "")
.lineLimit(1)
.truncationMode(.tail)
} else {
Text("#" + user.discriminator)
Text(user.discriminator == "0" ? user.username : "#" + user.discriminator)
}
}.font(.system(size: 12)).opacity(0.75)
}
Expand Down

0 comments on commit 71cf78d

Please sign in to comment.