Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Notifications Inbox Screen Implementation #113

Open
wants to merge 1 commit into
base: 2U/develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions Notifications/Notifications.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
149D4A9A2D0BEF7E003A2E1D /* NotificationsSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 149D4A992D0BEF7B003A2E1D /* NotificationsSettingsViewModel.swift */; };
14BAE6912D0978C300EAF0E4 /* NotificationsSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14BAE6902D0978BC00EAF0E4 /* NotificationsSettingsView.swift */; };
87E3F4AB2D8BE4FD628C91C4 /* Pods_App_Notifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CAFCD31A42C7E150939829CE /* Pods_App_Notifications.framework */; };
9704E8082D2BF8C500B28907 /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9704E8072D2BF8C100B28907 /* Notifications.swift */; };
978775242D19A20300D1C21E /* NotificationsInboxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 978775232D19A20300D1C21E /* NotificationsInboxView.swift */; };
978775262D19A21D00D1C21E /* NotificationsInboxViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 978775252D19A21D00D1C21E /* NotificationsInboxViewModel.swift */; };
97A222942D2404590067E6D2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97A222932D2404590067E6D2 /* Assets.xcassets */; };
97A222962D2415EA0067E6D2 /* Assets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97A222952D2415EA0067E6D2 /* Assets.swift */; };
97B079422D2BD59400538435 /* Data_Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97B079412D2BD58900538435 /* Data_Notifications.swift */; };
97B1F4332D2FBB5A00944213 /* AttributedText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97B1F4312D2FBB5A00944213 /* AttributedText.swift */; };
97B1F4342D2FBB5A00944213 /* HTML2TextParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97B1F4322D2FBB5A00944213 /* HTML2TextParser.swift */; };
FB43867C6484A90253882035 /* Pods_App_Notifications_NotificationsTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7FEAD4AF36405458BBBE5AB /* Pods_App_Notifications_NotificationsTests.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -66,6 +74,14 @@
7729007722CBCF0B8256DC02 /* Pods-App-Notifications.debugdev.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Notifications.debugdev.xcconfig"; path = "Target Support Files/Pods-App-Notifications/Pods-App-Notifications.debugdev.xcconfig"; sourceTree = "<group>"; };
7A8D523EE9F729312DE6718E /* Pods-App-Notifications.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Notifications.debug.xcconfig"; path = "Target Support Files/Pods-App-Notifications/Pods-App-Notifications.debug.xcconfig"; sourceTree = "<group>"; };
874E5747C9EC9E35C11CDA15 /* Pods-App-Notifications.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Notifications.release.xcconfig"; path = "Target Support Files/Pods-App-Notifications/Pods-App-Notifications.release.xcconfig"; sourceTree = "<group>"; };
9704E8072D2BF8C100B28907 /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
978775232D19A20300D1C21E /* NotificationsInboxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsInboxView.swift; sourceTree = "<group>"; };
978775252D19A21D00D1C21E /* NotificationsInboxViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsInboxViewModel.swift; sourceTree = "<group>"; };
97A222932D2404590067E6D2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97A222952D2415EA0067E6D2 /* Assets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assets.swift; sourceTree = "<group>"; };
97B079412D2BD58900538435 /* Data_Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data_Notifications.swift; sourceTree = "<group>"; };
97B1F4312D2FBB5A00944213 /* AttributedText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributedText.swift; sourceTree = "<group>"; };
97B1F4322D2FBB5A00944213 /* HTML2TextParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTML2TextParser.swift; sourceTree = "<group>"; };
9837AB207F25EDC411D2DC3F /* Pods-App-Notifications-NotificationsTests.debugprod.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Notifications-NotificationsTests.debugprod.xcconfig"; path = "Target Support Files/Pods-App-Notifications-NotificationsTests/Pods-App-Notifications-NotificationsTests.debugprod.xcconfig"; sourceTree = "<group>"; };
9BF6AF34619EAAF00A3FFD7A /* Pods-App-Notifications.debugprod.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Notifications.debugprod.xcconfig"; path = "Target Support Files/Pods-App-Notifications/Pods-App-Notifications.debugprod.xcconfig"; sourceTree = "<group>"; };
AA60551F3F53CDDD8E5E8DC5 /* Pods-App-Notifications-NotificationsTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Notifications-NotificationsTests.debug.xcconfig"; path = "Target Support Files/Pods-App-Notifications-NotificationsTests/Pods-App-Notifications-NotificationsTests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -138,6 +154,7 @@
0284DC0428D4996F00830893 /* Domain */ = {
isa = PBXGroup;
children = (
9704E8062D2BF8AA00B28907 /* Model */,
0283347628D499BC00C828FC /* NotificationsInteractor.swift */,
);
path = Domain;
Expand All @@ -147,6 +164,7 @@
isa = PBXGroup;
children = (
02EF39DB28D86BEF0058F6BD /* Strings.swift */,
97A222952D2415EA0067E6D2 /* Assets.swift */,
);
path = SwiftGen;
sourceTree = "<group>";
Expand All @@ -155,6 +173,8 @@
isa = PBXGroup;
children = (
1402A0C62B61011D00A0A00B /* Settings */,
978775222D19A06F00D1C21E /* NotificationsInbox */,
97B1F4302D2FBB4700944213 /* AttributedText */,
02F3BFDE29252F2F0051930C /* NotificationsRouter.swift */,
02F1752E2A4DA3B60019CD70 /* NotificationsAnalytics.swift */,
);
Expand Down Expand Up @@ -190,6 +210,7 @@
0284DC0428D4996F00830893 /* Domain */,
070019A228F6EF2700D5FC78 /* Presentation */,
02EF39D928D86A380058F6BD /* Localizable.strings */,
97A222932D2404590067E6D2 /* Assets.xcassets */,
);
path = Notifications;
sourceTree = "<group>";
Expand All @@ -209,16 +230,16 @@
1402A0C62B61011D00A0A00B /* Settings */ = {
isa = PBXGroup;
children = (
149D4A992D0BEF7B003A2E1D /* NotificationsSettingsViewModel.swift */,
14BAE6902D0978BC00EAF0E4 /* NotificationsSettingsView.swift */,
149D4A992D0BEF7B003A2E1D /* NotificationsSettingsViewModel.swift */,
);
path = Settings;
sourceTree = "<group>";
};
14116DAE2D1546AB00A30AE0 /* Model */ = {
isa = PBXGroup;
children = (
149D0E572D1D2EF600985307 /* NotificationsCount.swift */,
97B079412D2BD58900538435 /* Data_Notifications.swift */,
14116DB12D1546C300A30AE0 /* Data_NotificationsCount.swift */,
);
path = Model;
Expand Down Expand Up @@ -248,6 +269,33 @@
path = ../Pods;
sourceTree = "<group>";
};
9704E8062D2BF8AA00B28907 /* Model */ = {
isa = PBXGroup;
children = (
149D0E572D1D2EF600985307 /* NotificationsCount.swift */,
9704E8072D2BF8C100B28907 /* Notifications.swift */,
);
path = Model;
sourceTree = "<group>";
};
978775222D19A06F00D1C21E /* NotificationsInbox */ = {
isa = PBXGroup;
children = (
978775232D19A20300D1C21E /* NotificationsInboxView.swift */,
978775252D19A21D00D1C21E /* NotificationsInboxViewModel.swift */,
);
path = NotificationsInbox;
sourceTree = "<group>";
};
97B1F4302D2FBB4700944213 /* AttributedText */ = {
isa = PBXGroup;
children = (
97B1F4312D2FBB5A00944213 /* AttributedText.swift */,
97B1F4322D2FBB5A00944213 /* HTML2TextParser.swift */,
);
path = AttributedText;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -353,6 +401,7 @@
buildActionMask = 2147483647;
files = (
02EF39D128D867690058F6BD /* swiftgen.yml in Resources */,
97A222942D2404590067E6D2 /* Assets.xcassets in Resources */,
02EF39D728D86A380058F6BD /* Localizable.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -454,12 +503,19 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
97B079422D2BD59400538435 /* Data_Notifications.swift in Sources */,
14BAE6912D0978C300EAF0E4 /* NotificationsSettingsView.swift in Sources */,
0284DBFC28D4856A00830893 /* NotificationsEndpoint.swift in Sources */,
0283347728D499BC00C828FC /* NotificationsInteractor.swift in Sources */,
02F3BFDF29252F2F0051930C /* NotificationsRouter.swift in Sources */,
978775262D19A21D00D1C21E /* NotificationsInboxViewModel.swift in Sources */,
029737422949FB3B0051696B /* NotificationsPersistenceProtocol.swift in Sources */,
0284DC0328D4922900830893 /* NotificationsRepository.swift in Sources */,
9704E8082D2BF8C500B28907 /* Notifications.swift in Sources */,
978775242D19A20300D1C21E /* NotificationsInboxView.swift in Sources */,
97A222962D2415EA0067E6D2 /* Assets.swift in Sources */,
97B1F4332D2FBB5A00944213 /* AttributedText.swift in Sources */,
97B1F4342D2FBB5A00944213 /* HTML2TextParser.swift in Sources */,
02EF39DC28D86BEF0058F6BD /* Strings.swift in Sources */,
149D0E582D1D2EF600985307 /* NotificationsCount.swift in Sources */,
14116DB22D1546C300A30AE0 /* Data_NotificationsCount.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions Notifications/Notifications/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "discussions.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "three_dots_menu.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
147 changes: 147 additions & 0 deletions Notifications/Notifications/Data/Model/Data_Notifications.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
//
// Notifications.swift
// Notifications
//
// Created by Shafqat Muneer on 1/6/25.
//

import Foundation
import Core

public extension DataLayer {
struct Notifications: Codable {
public let next: String?
public let count: Int?
public let numPages: Int?
public let currentPage: Int?
public let start: Int?
public let results: [Notification]?

enum CodingKeys: String, CodingKey {
case next
case count
case numPages = "num_pages"
case currentPage = "current_page"
case start
case results
}

public init(
next: String?,
count: Int?,
numPages: Int?,
currentPage: Int?,
start: Int?,
results: [Notification]?
) {
self.next = next
self.count = count
self.numPages = numPages
self.currentPage = currentPage
self.start = start
self.results = results
}
}

struct Notification: Codable {
public let id: Int?
public let appName: String?
public let notificationType: String?
public let contentContext: ContentContext?
public let content: String?
public let lastRead: String?
public let lastSeen: String?
public let created: String

enum CodingKeys: String, CodingKey {
case id
case appName = "app_name"
case notificationType = "notification_type"
case contentContext = "content_context"
case content
case lastRead = "last_read"
case lastSeen = "last_seen"
case created
}

public init(
id: Int?,
appName: String?,
notificationType: String?,
contentContext: ContentContext?,
content: String?,
lastRead: String?,
lastSeen: String?,
created: String
) {
self.id = id
self.appName = appName
self.notificationType = notificationType
self.contentContext = contentContext
self.content = content
self.lastRead = lastRead
self.lastSeen = lastSeen
self.created = created
}
}

struct ContentContext: Codable {
public let topicId: String?
public let parentId: String?
public let threadId: String?
public let commentId: String?
public let postTitle: String?

enum CodingKeys: String, CodingKey {
case topicId = "topic_id"
case parentId = "parent_id"
case threadId = "thread_id"
case commentId = "comment_id"
case postTitle = "post_title"
}

public init(
topicId: String?,
parentId: String?,
threadId: String?,
commentId: String?,
postTitle: String?
) {
self.topicId = topicId
self.parentId = parentId
self.threadId = threadId
self.commentId = commentId
self.postTitle = postTitle
}
}
}

public extension DataLayer.Notifications {
var domain: Notifications {
Notifications(
next: next,
count: count,
numPages: numPages,
currentPage: currentPage,
start: start,
results: results?.compactMap { result in
Notification(
id: result.id,
appName: result.appName,
notificationType: result.notificationType,
contentContext: ContentContext(
topicId: result.contentContext?.topicId,
parentId: result.contentContext?.parentId,
threadId: result.contentContext?.threadId,
commentId: result.contentContext?.commentId,
postTitle: result.contentContext?.postTitle
),
content: result.content,
lastRead: result.lastRead.flatMap { Date(iso8601: $0) },
lastSeen: result.lastSeen.flatMap { Date(iso8601: $0) },
created: Date(iso8601: result.created)
)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ import Alamofire

enum NotificationsEndpoint: EndPointType {
case getNotificationsCount
case getAllNotifications(page: Int)

var path: String {
switch self {
case .getNotificationsCount:
"/api/notifications/count"
case .getAllNotifications:
"/api/notifications/"
}
}

var httpMethod: HTTPMethod {
switch self {
case .getNotificationsCount:
.get
.get
case .getAllNotifications:
.get
Comment on lines +28 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix indentations here

}
}

Expand All @@ -33,7 +38,15 @@ enum NotificationsEndpoint: EndPointType {
var task: HTTPTask {
switch self {
case .getNotificationsCount:
.request
return .request
case let .getAllNotifications(page):
var idiom: UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom }
let params: Parameters = [
"app_name": "discussion",
"page": page,
"page_size": idiom == .pad ? 24 : 12
]
return .requestParameters(parameters: params, encoding: URLEncoding.queryString)
}
}
}
Loading
Loading