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

Improve unread behavior #162

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions Swiftcord/ButtonStyles/DiscordChannelButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct DiscordChannelButton: ButtonStyle {
let isSelected: Bool
let unread: Bool
@State var isHovered: Bool = false

@Environment(\.controlSize) var size: ControlSize
Expand All @@ -19,8 +20,8 @@ struct DiscordChannelButton: ButtonStyle {
.frame(height: size == .large ? 42 : 32)
.padding(.horizontal, 2)
.font(.system(size: 15))
.foregroundColor(isSelected ? Color(nsColor: .labelColor) : .gray)
.accentColor(isSelected ? Color(nsColor: .labelColor) : .gray)
.foregroundColor(isSelected ? Color(nsColor: .labelColor) : unread ? Color(nsColor: .labelColor) : .gray)
.accentColor(isSelected ? Color(nsColor: .labelColor) : unread ? Color(nsColor: .labelColor) : .gray)
.background {
RoundedRectangle(cornerRadius: 5)
.fill(isSelected ? .gray.opacity(0.3) : (isHovered ? .gray.opacity(0.2) : .clear))
Expand Down
5 changes: 5 additions & 0 deletions Swiftcord/Views/Message/MessagesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ struct MessagesView: View {
guard msg.webhook_id == nil else { break }
// Remove typing status after user sent a message
ctx.typingStarted[msg.channel_id]?.removeAll { $0.user_id == msg.author.id }

// If user sends message, reset last message.
if gateway.cache.user?.id == msg.author.id {
gateway.readState[msg.channel_id] = gateway.readState[msg.channel_id]?.updatingLastMessage(id: msg.id)
}
case .messageUpdate(let newMsg):
guard newMsg.channel_id == ctx.channel?.id else { break }
viewModel.updateMessage(newMsg)
Expand Down
7 changes: 5 additions & 2 deletions Swiftcord/Views/Server/ChannelButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ struct ChannelButton: View, Equatable {

let channel: Channel
@Binding var selectedCh: Channel?

@EnvironmentObject var gateway: DiscordGateway

var body: some View {
let unread = gateway.readState[channel.id]?.last_message_id?.intValue ?? 0 < Int(channel.last_message_id ?? "0") ?? 0
if channel.type == .dm || channel.type == .groupDM {
DMButton(dm: channel, selectedCh: $selectedCh)
.buttonStyle(DiscordChannelButton(isSelected: selectedCh?.id == channel.id))
.buttonStyle(DiscordChannelButton(isSelected: selectedCh?.id == channel.id, unread: unread))
.controlSize(.large)
} else {
GuildChButton(channel: channel, selectedCh: $selectedCh)
.buttonStyle(DiscordChannelButton(isSelected: selectedCh?.id == channel.id))
.buttonStyle(DiscordChannelButton(isSelected: selectedCh?.id == channel.id, unread: unread))
}
}
}
Expand Down