Skip to content

Commit

Permalink
feat(user): show discord and guild join dates
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoAlgorithm committed Sep 28, 2023
1 parent 0d8d3bf commit c2c38f6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Swiftcord/Utils/Extensions/DiscordAPI/Guild+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ import DiscordKitCore
extension Guild {
var isDMChannel: Bool { id == "@me" }
}

extension Guild {
func iconURL(size: Int = 240) -> String? {
icon != nil ? "\(DiscordKitConfig.default.cdnURL)icons/\(id)/\(icon!).webp?size=\(size)" : nil
}
}
6 changes: 6 additions & 0 deletions Swiftcord/Utils/Extensions/DiscordAPI/Snowflake+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ extension Snowflake {

var isDM: Bool { self == Self.DM_GUILD }
}

extension Snowflake {
var createdAt: Date? {
decodeToDate()
}
}
2 changes: 1 addition & 1 deletion Swiftcord/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct ContentView: View {
ServerButton(
selected: state.selectedGuildID == guild.id || loadingGuildID == guild.id,
name: guild.properties.name,
serverIconURL: guild.properties.icon != nil ? "\(DiscordKitConfig.default.cdnURL)icons/\(guild.id)/\(guild.properties.icon!).webp?size=240" : nil,
serverIconURL: guild.properties.iconURL(),
isLoading: loadingGuildID == guild.id
) {
state.selectedGuildID = guild.id
Expand Down
23 changes: 23 additions & 0 deletions Swiftcord/Views/User/Avatar/UserAvatarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ struct UserAvatarView: View {
.tint(.blue)
}

Text("Member Since")
.font(.headline)
.textCase(.uppercase)
.padding(.top, 6)
HStack(spacing: 8) {
Image("DiscordIcon").resizable().aspectRatio(contentMode: .fit).frame(width: 16)
Text(user.id.createdAt?.formatted(.dateTime.day().month().year()) ?? "Unknown")

Circle().fill(Color(nsColor: .separatorColor)).frame(width: 4, height: 4)

if let iconURL = ctx.guild?.properties.iconURL(size: 32), let url = URL(string: iconURL) {
BetterImageView(url: url).frame(width: 16).clipShape(Circle())
} else {
Text("\(ctx.guild?.properties.name ?? "")")
.font(.caption)
.fixedSize()
.frame(width: 16, height: 16, alignment: .leading)
.background(.gray.opacity(0.5))
.clipShape(Circle())
}
Text(member?.joined_at.formatted(.dateTime.day().month().year()) ?? "Unknown")
}

if guildID != "@me" {
let guildRoles = ctx.roles
let roles = guildRoles.filter {
Expand Down

0 comments on commit c2c38f6

Please sign in to comment.