Skip to content

Commit

Permalink
Fixed some inbox problems, tweaked haptics (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews authored Nov 9, 2023
1 parent 5f888cf commit b91d4e5
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 90 deletions.
28 changes: 14 additions & 14 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
CD863FBA2A6AEB5900A31ED9 /* TabSafeScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD863FB92A6AEB5900A31ED9 /* TabSafeScrollView.swift */; };
CD863FBC2A6B026400A31ED9 /* DocumentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD863FBB2A6B026400A31ED9 /* DocumentView.swift */; };
CD8C55342A95515C0060B75B /* Onboarding Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD8C55332A95515C0060B75B /* Onboarding Text.swift */; };
CD8CF2092AF3F131009FFC23 /* Firm Info.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CD8CF2082AF3F131009FFC23 /* Firm Info.ahap */; };
CD9DD8832A622A6C0044EA8E /* ReportCommentReply.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9DD8822A622A6C0044EA8E /* ReportCommentReply.swift */; };
CD9DD8852A62302A0044EA8E /* ConcreteEditorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9DD8842A62302A0044EA8E /* ConcreteEditorModel.swift */; };
CDA145ED2A510AC100DDAFC9 /* MarkCommentReplyAsReadRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA145EC2A510AC100DDAFC9 /* MarkCommentReplyAsReadRequest.swift */; };
Expand All @@ -417,12 +418,12 @@
CDA2C5262A705D6000649D5A /* PostEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA2C5252A705D6000649D5A /* PostEditor.swift */; };
CDB0117D2A6F703800D043EB /* CommentEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB0117C2A6F703800D043EB /* CommentEditor.swift */; };
CDB0117F2A6F70A000D043EB /* Editor Tracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB0117E2A6F70A000D043EB /* Editor Tracker.swift */; };
CDB45C5A2AF0AEFE00A1FF08 /* AlternativeIconLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB45C592AF0AEFE00A1FF08 /* AlternativeIconLabel.swift */; };
CDB45C5C2AF1A1D800A1FF08 /* CoreTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB45C5B2AF1A1D800A1FF08 /* CoreTracker.swift */; };
CDB45C5E2AF1A96C00A1FF08 /* AssociatedColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB45C5D2AF1A96C00A1FF08 /* AssociatedColor.swift */; };
CDB45C602AF1AF4900A1FF08 /* MentionModel+TrackerItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB45C5F2AF1AF4900A1FF08 /* MentionModel+TrackerItem.swift */; };
CDB45C622AF1AF9B00A1FF08 /* ReplyModel+TrackerItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB45C612AF1AF9B00A1FF08 /* ReplyModel+TrackerItem.swift */; };
CDB45C642AF1AFB900A1FF08 /* MessageModel+TrackerItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB45C632AF1AFB900A1FF08 /* MessageModel+TrackerItem.swift */; };
CDB45C5A2AF0AEFE00A1FF08 /* AlternativeIconLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB45C592AF0AEFE00A1FF08 /* AlternativeIconLabel.swift */; };
CDC1C93C2A7AA76000072E3D /* InternetSpeed.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC1C93B2A7AA76000072E3D /* InternetSpeed.swift */; };
CDC1C93F2A7AB8C700072E3D /* AccessibilitySettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC1C93E2A7AB8C700072E3D /* AccessibilitySettingsView.swift */; };
CDC1C9412A7ABA9C00072E3D /* ReadMarkStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC1C9402A7ABA9C00072E3D /* ReadMarkStyle.swift */; };
Expand Down Expand Up @@ -454,11 +455,10 @@
CDE6A81A2A490B970062D161 /* Inbox Reply View.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE6A8192A490B970062D161 /* Inbox Reply View.swift */; };
CDE9CE4C2A7B0831002B97DD /* Gentle Info.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE4B2A7B0831002B97DD /* Gentle Info.ahap */; };
CDE9CE4F2A7B0B1B002B97DD /* Haptic.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE9CE4E2A7B0B1B002B97DD /* Haptic.swift */; };
CDE9CE512A7B0C66002B97DD /* Firmer Info.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE502A7B0C66002B97DD /* Firmer Info.ahap */; };
CDE9CE512A7B0C66002B97DD /* Light Success.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE502A7B0C66002B97DD /* Light Success.ahap */; };
CDE9CE532A7B1100002B97DD /* Mushy Info.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE522A7B1100002B97DD /* Mushy Info.ahap */; };
CDE9CE572A7B11FD002B97DD /* Rigid Info.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE562A7B11FD002B97DD /* Rigid Info.ahap */; };
CDE9CE5D2A7B2290002B97DD /* Gentle Success.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE5C2A7B2290002B97DD /* Gentle Success.ahap */; };
CDE9CE5F2A7B3197002B97DD /* Success.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE5E2A7B3197002B97DD /* Success.ahap */; };
CDE9CE5D2A7B2290002B97DD /* Success.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE5C2A7B2290002B97DD /* Success.ahap */; };
CDE9CE612A7B32EB002B97DD /* Destructive Success.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE602A7B32EB002B97DD /* Destructive Success.ahap */; };
CDE9CE652A7B338E002B97DD /* Violent Success.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE642A7B338E002B97DD /* Violent Success.ahap */; };
CDE9CE682A7B3481002B97DD /* Failure.ahap in Resources */ = {isa = PBXBuildFile; fileRef = CDE9CE672A7B3481002B97DD /* Failure.ahap */; };
Expand Down Expand Up @@ -910,6 +910,7 @@
CD863FB92A6AEB5900A31ED9 /* TabSafeScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabSafeScrollView.swift; sourceTree = "<group>"; };
CD863FBB2A6B026400A31ED9 /* DocumentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentView.swift; sourceTree = "<group>"; };
CD8C55332A95515C0060B75B /* Onboarding Text.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Onboarding Text.swift"; sourceTree = "<group>"; };
CD8CF2082AF3F131009FFC23 /* Firm Info.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Firm Info.ahap"; sourceTree = "<group>"; };
CD9DD8822A622A6C0044EA8E /* ReportCommentReply.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportCommentReply.swift; sourceTree = "<group>"; };
CD9DD8842A62302A0044EA8E /* ConcreteEditorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConcreteEditorModel.swift; sourceTree = "<group>"; };
CDA145EC2A510AC100DDAFC9 /* MarkCommentReplyAsReadRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkCommentReplyAsReadRequest.swift; sourceTree = "<group>"; };
Expand All @@ -922,12 +923,12 @@
CDA2C5252A705D6000649D5A /* PostEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostEditor.swift; sourceTree = "<group>"; };
CDB0117C2A6F703800D043EB /* CommentEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentEditor.swift; sourceTree = "<group>"; };
CDB0117E2A6F70A000D043EB /* Editor Tracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Editor Tracker.swift"; sourceTree = "<group>"; };
CDB45C592AF0AEFE00A1FF08 /* AlternativeIconLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlternativeIconLabel.swift; sourceTree = "<group>"; };
CDB45C5B2AF1A1D800A1FF08 /* CoreTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreTracker.swift; sourceTree = "<group>"; };
CDB45C5D2AF1A96C00A1FF08 /* AssociatedColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssociatedColor.swift; sourceTree = "<group>"; };
CDB45C5F2AF1AF4900A1FF08 /* MentionModel+TrackerItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MentionModel+TrackerItem.swift"; sourceTree = "<group>"; };
CDB45C612AF1AF9B00A1FF08 /* ReplyModel+TrackerItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ReplyModel+TrackerItem.swift"; sourceTree = "<group>"; };
CDB45C632AF1AFB900A1FF08 /* MessageModel+TrackerItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MessageModel+TrackerItem.swift"; sourceTree = "<group>"; };
CDB45C592AF0AEFE00A1FF08 /* AlternativeIconLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlternativeIconLabel.swift; sourceTree = "<group>"; };
CDC1C93B2A7AA76000072E3D /* InternetSpeed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InternetSpeed.swift; sourceTree = "<group>"; };
CDC1C93E2A7AB8C700072E3D /* AccessibilitySettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilitySettingsView.swift; sourceTree = "<group>"; };
CDC1C9402A7ABA9C00072E3D /* ReadMarkStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadMarkStyle.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -959,11 +960,10 @@
CDE6A8192A490B970062D161 /* Inbox Reply View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Inbox Reply View.swift"; sourceTree = "<group>"; };
CDE9CE4B2A7B0831002B97DD /* Gentle Info.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Gentle Info.ahap"; sourceTree = "<group>"; };
CDE9CE4E2A7B0B1B002B97DD /* Haptic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Haptic.swift; sourceTree = "<group>"; };
CDE9CE502A7B0C66002B97DD /* Firmer Info.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Firmer Info.ahap"; sourceTree = "<group>"; };
CDE9CE502A7B0C66002B97DD /* Light Success.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Light Success.ahap"; sourceTree = "<group>"; };
CDE9CE522A7B1100002B97DD /* Mushy Info.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Mushy Info.ahap"; sourceTree = "<group>"; };
CDE9CE562A7B11FD002B97DD /* Rigid Info.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Rigid Info.ahap"; sourceTree = "<group>"; };
CDE9CE5C2A7B2290002B97DD /* Gentle Success.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Gentle Success.ahap"; sourceTree = "<group>"; };
CDE9CE5E2A7B3197002B97DD /* Success.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = Success.ahap; sourceTree = "<group>"; };
CDE9CE5C2A7B2290002B97DD /* Success.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = Success.ahap; sourceTree = "<group>"; };
CDE9CE602A7B32EB002B97DD /* Destructive Success.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Destructive Success.ahap"; sourceTree = "<group>"; };
CDE9CE642A7B338E002B97DD /* Violent Success.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Violent Success.ahap"; sourceTree = "<group>"; };
CDE9CE672A7B3481002B97DD /* Failure.ahap */ = {isa = PBXFileReference; lastKnownFileType = text; path = Failure.ahap; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2426,7 +2426,7 @@
isa = PBXGroup;
children = (
CDE9CE4B2A7B0831002B97DD /* Gentle Info.ahap */,
CDE9CE502A7B0C66002B97DD /* Firmer Info.ahap */,
CD8CF2082AF3F131009FFC23 /* Firm Info.ahap */,
CDE9CE522A7B1100002B97DD /* Mushy Info.ahap */,
CDE9CE562A7B11FD002B97DD /* Rigid Info.ahap */,
);
Expand All @@ -2436,8 +2436,8 @@
CDE9CE592A7B2264002B97DD /* Success */ = {
isa = PBXGroup;
children = (
CDE9CE5C2A7B2290002B97DD /* Gentle Success.ahap */,
CDE9CE5E2A7B3197002B97DD /* Success.ahap */,
CDE9CE502A7B0C66002B97DD /* Light Success.ahap */,
CDE9CE5C2A7B2290002B97DD /* Success.ahap */,
CDE9CE602A7B32EB002B97DD /* Destructive Success.ahap */,
CDE9CE642A7B338E002B97DD /* Violent Success.ahap */,
);
Expand Down Expand Up @@ -2682,13 +2682,13 @@
files = (
6363D5CC27EE196A00E34822 /* Preview Assets.xcassets in Resources */,
CDE9CE4C2A7B0831002B97DD /* Gentle Info.ahap in Resources */,
CD8CF2092AF3F131009FFC23 /* Firm Info.ahap in Resources */,
CDE9CE572A7B11FD002B97DD /* Rigid Info.ahap in Resources */,
CDE9CE5D2A7B2290002B97DD /* Gentle Success.ahap in Resources */,
CDE9CE5D2A7B2290002B97DD /* Success.ahap in Resources */,
CDE9CE682A7B3481002B97DD /* Failure.ahap in Resources */,
50CC4A702A9BD2480074C845 /* instance_metadata.json in Resources */,
CDE9CE652A7B338E002B97DD /* Violent Success.ahap in Resources */,
CDE9CE512A7B0C66002B97DD /* Firmer Info.ahap in Resources */,
CDE9CE5F2A7B3197002B97DD /* Success.ahap in Resources */,
CDE9CE512A7B0C66002B97DD /* Light Success.ahap in Resources */,
CDE9CE532A7B1100002B97DD /* Mushy Info.ahap in Resources */,
CDE9CE612A7B32EB002B97DD /* Destructive Success.ahap in Resources */,
6332FDBD27EFAF7C0009A98A /* Settings.bundle in Resources */,
Expand Down
14 changes: 7 additions & 7 deletions Mlem/Enums/Haptic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ enum Haptic: String {
/// Very gentle tap. Used for subtle feedback--things like crossing a swipe boundary
case gentleInfo = "Gentle Info"

/// Firmer tap. Used for slightly less subtle feedback
case firmerInfo = "Firmer Info"
/// Slightly firmer tap. Used for less subtle feedback--crossing a second swipe boundary, dropping a widget
case firmInfo = "Firm Info"

/// Mushy, gentle tap. Used for extremely subtle feedback
case mushyInfo = "Mushy Info"

/// Rigid tap. Used for subtle feedback on "clickier" things
case rigidInfo = "Rigid Info"

/// Success notification for events that don't need a heavy haptic--votes, saves, etc
/// NOTE: this is a gentleInfo and a firmerInfo played in quick succession
case gentleSuccess = "Gentle Success"
/// Success notification for extremely common, low-priority successes--dropping a widget, upvoting a post
case lightSuccess = "Light Success"

/// Standard success notification for rarer, more significant events like posting a post or comment
/// Standard success notification
/// NOTE: this is a gentleInfo and a firmerInfo played in quick succession
case success = "Success"

/// Success notification for destructive events like unsubscribing or deleting
Expand Down
6 changes: 3 additions & 3 deletions Mlem/Extensions/Swipey Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ struct SwipeyView: ViewModifier {
if previousIndex == nil {
return (.gentleInfo, .high)
} else if previousIndex == 1 {
return (.firmerInfo, .high)
return (.firmInfo, .high)
} else {
return (.firmerInfo, .high)
return (.firmInfo, .high)
}
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ extension View {
@ViewBuilder
func addSwipeyActions(_ configuration: SwipeConfiguration) -> some View {
modifier(
SwipeyView(configuration: configuration)
SwipeyView(configuration: configuration)
)
}
}
21 changes: 21 additions & 0 deletions Mlem/Haptics/Info/Firm Info.ahap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"Version": 1,
"Pattern": [
{
"Event": {
"Time": 0,
"EventType": "HapticTransient",
"EventParameters": [
{
"ParameterID": "HapticIntensity",
"ParameterValue": 0.6
},
{
"ParameterID": "HapticSharpness",
"ParameterValue": 0.75
}
]
}
}
]
}
37 changes: 0 additions & 37 deletions Mlem/Haptics/Success/Gentle Success.ahap

This file was deleted.

File renamed without changes.
11 changes: 5 additions & 6 deletions Mlem/Haptics/Success/Success.ahap
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"Version": 1,
"Pattern": [
Expand All @@ -9,27 +8,27 @@
"EventParameters": [
{
"ParameterID": "HapticIntensity",
"ParameterValue": 0.9
"ParameterValue": 0.45
},
{
"ParameterID": "HapticSharpness",
"ParameterValue": 0.6
"ParameterValue": 0.55
}
]
}
},
{
"Event": {
"Time": 0.2,
"Time": 0.1,
"EventType": "HapticTransient",
"EventParameters": [
{
"ParameterID": "HapticIntensity",
"ParameterValue": 0.7
"ParameterValue": 0.75
},
{
"ParameterID": "HapticSharpness",
"ParameterValue": 0.8
"ParameterValue": 0.9
}
]
}
Expand Down
7 changes: 3 additions & 4 deletions Mlem/Models/Content/Inbox/MentionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension MentionModel {
voting = true
defer { voting = false }

hapticManager.play(haptic: .gentleSuccess, priority: .low)
hapticManager.play(haptic: .lightSuccess, priority: .low)
let operation = votes.myVote == inputOp ? ScoringOperation.resetVote : inputOp

let original: MentionModel = .init(from: self)
Expand All @@ -138,24 +138,23 @@ extension MentionModel {
}

func toggleRead(unreadTracker: UnreadTracker) async {
hapticManager.play(haptic: .gentleSuccess, priority: .low)
hapticManager.play(haptic: .lightSuccess, priority: .low)

// store original state
let originalPersonMention = APIPersonMention(from: personMention)

// state fake
await setPersonMention(APIPersonMention(from: personMention, read: !personMention.read))
await unreadTracker.toggleMentionRead(originalState: originalPersonMention.read)

// call API and either update with latest info or revert state fake on fail
do {
let newMessage = try await inboxRepository.markMentionRead(id: personMention.id, isRead: personMention.read)
await unreadTracker.toggleMentionRead(originalState: originalPersonMention.read)
await reinit(from: newMessage)
} catch {
hapticManager.play(haptic: .failure, priority: .high)
errorHandler.handle(error)
await setPersonMention(originalPersonMention)
await unreadTracker.toggleMentionRead(originalState: !originalPersonMention.read)
}
}

Expand Down
5 changes: 2 additions & 3 deletions Mlem/Models/Content/Inbox/MessageModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,23 @@ class MessageModel: ContentIdentifiable, ObservableObject {
}

func toggleRead(unreadTracker: UnreadTracker) async {
hapticManager.play(haptic: .gentleSuccess, priority: .low)
hapticManager.play(haptic: .lightSuccess, priority: .low)

// store original state
let originalPrivateMessage = privateMessage

// state fake
await setPrivateMessage(APIPrivateMessage(from: privateMessage, read: !privateMessage.read))
await unreadTracker.toggleMessageRead(originalState: originalPrivateMessage.read)

// call API and either update with latest info or revert state fake on fail
do {
let newMessage = try await inboxRepository.markMessageRead(id: privateMessage.id, isRead: privateMessage.read)
await unreadTracker.toggleMessageRead(originalState: originalPrivateMessage.read)
await reinit(from: newMessage)
} catch {
hapticManager.play(haptic: .failure, priority: .high)
errorHandler.handle(error)
await setPrivateMessage(originalPrivateMessage)
await unreadTracker.toggleMessageRead(originalState: !originalPrivateMessage.read)
}
}

Expand Down
Loading

0 comments on commit b91d4e5

Please sign in to comment.