Skip to content

Commit

Permalink
feat: view reactions sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomatree committed Sep 12, 2024
1 parent 8757923 commit 986e349
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 19 deletions.
4 changes: 4 additions & 0 deletions Revolt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
17F502562B9BFB2800A3022D /* CreateGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F502552B9BFB2800A3022D /* CreateGroup.swift */; };
17F555272AFC229900958F2F /* ServerSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F555262AFC229900958F2F /* ServerSettings.swift */; };
17F8B7092C7983730065F1DE /* CreateServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F8B7082C7983730065F1DE /* CreateServer.swift */; };
17F9D7632C9208B500D0BB6F /* MessageReactionsSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F9D7622C9208B500D0BB6F /* MessageReactionsSheet.swift */; };
36D461CF77D84B97B94929A9 /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = 03268FCCFC7D4D1F8B6E9F6F /* Sentry */; };
D49B705329C4D3FE009494A5 /* RevoltApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D49B705229C4D3FE009494A5 /* RevoltApp.swift */; };
D49B705729C4D3FE009494A5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D49B705629C4D3FE009494A5 /* Assets.xcassets */; };
Expand Down Expand Up @@ -281,6 +282,7 @@
17F502552B9BFB2800A3022D /* CreateGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateGroup.swift; sourceTree = "<group>"; };
17F555262AFC229900958F2F /* ServerSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSettings.swift; sourceTree = "<group>"; };
17F8B7082C7983730065F1DE /* CreateServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateServer.swift; sourceTree = "<group>"; };
17F9D7622C9208B500D0BB6F /* MessageReactionsSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageReactionsSheet.swift; sourceTree = "<group>"; };
D49B704F29C4D3FE009494A5 /* Revolt.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Revolt.app; sourceTree = BUILT_PRODUCTS_DIR; };
D49B705229C4D3FE009494A5 /* RevoltApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RevoltApp.swift; sourceTree = "<group>"; };
D49B705629C4D3FE009494A5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -604,6 +606,7 @@
1748B2062B1FB88B00AA2D47 /* MessageReactions.swift */,
1759C3992B291A75006E6BBE /* MessageContentsView.swift */,
1759C39B2B291E2F006E6BBE /* SystemMessageView.swift */,
17F9D7622C9208B500D0BB6F /* MessageReactionsSheet.swift */,
);
path = MessageRenderer;
sourceTree = "<group>";
Expand Down Expand Up @@ -935,6 +938,7 @@
178BB1172B02E63B001143A4 /* LoadingSpinnerView.swift in Sources */,
17CE783F2B129E28006C1D2C /* ServerScrollView.swift in Sources */,
DA99EC5029D5F35900419FDA /* Login.swift in Sources */,
17F9D7632C9208B500D0BB6F /* MessageReactionsSheet.swift in Sources */,
178BB1102B02D89A001143A4 /* HCaptchaView.swift in Sources */,
17DFB4642AE06A5D00E1D417 /* Settings.swift in Sources */,
17F555272AFC229900958F2F /* ServerSettings.swift in Sources */,
Expand Down
25 changes: 20 additions & 5 deletions Revolt/Components/MessageRenderer/MessageContentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct MessageContentsView: View {
@State var showMemberSheet: Bool = false
@State var showReportSheet: Bool = false
@State var showReactSheet: Bool = false
@State var showReactionsSheet: Bool = false
@State var isStatic: Bool

private var canManageMessages: Bool {
Expand All @@ -78,7 +79,7 @@ struct MessageContentsView: View {

var body: some View {
VStack(alignment: .leading, spacing: 2) {
if let content = Binding(viewModel.$message.content) {
if let content = Binding(viewModel.$message.content), !content.wrappedValue.isEmpty {
Contents(text: content, fontSize: 16)
//.font(.body)
}
Expand All @@ -88,10 +89,13 @@ struct MessageContentsView: View {
MessageEmbed(embed: embed)
}
}

VStack(alignment: .leading) {
ForEach(viewModel.message.attachments ?? []) { attachment in
MessageAttachment(attachment: attachment)


if let attachments = viewModel.message.attachments {
VStack(alignment: .leading) {
ForEach(attachments) { attachment in
MessageAttachment(attachment: attachment)
}
}
}

Expand All @@ -118,6 +122,9 @@ struct MessageContentsView: View {
.presentationDetents([.large])
.presentationBackground(viewState.theme.background)
}
.sheet(isPresented: $showReactionsSheet) {
MessageReactionsSheet(viewModel: viewModel)
}
.contextMenu(menuItems: {
if !isStatic {
Button(action: viewModel.reply, label: {
Expand All @@ -130,6 +137,14 @@ struct MessageContentsView: View {
Label("React", systemImage: "face.smiling.inverse")
}

if !(viewModel.message.reactions?.isEmpty ?? true) {
Button {
showReactionsSheet = true
} label: {
Label("Reactions", systemImage: "face.smiling.inverse")
}
}

Button {
copyText(text: viewModel.message.content ?? "")
} label: {
Expand Down
30 changes: 16 additions & 14 deletions Revolt/Components/MessageRenderer/MessageReactions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,22 @@ struct MessageReactions: View {
let restrict_reactions = interactions?.restrict_reactions ?? false
let (required, optional) = getReactions()

HFlow(spacing: 4) {
ForEach(required, id: \.0) { (emoji, users) in
MessageReaction(channel: channel, message: message, emoji: emoji, users: users)
}

if required.count != 0, optional.count != 0 {
Divider()
.frame(height: 14)
.foregroundStyle(viewState.theme.foreground3)
.padding(.horizontal, 2)
}

ForEach(optional, id: \.0) { (emoji, users) in
MessageReaction(channel: channel, message: message, emoji: emoji, users: users, disabled: restrict_reactions)
if !required.isEmpty || !optional.isEmpty {
HFlow(spacing: 4) {
ForEach(required, id: \.0) { (emoji, users) in
MessageReaction(channel: channel, message: message, emoji: emoji, users: users)
}

if required.count != 0, optional.count != 0 {
Divider()
.frame(height: 14)
.foregroundStyle(viewState.theme.foreground3)
.padding(.horizontal, 2)
}

ForEach(optional, id: \.0) { (emoji, users) in
MessageReaction(channel: channel, message: message, emoji: emoji, users: users, disabled: restrict_reactions)
}
}
}
}
Expand Down
77 changes: 77 additions & 0 deletions Revolt/Components/MessageRenderer/MessageReactionsSheet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// MessageReactionsSheet.swift
// Revolt
//
// Created by Angelo on 11/09/2024.
//

import Foundation
import SwiftUI
import Types

struct MessageReactionsSheet: View {
@EnvironmentObject var viewState: ViewState

@ObservedObject var viewModel: MessageContentsViewModel
@State var selection: String

init(viewModel: MessageContentsViewModel) {
self.viewModel = viewModel
selection = viewModel.message.reactions!.keys.first!
}

var body: some View {
VStack {
ScrollView(.horizontal) {
HStack {
ForEach(Array(viewModel.message.reactions!.keys), id: \.self) { emoji in
Button {
selection = emoji
} label: {
HStack(spacing: 8) {
if emoji.count == 26 {
LazyImage(source: .emoji(emoji), height: 16, width: 16, clipTo: Rectangle())
} else {
Text(verbatim: emoji)
.font(.system(size: 16))
}

Text(verbatim: String(viewModel.message.reactions![emoji]!.count))

}
}
.padding(8)
.background(RoundedRectangle(cornerRadius: 5).foregroundStyle(selection == emoji ? viewState.theme.background3 : viewState.theme.background2))
}
}
.padding(16)
}

HStack {
let users = viewModel.message.reactions![selection]!

List {
ForEach(users.compactMap({ viewState.users[$0] }), id: \.self) { user in
let member = viewModel.server.flatMap { viewState.members[$0.id]![user.id] }

Button {
viewState.openUserSheet(user: user, member: member)
} label: {
HStack(spacing: 8) {
Avatar(user: user, member: member)

Text(verbatim: member?.nickname ?? user.display_name ?? user.username)
}
}
}
.listRowSeparator(.hidden)
.listRowBackground(viewState.theme.background)
}

}
}
.padding(.top, 16)
.presentationDragIndicator(.visible)
.presentationBackground(viewState.theme.background)
}
}

0 comments on commit 986e349

Please sign in to comment.