Skip to content

Commit

Permalink
fixed posts not showing in profile (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews authored and boscojwho committed Nov 23, 2023
1 parent b53a78e commit f19cebc
Show file tree
Hide file tree
Showing 70 changed files with 2,949 additions and 1,547 deletions.
193 changes: 158 additions & 35 deletions Mlem.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
"version" : "12.1.4"
}
},
{
"identity" : "semaphore",
"kind" : "remoteSourceControl",
"location" : "https://github.com/groue/Semaphore",
"state" : {
"revision" : "f1c4a0acabeb591068dea6cffdd39660b86dec28",
"version" : "0.0.8"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
Expand Down
7 changes: 7 additions & 0 deletions Mlem/API/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,19 @@ extension APIClient {
return try await perform(request: request).privateMessageReportView
}

@available(*, deprecated, message: "Use id-based sendPrivateMessage instead")
@discardableResult
func sendPrivateMessage(content: String, recipient: APIPerson) async throws -> PrivateMessageResponse {
let request = try CreatePrivateMessageRequest(session: session, content: content, recipient: recipient)
return try await perform(request: request)
}

@discardableResult
func sendPrivateMessage(content: String, recipientId: Int) async throws -> PrivateMessageResponse {
let request = try CreatePrivateMessageRequest(session: session, content: content, recipientId: recipientId)
return try await perform(request: request)
}

func markPrivateMessageRead(id: Int, isRead: Bool) async throws -> APIPrivateMessageView {
let request = try MarkPrivateMessageAsRead(session: session, privateMessageId: id, read: isRead)
return try await perform(request: request).privateMessageView
Expand Down
15 changes: 15 additions & 0 deletions Mlem/API/Models/Comments/APICommentReply.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,19 @@ struct APICommentReply: Decodable {
let commentId: Int
let read: Bool
let published: Date

init(
from commentReply: APICommentReply,
id: Int? = nil,
recipientId: Int? = nil,
commentId: Int? = nil,
read: Bool? = nil,
published: Date? = nil
) {
self.id = id ?? commentReply.id
self.recipientId = recipientId ?? commentReply.recipientId
self.commentId = commentId ?? commentReply.commentId
self.read = read ?? commentReply.read
self.published = published ?? commentReply.published
}
}
15 changes: 15 additions & 0 deletions Mlem/API/Models/Messages/APIPrivateMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@ struct APIPrivateMessage: Decodable {
let updated: Date?
let published: Date
let deleted: Bool

init(
from apiPrivateMessage: APIPrivateMessage,
read: Bool? = nil
) {
self.id = apiPrivateMessage.id
self.content = apiPrivateMessage.content
self.creatorId = apiPrivateMessage.creatorId
self.recipientId = apiPrivateMessage.recipientId
self.local = apiPrivateMessage.local
self.read = read ?? apiPrivateMessage.read
self.updated = apiPrivateMessage.updated
self.published = apiPrivateMessage.published
self.deleted = apiPrivateMessage.deleted
}
}
25 changes: 24 additions & 1 deletion Mlem/API/Models/Person/APIPersonMention.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,33 @@ struct APIPersonMention: Decodable {
let commentId: Int
let read: Bool
let published: Date

init(
from personMention: APIPersonMention,
id: Int? = nil,
recipientId: Int? = nil,
commentId: Int? = nil,
read: Bool? = nil,
published: Date? = nil
) {
self.id = id ?? personMention.id
self.recipientId = recipientId ?? personMention.recipientId
self.commentId = commentId ?? personMention.commentId
self.read = read ?? personMention.read
self.published = published ?? personMention.published
}
}

extension APIPersonMention: Hashable {
func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(read)
hasher.combine(published)
}
}

extension APIPersonMention: Equatable {
static func == (lhs: APIPersonMention, rhs: APIPersonMention) -> Bool {
lhs.id == rhs.id
lhs.hashValue == rhs.hashValue
}
}
11 changes: 11 additions & 0 deletions Mlem/API/Models/ScoringOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@
//

import Foundation
import SwiftUI

enum ScoringOperation: Int, Decodable {
case upvote = 1
case downvote = -1
case resetVote = 0
}

extension ScoringOperation: AssociatedColor {
var color: Color? {
switch self {
case .upvote: return .upvoteColor
case .downvote: return .downvoteColor
case .resetVote: return nil
}
}
}

extension ScoringOperation: AssociatedIcon {
var iconName: String {
switch self {
Expand Down
10 changes: 10 additions & 0 deletions Mlem/API/Requests/Messages/CreatePrivateMessageRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ struct CreatePrivateMessageRequest: APIPostRequest {
let recipient_id: Int
}

init(
session: APISession,
content: String,
recipientId: Int
) throws {
self.instanceURL = try session.instanceUrl
self.body = try .init(auth: session.token, content: content, recipient_id: recipientId)
}

@available(*, deprecated, message: "Use id-based initializer instead")
init(
session: APISession,
content: String,
Expand Down
2 changes: 2 additions & 0 deletions Mlem/App Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ struct AppConstants {

static let blockUserPrompt: String = "Really block this user?"
static let reportPostPrompt: String = "Really report this post?"
static let reportCommentPrompt: String = "Really report this comment?"
static let reportMessagePrompt: String = "Really report this message?"
}
19 changes: 19 additions & 0 deletions Mlem/Dependency/InboxRepository+Dependency.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// InboxRepository+Dependency.swift
// Mlem
//
// Created by Eric Andrews on 2023-09-23.
//
import Dependencies
import Foundation

extension InboxRepository: DependencyKey {
static let liveValue = InboxRepository()
}

extension DependencyValues {
var inboxRepository: InboxRepository {
get { self[InboxRepository.self] }
set { self[InboxRepository.self] = newValue }
}
}
2 changes: 1 addition & 1 deletion Mlem/Enums/Content Type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import Foundation

enum ContentType: Int, Codable {
case post, comment, community, user
case post, comment, community, user, message, mention, reply
}
12 changes: 12 additions & 0 deletions Mlem/Enums/ContentIdentifiable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// ContentIdentifiable.swift
// Mlem
//
// Created by Eric Andrews on 2023-10-14.
//
import Foundation

// TODO: migrate this to be ContentModel and make subtypes of ContentModel for content with URLs, etc.
protocol ContentIdentifiable {
var uid: ContentModelIdentifier { get }
}
25 changes: 0 additions & 25 deletions Mlem/Enums/Inbox Item Type.swift

This file was deleted.

15 changes: 15 additions & 0 deletions Mlem/Enums/LoadingState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// LoadingState.swift
// Mlem
//
// Created by Eric Andrews on 2023-10-12.
//
import Foundation

/// Enum of possible loading states that a tracker can be in.
/// - idle: not currently loading, but more items available to load
/// - loading: currently loading more items
/// - done: no more items available to load
enum LoadingState {
case idle, loading, done
}
13 changes: 13 additions & 0 deletions Mlem/Extensions/AssociatedColor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// AssociatedColor.swift
// Mlem
//
// Created by Eric Andrews on 2023-10-31.
//

import Foundation
import SwiftUI

protocol AssociatedColor {
var color: Color? { get }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// MentionModel+InboxItem.swift
// Mlem
//
// Created by Eric Andrews on 2023-10-20.
//

import Foundation

extension MentionModel: InboxItem {
typealias ParentType = AnyInboxItem

var published: Date { personMention.published }

var creatorId: Int { comment.creatorId }

var read: Bool { personMention.read }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MessageModel+InboxItem.swift
// Mlem
//
// Created by Eric Andrews on 2023-10-16.
//
import Foundation

extension MessageModel: InboxItem {
typealias ParentType = AnyInboxItem

var published: Date { privateMessage.published }

var creatorId: Int { privateMessage.creatorId }

var read: Bool { privateMessage.read }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ReplyModel+InboxItem.swift
// Mlem
//
// Created by Eric Andrews on 2023-10-16.
//
import Foundation

extension ReplyModel: InboxItem {
typealias ParentType = AnyInboxItem

var published: Date { commentReply.published }

var creatorId: Int { comment.creatorId }

var read: Bool { commentReply.read }
}
17 changes: 17 additions & 0 deletions Mlem/Extensions/Tracker Items/MentionModel+TrackerItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MentionModel+TrackerItem.swift
// Mlem
//
// Created by Eric Andrews on 2023-10-31.
//

import Foundation

extension MentionModel: TrackerItem {
func sortVal(sortType: TrackerSortType) -> TrackerSortVal {
switch sortType {
case .published:
return .published(personMention.published)
}
}
}
17 changes: 17 additions & 0 deletions Mlem/Extensions/Tracker Items/MessageModel+TrackerItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MessageModel+TrackerItem.swift
// Mlem
//
// Created by Eric Andrews on 2023-10-31.
//

import Foundation

extension MessageModel: TrackerItem {
func sortVal(sortType: TrackerSortType) -> TrackerSortVal {
switch sortType {
case .published:
return .published(privateMessage.published)
}
}
}
17 changes: 17 additions & 0 deletions Mlem/Extensions/Tracker Items/ReplyModel+TrackerItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ReplyModel+TrackerItem.swift
// Mlem
//
// Created by Eric Andrews on 2023-10-31.
//

import Foundation

extension ReplyModel: TrackerItem {
func sortVal(sortType: TrackerSortType) -> TrackerSortVal {
switch sortType {
case .published:
return .published(commentReply.published)
}
}
}
9 changes: 6 additions & 3 deletions Mlem/Icons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ struct Icons {
static let unsaveFill: String = "bookmark.slash.fill"

// mark read
static let markRead: String = "envelope"
static let markRead: String = "envelope.open"
static let markReadFill: String = "envelope.open.fill"
static let markUnread: String = "envelope.open"
static let markUnread: String = "envelope"
static let markUnreadFill: String = "envelope.fill"

// moderation
Expand Down Expand Up @@ -124,7 +124,6 @@ struct Icons {
static let hide: String = "eye.slash"
static let show: String = "eye"
static let blurNsfw: String = "eye.trianglebadge.exclamationmark"
static let endOfFeed: String = "figure.climbing"
static let noContent: String = "binoculars"
static let noPosts: String = "text.bubble"
static let time: String = "clock"
Expand All @@ -134,6 +133,10 @@ struct Icons {
static let personFill: String = "person.fill"
static let close: String = "multiply"

// end of feed
static let endOfFeedHobbit: String = "figure.climbing"
static let endOfFeedCartoon: String = "figure.wave"

// common operations
static let share: String = "square.and.arrow.up"
static let subscribe: String = "plus.circle"
Expand Down
Loading

0 comments on commit f19cebc

Please sign in to comment.