Skip to content

Commit 71cf78d

Browse files
fix(user): update most uses of username to match Discord username update
fix(currentUser): show username instead of discrim if account is migrated, in user footer
1 parent 87aae42 commit 71cf78d

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

Swiftcord/Utils/Extensions/DiscordAPI/Channel+.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import DiscordKitCore
1010
extension Channel {
1111
func label(_ users: [Snowflake: User] = [:]) -> String? {
1212
name ?? recipient_ids?
13-
.compactMap { users[$0]?.username }
13+
.compactMap { users[$0]?.displayName }
1414
.joined(separator: ", ")
1515
}
1616
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// User+displayName.swift
3+
// Swiftcord
4+
//
5+
// Created by Vincent Kwok on 5/10/23.
6+
//
7+
8+
import Foundation
9+
import DiscordKitCore
10+
11+
extension User {
12+
var displayName: String {
13+
global_name ?? username
14+
}
15+
}

Swiftcord/Views/Message/MessageRenderViews/MessageView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct MessageView: View, Equatable {
8787
VStack(alignment: .leading, spacing: Self.lineSpacing) {
8888
if !shrunk {
8989
HStack(spacing: 6) {
90-
Text(message.member?.nick ?? message.author.username)
90+
Text(message.member?.nick ?? message.author.displayName)
9191
.font(.system(size: 15))
9292
.fontWeight(.medium)
9393
if message.author.bot ?? false || message.webhook_id != nil {

Swiftcord/Views/Message/MessageRenderViews/ReferenceMessageView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct ReferenceMessageView: View {
3636
)
3737

3838
Group {
39-
Text(quotedMsg.author.username)
39+
Text(quotedMsg.author.displayName)
4040
.font(.system(size: 14))
4141
.opacity(0.9)
4242

Swiftcord/Views/Message/MessagesView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ struct MessagesView: View {
285285
}
286286
.overlay {
287287
let typingMembers = ctx.typingStarted[channel.id]?
288-
.map { $0.member?.nick ?? $0.member?.user?.username ?? "" } ?? []
288+
.map { $0.member?.nick ?? $0.member?.user?.displayName ?? "" } ?? []
289289

290290
if !typingMembers.isEmpty {
291291
HStack {
292292
// The dimensions are quite arbitrary
293293
// FIXME: The animation broke, will have to fix it
294-
LottieView(name: "typing-animatiokn", play: .constant(true), width: 160, height: 160)
294+
LottieView(name: "typing-animation", play: .constant(true), width: 160, height: 160)
295295
.lottieLoopMode(.loop)
296296
.frame(width: 32, height: 24)
297297
Group {

Swiftcord/Views/User/CurrentUserFooter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ struct CurrentUserFooter: View {
9898
.controlSize(.small)
9999

100100
VStack(alignment: .leading, spacing: 0) {
101-
Text(user.username).font(.headline)
101+
Text(user.global_name ?? user.username).font(.headline)
102102
Group {
103103
if let customStatus = customStatus {
104104
Text(customStatus.state ?? "")
105105
.lineLimit(1)
106106
.truncationMode(.tail)
107107
} else {
108-
Text("#" + user.discriminator)
108+
Text(user.discriminator == "0" ? user.username : "#" + user.discriminator)
109109
}
110110
}.font(.system(size: 12)).opacity(0.75)
111111
}

0 commit comments

Comments
 (0)