Skip to content

Commit

Permalink
Send and reply to private messages (#1530)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Andrews <[email protected]>
  • Loading branch information
Sjmarf and EricBAndrews authored Dec 25, 2024
1 parent 6efd898 commit df4a816
Show file tree
Hide file tree
Showing 21 changed files with 583 additions and 32 deletions.
28 changes: 26 additions & 2 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
0331715E2CCD6D95002DA370 /* ContentPurgeEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0331715D2CCD6D95002DA370 /* ContentPurgeEditorView.swift */; };
033171782CCE89E3002DA370 /* PurgableProviding+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033171772CCE89E3002DA370 /* PurgableProviding+Extensions.swift */; };
033EF4102CB9AEF7004D8A3F /* ExpandedPostView+Views.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033EF40F2CB9AEF7004D8A3F /* ExpandedPostView+Views.swift */; };
033F84492D18D1F400D87A9E /* MessageFeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033F84482D18D1F400D87A9E /* MessageFeedView.swift */; };
033F844D2D18D90900D87A9E /* MessageBubbleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033F844C2D18D90900D87A9E /* MessageBubbleView.swift */; };
033F844F2D196AC700D87A9E /* OptimalHeightLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033F844E2D196AC700D87A9E /* OptimalHeightLayout.swift */; };
033F84512D196AFD00D87A9E /* MessageFeedView+Logic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033F84502D196AFD00D87A9E /* MessageFeedView+Logic.swift */; };
033F84AD2C298466002E3EDF /* SectionIndexTitles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033F84AC2C298466002E3EDF /* SectionIndexTitles.swift */; };
033F84B12C29907F002E3EDF /* FeedbackType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033F84B02C29907F002E3EDF /* FeedbackType.swift */; };
033F84BB2C2ACB96002E3EDF /* CommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033F84BA2C2ACB96002E3EDF /* CommentView.swift */; };
Expand Down Expand Up @@ -505,6 +509,10 @@
0331715D2CCD6D95002DA370 /* ContentPurgeEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentPurgeEditorView.swift; sourceTree = "<group>"; };
033171772CCE89E3002DA370 /* PurgableProviding+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PurgableProviding+Extensions.swift"; sourceTree = "<group>"; };
033EF40F2CB9AEF7004D8A3F /* ExpandedPostView+Views.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ExpandedPostView+Views.swift"; sourceTree = "<group>"; };
033F84482D18D1F400D87A9E /* MessageFeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageFeedView.swift; sourceTree = "<group>"; };
033F844C2D18D90900D87A9E /* MessageBubbleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageBubbleView.swift; sourceTree = "<group>"; };
033F844E2D196AC700D87A9E /* OptimalHeightLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptimalHeightLayout.swift; sourceTree = "<group>"; };
033F84502D196AFD00D87A9E /* MessageFeedView+Logic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MessageFeedView+Logic.swift"; sourceTree = "<group>"; };
033F84AC2C298466002E3EDF /* SectionIndexTitles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionIndexTitles.swift; sourceTree = "<group>"; };
033F84B02C29907F002E3EDF /* FeedbackType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackType.swift; sourceTree = "<group>"; };
033F84BA2C2ACB96002E3EDF /* CommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -997,6 +1005,16 @@
path = Avatar;
sourceTree = "<group>";
};
033F844B2D18D8F400D87A9E /* MessageFeedView */ = {
isa = PBXGroup;
children = (
033F84482D18D1F400D87A9E /* MessageFeedView.swift */,
033F84502D196AFD00D87A9E /* MessageFeedView+Logic.swift */,
033F844C2D18D90900D87A9E /* MessageBubbleView.swift */,
);
path = MessageFeedView;
sourceTree = "<group>";
};
033F84C62C2B192F002E3EDF /* MlemStats */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1160,6 +1178,7 @@
CDD99C3B2C73F3FF0010367F /* DeleteAccountView.swift */,
03B25B3A2CC44FFF00EB6DF5 /* UploadConfirmationView.swift */,
03E46AD12D130681002589DB /* VotesListView.swift */,
033F844B2D18D8F400D87A9E /* MessageFeedView */,
);
name = Pages;
path = Mlem/App/Views/Pages;
Expand Down Expand Up @@ -1591,6 +1610,7 @@
CD635E1A2C94DACD00864F75 /* BypassProxyWarningSheet.swift */,
03AB484E2CBAE33500567FF9 /* MarkdownWithLinkList.swift */,
037DE0792CE108D9007F7B92 /* FooterLinkView.swift */,
033F844E2D196AC700D87A9E /* OptimalHeightLayout.swift */,
);
path = Shared;
sourceTree = "<group>";
Expand Down Expand Up @@ -2243,6 +2263,7 @@
03AB484F2CBAE33500567FF9 /* MarkdownWithLinkList.swift in Sources */,
03531EF12C2DA298004A3464 /* SearchResultsView.swift in Sources */,
034B94852C09348400039AF4 /* MarkdownImageView.swift in Sources */,
033F84512D196AFD00D87A9E /* MessageFeedView+Logic.swift in Sources */,
CD9CFA2A2C2E1E8400739BBC /* FeedHeaderView.swift in Sources */,
CDB41E8E2C84CFA200BD2DE9 /* FixedImageView.swift in Sources */,
033F84C12C2AD072002E3EDF /* CommentWrapper.swift in Sources */,
Expand Down Expand Up @@ -2285,6 +2306,7 @@
CD1446212A5B328E00610EF1 /* Privacy Policy.swift in Sources */,
03AFD0E32C3C0C540054B8AD /* InstanceView.swift in Sources */,
CDD4A09C2C8A122F0001AD1A /* CodableSettings.swift in Sources */,
033F844F2D196AC700D87A9E /* OptimalHeightLayout.swift in Sources */,
03ECD7212C8654BA00D48BF6 /* PostEditorView+Toolbar.swift in Sources */,
033EF4102CB9AEF7004D8A3F /* ExpandedPostView+Views.swift in Sources */,
03FE140C2BF953B000A8377F /* HandleError.swift in Sources */,
Expand Down Expand Up @@ -2404,6 +2426,7 @@
CDB2EC8A2BFAEFDF00DBC0EF /* ThumbnailImageView.swift in Sources */,
0397D4932C6CE87E002C6CDC /* PostEditorTargetView.swift in Sources */,
034690992D105DFD0073E664 /* InboxView+Types.swift in Sources */,
033F84492D18D1F400D87A9E /* MessageFeedView.swift in Sources */,
030050D52D10AE30002B1E99 /* Report+Extensions.swift in Sources */,
CD57AFA32D03761500AB3956 /* WebpView.swift in Sources */,
0369B3562BFA6824001EFEDF /* InboxView.swift in Sources */,
Expand Down Expand Up @@ -2451,6 +2474,7 @@
033F84BF2C2ACC9F002E3EDF /* Comment1Providing+Extensions.swift in Sources */,
0369B35D2BFB86E3001EFEDF /* Account.swift in Sources */,
036CC3AF2B8145C30098B6A1 /* AppState.swift in Sources */,
033F844D2D18D90900D87A9E /* MessageBubbleView.swift in Sources */,
03134A502BEAD245002662CC /* NavigationLink+NavigationPage.swift in Sources */,
03B431BC2C455838001A1EB5 /* LargePostBodyView.swift in Sources */,
CDFB8C692C7796020070845F /* View+DynamicBlur.swift in Sources */,
Expand Down Expand Up @@ -2998,8 +3022,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/mlemgroup/MlemMiddleware";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.56.0;
kind = upToNextMinorVersion;
minimumVersion = 0.57.0;
};
};
CD64A9182CA37D63007CA7E6 /* XCRemoteSwiftPackageReference "Gifu" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/mlemgroup/MlemMiddleware",
"state" : {
"revision" : "064dbc65be21977113207067c563155ee859f485",
"version" : "0.56.0"
"revision" : "da33c0b616559921a8dd895c843aaf8abf2d85db",
"version" : "0.57.0"
}
},
{
Expand Down
10 changes: 5 additions & 5 deletions Mlem/App/Globals/Definitions/FiltersTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Created by Eric Andrews on 2024-12-22.
//

import Observation
import Dependencies
import Foundation
import MlemMiddleware
import Observation

@Observable
class FiltersTracker {
Expand All @@ -30,13 +30,13 @@ class FiltersTracker {
init() {
@Dependency(\.persistenceRepository) var persistenceRepository

isAdmin = AppState.main.firstPerson?.isAdmin ?? false
moderatedCommunityActorIds = AppState.main.firstPerson?.moderatedCommunityActorIds ?? .init()
filteredKeywords = persistenceRepository.loadFilteredKeywords()
self.isAdmin = AppState.main.firstPerson?.isAdmin ?? false
self.moderatedCommunityActorIds = AppState.main.firstPerson?.moderatedCommunityActorIds ?? .init()
self.filteredKeywords = persistenceRepository.loadFilteredKeywords()
}

func postWouldBeFiltered(_ post: any Post) -> Bool {
return post.title.lowercased().containsWordsIn(filteredKeywords)
post.title.lowercased().containsWordsIn(filteredKeywords)
}

static var main: FiltersTracker = .init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ extension Message1Providing {
@ActionBuilder
func allMenuActions(
feedback: Set<FeedbackType> = [.haptic, .toast],
isInMessageFeed: Bool = false,
navigation: NavigationLayer? = nil,
report: Report? = nil
) -> [any Action] {
basicMenuActions(feedback: feedback)
basicMenuActions(
feedback: feedback,
isInMessageFeed: isInMessageFeed,
navigation: navigation
)
if api.isAdmin {
ActionGroup(
appearance: .init(label: "Moderation...", color: Palette.main.moderation, icon: Icons.moderation),
Expand All @@ -42,10 +48,14 @@ extension Message1Providing {
@ActionBuilder
func basicMenuActions(
feedback: Set<FeedbackType> = [.haptic, .toast],
isInMessageFeed: Bool = false,
navigation: NavigationLayer? = nil,
report: Report? = nil
) -> [any Action] {
if !isOwnMessage {
replyAction()
if let navigation, !isInMessageFeed {
replyAction(navigation: navigation)
}
markReadAction(feedback: feedback)
}
if !deleted {
Expand All @@ -57,7 +67,9 @@ extension Message1Providing {
if report == nil {
reportAction()
}
blockCreatorAction(feedback: feedback)
if !isInMessageFeed {
blockCreatorAction(feedback: feedback)
}
}
}

Expand All @@ -75,11 +87,15 @@ extension Message1Providing {

// These actions are also defined in Interactable1Providing... another protocol for these may be a good idea

func replyAction() -> BasicAction {
.init(
func replyAction(navigation: NavigationLayer) -> BasicAction {
var callback: (() -> Void)?
if let creator = creator_, api.canInteract {
callback = { navigation.push(.messageFeed(creator, focusTextField: true)) }
}
return .init(
id: "reply\(uid)",
appearance: .reply(),
callback: nil
callback: callback
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ extension Person1Providing {
@ActionBuilder
func menuActions(
feedback: Set<FeedbackType> = [.haptic, .toast],
isInMessageFeed: Bool = false,
navigation: NavigationLayer?,
community: (any Community)?
) -> [any Action] {
Expand All @@ -99,6 +100,9 @@ extension Person1Providing {
copyNameAction()
shareAction()
if (AppState.main.firstSession as? UserSession)?.person?.person1 !== person1 {
if !isInMessageFeed {
sendMessageAction()
}
blockAction(feedback: feedback)
}
}
Expand All @@ -118,6 +122,14 @@ extension Person1Providing {
)
}

func sendMessageAction() -> BasicAction {
.init(
id: "sendMessage\(uid)",
appearance: .init(label: "Send Message", color: Palette.main.accent, icon: Icons.message),
callback: { NavigationModel.main.openSheet(.messageFeed(self, focusTextField: true)) }
)
}

func banActions(community: (any Community)?, withUserLabel: Bool = false) -> [any Action] {
let isModerator: Bool
let showBoth: Bool
Expand Down
23 changes: 23 additions & 0 deletions Mlem/App/Utility/Extensions/Date+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,27 @@ extension Date {
let current = calendar.dateComponents([.month, .day, .year], from: .now)
return date.month == current.month && date.day == current.day && date.year != current.year
}

// https://stackoverflow.com/a/48652058/17629371
func messagesRelativeDate() -> String {
let dateFormatter = DateFormatter()
let calendar = Calendar(identifier: .gregorian)
dateFormatter.doesRelativeDateFormatting = true

if calendar.isDateInToday(self) {
dateFormatter.timeStyle = .short
dateFormatter.dateStyle = .medium
} else if calendar.isDateInYesterday(self) {
dateFormatter.timeStyle = .short
dateFormatter.dateStyle = .medium
} else if calendar.compare(Date(), to: self, toGranularity: .weekOfYear) == .orderedSame {
let weekday = calendar.dateComponents([.weekday], from: self).weekday ?? 0
return dateFormatter.weekdaySymbols[weekday - 1]
} else {
dateFormatter.timeStyle = .none
dateFormatter.dateStyle = .short
}

return dateFormatter.string(from: self)
}
}
12 changes: 12 additions & 0 deletions Mlem/App/Utility/Extensions/MarkdownConfiguration+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ extension MarkdownConfiguration {
font: .caption1,
codeFontScaleFactor: 0.9
) }

static var inverted: MarkdownConfiguration { .init(
inlineImageLoader: loadInlineImage,
imageBlockView: { imageView($0, shouldBlur: false) },
wrapCodeBlockLines: Settings.main.wrapCodeBlockLines,
primaryColor: Palette.main.selectedInteractionBarItem,
secondaryColor: Palette.main.selectedInteractionBarItem.opacity(0.8),
spoilerHeaderBackgroundColor: Palette.main.selectedInteractionBarItem.opacity(0.1),
spoilerOutlineColor: Palette.main.selectedInteractionBarItem.opacity(0.5),
codeBackgroundColor: Palette.main.selectedInteractionBarItem.opacity(0.1),
codeFontScaleFactor: 0.9
) }
}

private func imageView(_ inlineImage: InlineImage, shouldBlur: Bool) -> AnyView {
Expand Down
2 changes: 1 addition & 1 deletion Mlem/App/Views/Pages/Community/CommunityView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Created by Sjmarf on 30/07/2024.
//

import Dependencies
import LemmyMarkdownUI
import MlemMiddleware
import SwiftUI
import Dependencies

struct CommunityView: View {
enum Tab: String, CaseIterable, Identifiable {
Expand Down
Loading

0 comments on commit df4a816

Please sign in to comment.