2024-01-31 16:47:29 +01:00
|
|
|
//Made by Lumaa
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct NotificationRow: View {
|
2024-02-04 10:44:51 +01:00
|
|
|
@EnvironmentObject private var navigator: Navigator
|
2024-02-04 08:43:56 +01:00
|
|
|
|
2024-02-29 13:33:17 +01:00
|
|
|
@State private var multiPeopleSheet: Bool = false
|
|
|
|
|
|
|
|
var notif: GroupedNotification
|
2024-02-10 02:22:39 +01:00
|
|
|
var showIcon: Bool = true
|
2024-01-31 16:47:29 +01:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack {
|
|
|
|
HStack(spacing: 5) {
|
2024-02-29 13:33:17 +01:00
|
|
|
if let acc = notif.accounts.first {
|
|
|
|
if notif.accounts.count == 1 {
|
|
|
|
ProfilePicture(url: acc.avatar, size: 60)
|
|
|
|
.padding(.trailing)
|
|
|
|
.overlay(alignment: .bottomTrailing) {
|
|
|
|
if showIcon {
|
|
|
|
notifIcon()
|
|
|
|
.offset(x: -5, y: 5)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal, 10)
|
|
|
|
.onTapGesture {
|
|
|
|
navigator.navigate(to: .account(acc: acc))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
accountCount()
|
|
|
|
.padding(.trailing)
|
|
|
|
.overlay(alignment: .bottomTrailing) {
|
|
|
|
if showIcon {
|
|
|
|
notifIcon()
|
|
|
|
.offset(x: -5, y: 5)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal, 10)
|
|
|
|
.onTapGesture {
|
|
|
|
multiPeopleSheet.toggle()
|
|
|
|
}
|
2024-02-04 08:43:56 +01:00
|
|
|
}
|
2024-02-29 13:33:17 +01:00
|
|
|
}
|
2024-02-04 08:43:56 +01:00
|
|
|
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(localizedString())
|
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
.font(.subheadline)
|
|
|
|
.lineLimit(2)
|
|
|
|
|
|
|
|
if notif.status != nil {
|
|
|
|
TextEmoji(notif.status!.content, emojis: notif.status!.emojis)
|
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundStyle(Color.gray)
|
|
|
|
.lineLimit(3, reservesSpace: true)
|
2024-02-08 08:33:20 +01:00
|
|
|
|
2024-02-29 13:33:17 +01:00
|
|
|
|
|
|
|
HStack(spacing: 7.5) {
|
|
|
|
if notif.status!.mediaAttachments.count > 0 {
|
|
|
|
Label("activity.status.attachments-\(notif.status!.mediaAttachments.count)", systemImage: notif.status!.mediaAttachments.count > 1 ? "photo.on.rectangle.angled" : "photo")
|
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundStyle(Color.gray)
|
|
|
|
.lineLimit(1, reservesSpace: false)
|
|
|
|
}
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
Text(notif.notifications[0].createdAt.relativeFormatted)
|
2024-02-08 08:33:20 +01:00
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundStyle(Color.gray)
|
|
|
|
.lineLimit(1, reservesSpace: false)
|
|
|
|
}
|
2024-02-04 08:43:56 +01:00
|
|
|
} else {
|
2024-02-29 13:33:17 +01:00
|
|
|
if let acc = notif.accounts.first {
|
|
|
|
TextEmoji(acc.note, emojis: acc.emojis)
|
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundStyle(Color.gray)
|
|
|
|
.lineLimit(3, reservesSpace: true)
|
|
|
|
}
|
2024-02-04 08:43:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
.onTapGesture {
|
2024-02-29 13:33:17 +01:00
|
|
|
navigator.navigate(to: notif.status == nil ? .account(acc: notif.accounts.first!) : .post(status: notif.status!))
|
2024-02-04 08:43:56 +01:00
|
|
|
}
|
2024-01-31 16:47:29 +01:00
|
|
|
}
|
|
|
|
.padding(.horizontal)
|
2024-02-29 13:33:17 +01:00
|
|
|
.sheet(isPresented: $multiPeopleSheet) {
|
|
|
|
users
|
|
|
|
.presentationDetents([.height(200), .medium])
|
|
|
|
.presentationDragIndicator(.visible)
|
|
|
|
.presentationCornerRadius(25)
|
|
|
|
.scrollBounceBehavior(.basedOnSize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var users: some View {
|
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
|
|
VStack(alignment: .listRowSeparatorLeading) {
|
|
|
|
ForEach(notif.accounts) { acc in
|
|
|
|
HStack {
|
|
|
|
ProfilePicture(url: acc.avatar, size: 60)
|
|
|
|
.padding(.horizontal)
|
|
|
|
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(acc.displayName ?? acc.username)
|
|
|
|
.font(.body.bold())
|
|
|
|
Text("@\(acc.acct)")
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundStyle(Color.gray)
|
|
|
|
.lineLimit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.padding(.vertical)
|
|
|
|
.onTapGesture {
|
|
|
|
multiPeopleSheet.toggle()
|
|
|
|
navigator.navigate(to: .account(acc: acc))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.top)
|
2024-01-31 16:47:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-04 08:43:56 +01:00
|
|
|
private func localizedString() -> LocalizedStringKey {
|
2024-02-29 13:33:17 +01:00
|
|
|
var nameStr: String = ""
|
|
|
|
if notif.accounts.count > 1, let acc = notif.accounts.first {
|
|
|
|
nameStr = String(localized: "activity.group.\("@" + acc.username)-\(notif.accounts.count - 1)")
|
|
|
|
} else if let acc = notif.accounts.first {
|
|
|
|
nameStr = "@\(acc.username)"
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (notif.type) {
|
2024-01-31 16:47:29 +01:00
|
|
|
case .favourite:
|
2024-02-04 08:43:56 +01:00
|
|
|
return "activity.favorite.\(nameStr)"
|
2024-01-31 16:47:29 +01:00
|
|
|
case .follow:
|
2024-02-04 08:43:56 +01:00
|
|
|
return "activity.followed.\(nameStr)"
|
2024-01-31 16:47:29 +01:00
|
|
|
case .mention:
|
2024-02-04 08:43:56 +01:00
|
|
|
return "activity.mentionned.\(nameStr)"
|
2024-01-31 16:47:29 +01:00
|
|
|
case .reblog:
|
2024-02-04 08:43:56 +01:00
|
|
|
return "activity.reblogged.\(nameStr)"
|
2024-01-31 16:47:29 +01:00
|
|
|
case .status:
|
2024-02-04 08:43:56 +01:00
|
|
|
return "activity.status.\(nameStr)"
|
2024-02-29 13:33:17 +01:00
|
|
|
case .update:
|
|
|
|
return "activity.update.\(nameStr)"
|
2024-03-09 16:09:03 +01:00
|
|
|
case .poll:
|
|
|
|
return "activity.poll.\(nameStr)"
|
2024-01-31 16:47:29 +01:00
|
|
|
default:
|
2024-03-09 16:09:03 +01:00
|
|
|
return "activity.unknown" // follow requests
|
2024-01-31 16:47:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func notifColor() -> Color {
|
2024-02-29 13:33:17 +01:00
|
|
|
switch (notif.type) {
|
2024-01-31 16:47:29 +01:00
|
|
|
case .favourite:
|
|
|
|
return Color.red
|
|
|
|
case .follow:
|
|
|
|
return Color.purple
|
|
|
|
case .mention:
|
|
|
|
return Color.blue
|
|
|
|
case .reblog:
|
2024-02-08 08:33:20 +01:00
|
|
|
return Color.orange
|
2024-02-29 13:33:17 +01:00
|
|
|
case .status, .update: // update and post are techn. the same
|
2024-01-31 16:47:29 +01:00
|
|
|
return Color.yellow
|
2024-03-09 16:09:03 +01:00
|
|
|
case .poll:
|
|
|
|
return Color.green
|
2024-01-31 16:47:29 +01:00
|
|
|
default:
|
|
|
|
return Color.gray
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
private func notifIcon() -> some View {
|
2024-02-10 01:08:53 +01:00
|
|
|
let size: CGFloat = 60.0 / 4.0
|
2024-02-04 08:43:56 +01:00
|
|
|
|
2024-01-31 16:47:29 +01:00
|
|
|
ZStack {
|
2024-02-29 13:33:17 +01:00
|
|
|
switch (notif.type) {
|
2024-01-31 16:47:29 +01:00
|
|
|
case .favourite:
|
|
|
|
Image(systemName: "heart.fill")
|
2024-02-10 01:08:53 +01:00
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(width: size, height: size)
|
2024-01-31 16:47:29 +01:00
|
|
|
case .follow:
|
|
|
|
Image(systemName: "person.fill.badge.plus")
|
2024-02-10 01:08:53 +01:00
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(width: size, height: size)
|
2024-01-31 16:47:29 +01:00
|
|
|
case .mention:
|
|
|
|
Image(systemName: "tag.fill")
|
2024-02-10 01:08:53 +01:00
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(width: size, height: size)
|
2024-01-31 16:47:29 +01:00
|
|
|
case .reblog:
|
|
|
|
Image(systemName: "bolt.horizontal.fill")
|
2024-02-10 01:08:53 +01:00
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(width: size, height: size)
|
2024-01-31 16:47:29 +01:00
|
|
|
case .status:
|
|
|
|
Image(systemName: "text.badge.plus")
|
2024-02-10 01:08:53 +01:00
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(width: size, height: size)
|
2024-02-29 13:33:17 +01:00
|
|
|
case .update:
|
|
|
|
Image(systemName: "pencil.and.scribble")
|
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(width: size, height: size)
|
2024-03-09 16:09:03 +01:00
|
|
|
case .poll:
|
|
|
|
Image(systemName: "checklist")
|
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(width: size, height: size)
|
2024-01-31 16:47:29 +01:00
|
|
|
default:
|
|
|
|
Image(systemName: "questionmark")
|
2024-02-10 01:08:53 +01:00
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(width: size, height: size)
|
2024-01-31 16:47:29 +01:00
|
|
|
}
|
|
|
|
}
|
2024-02-04 08:43:56 +01:00
|
|
|
.frame(minWidth: 30)
|
|
|
|
.padding(7)
|
2024-01-31 16:47:29 +01:00
|
|
|
.background(notifColor())
|
|
|
|
.clipShape(.circle)
|
|
|
|
.overlay {
|
|
|
|
Circle()
|
|
|
|
.stroke(Color.appBackground, lineWidth: 3)
|
|
|
|
}
|
|
|
|
.fixedSize()
|
|
|
|
}
|
2024-02-29 13:33:17 +01:00
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
private func accountCount() -> some View {
|
|
|
|
ZStack {
|
|
|
|
Text(String("+\(notif.accounts.count - 1)"))
|
|
|
|
.font(.body)
|
|
|
|
.scaledToFit()
|
|
|
|
.lineLimit(1)
|
|
|
|
.minimumScaleFactor(0.5)
|
|
|
|
.frame(width: 30, height: 30)
|
|
|
|
}
|
|
|
|
.frame(width: 40, height: 40)
|
|
|
|
.padding(7)
|
|
|
|
.background(Color.gray)
|
|
|
|
.clipShape(.circle)
|
|
|
|
.overlay {
|
|
|
|
Circle()
|
|
|
|
.stroke(Color.appBackground, lineWidth: 3)
|
|
|
|
}
|
|
|
|
.fixedSize()
|
|
|
|
}
|
2024-01-31 16:47:29 +01:00
|
|
|
}
|