forked from tealbathingsuit/accord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
212 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
project: Accord.xcodeproj | ||
schemes: | ||
- Accord | ||
targets: | ||
- Accord |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// DMButton.swift | ||
// Accord | ||
// | ||
// Created by evelyn on 2022-05-17. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct DMButton: View { | ||
@Binding var selection: Int? | ||
@Binding var selectedServer: Int? | ||
@StateObject var updater: ServerListView.UpdateView | ||
@State var mentionCount: Int? | ||
@State var iconHovered: Bool = false | ||
var body: some View { | ||
ZStack(alignment: .bottomTrailing) { | ||
Button(action: { | ||
selection = nil | ||
DispatchQueue.global().async { | ||
wss?.cachedMemberRequest.removeAll() | ||
ServerListView.privateChannels = ServerListView.privateChannels.sorted(by: { $0.last_message_id ?? "" > $1.last_message_id ?? "" }) | ||
} | ||
selectedServer = 201 | ||
let prevSelection = selection | ||
if let selectionPrevious = UserDefaults.standard.object(forKey: "AccordChannelDMs") as? Int { | ||
self.selection = selectionPrevious | ||
} | ||
if let selection = prevSelection { | ||
UserDefaults.standard.set(selection, forKey: "AccordChannelDMs") | ||
} | ||
}) { | ||
Image(systemName: "bubble.right.fill") | ||
.imageScale(.medium) | ||
.frame(width: 45, height: 45) | ||
.background(selectedServer == 201 ? Color.accentColor.opacity(0.5) : Color(NSColor.windowBackgroundColor)) | ||
.cornerRadius(iconHovered || selectedServer == 201 ? 13.5 : 23.5) | ||
.if(selectedServer == 201, transform: { $0.foregroundColor(Color.white) }) | ||
.onHover(perform: { h in withAnimation(Animation.linear(duration: 0.1)) { self.iconHovered = h } }) | ||
} | ||
if let mentionCount = mentionCount, mentionCount != 0 { | ||
ZStack { | ||
Circle() | ||
.foregroundColor(Color.red) | ||
.frame(width: 15, height: 15) | ||
Text(String(mentionCount)) | ||
.foregroundColor(Color.white) | ||
.fontWeight(.semibold) | ||
.font(.caption) | ||
} | ||
} | ||
} | ||
.buttonStyle(BorderlessButtonStyle()) | ||
.onReceive(self.updater.$updater, perform: { _ in | ||
DispatchQueue.global().async { | ||
self.mentionCount = ServerListView.privateChannels.compactMap({ $0.read_state?.mention_count }).reduce(0, +) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// PrivateChannelsView.swift | ||
// Accord | ||
// | ||
// Created by evelyn on 2022-05-17. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct PrivateChannelsView: View { | ||
var privateChannels: [Channel] | ||
@Binding var selection: Int? | ||
@StateObject var viewUpdater: ServerListView.UpdateView | ||
var body: some View { | ||
ForEach(privateChannels, id: \.id) { channel in | ||
NavigationLink(destination: NavigationLazyView(ChannelView(channel).equatable()), tag: Int(channel.id) ?? 0, selection: self.$selection) { | ||
ServerListViewCell(channel: channel, updater: self.viewUpdater) | ||
.onChange(of: self.selection, perform: { [selection] new in | ||
if new == Int(channel.id) { | ||
channel.read_state?.mention_count = 0 | ||
channel.read_state?.last_message_id = channel.last_message_id | ||
viewUpdater.updateView() | ||
} else if selection == Int(channel.id) { | ||
print("wow") | ||
channel.read_state?.mention_count = 0 | ||
channel.read_state?.last_message_id = channel.last_message_id | ||
} | ||
}) | ||
} | ||
.contextMenu { | ||
Button("Copy Channel ID") { | ||
NSPasteboard.general.clearContents() | ||
NSPasteboard.general.setString(channel.id, forType: .string) | ||
} | ||
Button("Close DM") { | ||
let headers = Headers( | ||
userAgent: discordUserAgent, | ||
contentType: nil, | ||
token: AccordCoreVars.token, | ||
type: .DELETE, | ||
discordHeaders: true, | ||
referer: "https://discord.com/channels/@me", | ||
empty: true | ||
) | ||
Request.ping(url: URL(string: "\(rootURL)/channels/\(channel.id)"), headers: headers) | ||
guard let index = ServerListView.privateChannels[indexOf: channel.id] else { return } | ||
ServerListView.privateChannels.remove(at: index) | ||
} | ||
Button("Mark as read") { | ||
channel.read_state?.mention_count = 0 | ||
channel.read_state?.last_message_id = channel.last_message_id | ||
} | ||
Button("Open in new window") { | ||
showWindow(channel) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.