diff --git a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate
index d191c9f..6518c2a 100644
Binary files a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate and b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
index d3ff26d..eb86d1b 100644
--- a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -282,7 +282,9 @@
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "403"
- endingLineNumber = "403">
+ endingLineNumber = "403"
+ landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
+ landmarkType = "5">
+ endingLineNumber = "410"
+ landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
+ landmarkType = "5">
@@ -599,7 +603,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "313"
endingLineNumber = "313"
- landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
+ landmarkName = "listingHasEnded(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkType = "5">
@@ -615,7 +619,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "322"
endingLineNumber = "322"
- landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
+ landmarkName = "listingHasEnded(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkType = "5">
@@ -631,7 +635,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "335"
endingLineNumber = "335"
- landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
+ landmarkName = "listingHasEnded(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkType = "5">
diff --git a/Vendoo/HomeViewController.swift b/Vendoo/HomeViewController.swift
index f296422..a1326c5 100644
--- a/Vendoo/HomeViewController.swift
+++ b/Vendoo/HomeViewController.swift
@@ -232,21 +232,23 @@ extension HomeViewController: ServiceNotificationManagerDelegate {
}
if (ebayInfo != nil) {
- notificationArray.append(
- [
+ let notification = [
"network": "ebay",
"message": (ebayInfo as! [String : AnyObject])["notification"] as! String,
"type": (ebayInfo as! [String : AnyObject])["type"] as! String,
"seen":false,
"key": (ebayInfo as! [String : AnyObject])["listingKey"] as! String,
"UUID": NSUUID().UUIDString
- ]
+ ]
+
+ notificationArray.append(
+ notification as! [String : AnyObject]
)
self.endedListings.appendContentsOf( self.userListings.filter({$0.key == ((ebayInfo as! [String : AnyObject])["listingKey"] as! String)}))
self.userListings = self.userListings.filter({$0.key != ((ebayInfo as! [String : AnyObject])["listingKey"] as! String)})
let itemsView = self.viewControllers![0] as! ItemTableViewController
- self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)/user_Listings/\(((ebayInfo as! [String : AnyObject])["listingKey"] as! String))").observeSingleEventOfType( .Value, withBlock: {
+ /*self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)/user_Listings/\(((ebayInfo as! [String : AnyObject])["listingKey"] as! String))").observeSingleEventOfType( .Value, withBlock: {
(snapshot) -> Void in
var listingDict = snapshot.value as? [String : AnyObject]
@@ -254,7 +256,41 @@ extension HomeViewController: ServiceNotificationManagerDelegate {
self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)/user_Listings/\(((ebayInfo as! [String : AnyObject])["listingKey"] as! String))").setValue(listingDict)
itemsView.itemTable.reloadData()
+ })*/
+
+ self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)").observeSingleEventOfType( .Value, withBlock: {
+ (snapshot) -> Void in
+
+ var userDict = snapshot.value as? [String : AnyObject]
+ var notifications = userDict!["notifications"] as? [String: AnyObject]
+
+ if notifications == nil {
+ userDict!["notifications"] = [((ebayInfo as! [String : AnyObject])["listingKey"] as! String):notification]
+ }else {
+ notifications![((ebayInfo as! [String : AnyObject])["listingKey"] as! String)] = notification
+ userDict!["notifications"] = notifications
+ }
+
+ var listings = userDict!["user_Listings"] as! [String: AnyObject]
+ var listingDict = (listings[((ebayInfo as! [String : AnyObject])["listingKey"] as! String)] as! [String : AnyObject])
+ listingDict["listingStatus"] = "Ended"
+
+ //save everything back to their respective dictionaries
+ listings[((ebayInfo as! [String : AnyObject])["listingKey"] as! String)] = listingDict
+ userDict!["user_Listings"] = listings
+
+ self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)").setValue(userDict, withCompletionBlock: {
+ (error, reference) -> Void in
+
+ if error == nil {
+ //reload data for notifications
+ NSUserDefaults.standardUserDefaults().setObject(notificationArray, forKey: "notifications")
+ itemsView.itemTable.reloadData()
+ }
+ })
+
})
+
}
if (amazonInfo != nil) {
@@ -271,32 +307,52 @@ extension HomeViewController: ServiceNotificationManagerDelegate {
}
if (etsyInfo != nil) {
+ let notification = [
+ "network": "etsy",
+ "message": (etsyInfo as! [String : AnyObject])["notification"] as! String,
+ "type": "ended",
+ "seen":false,
+ "key": (etsyInfo as! [String : AnyObject])["listingKey"] as! String,
+ "UUID": NSUUID().UUIDString
+ ]
notificationArray.append(
- [
- "network": "etsy",
- "message": (etsyInfo as! [String : AnyObject])["notification"] as! String,
- "type": "ended",
- "seen":false,
- "key": (etsyInfo as! [String : AnyObject])["listingKey"] as! String,
- "UUID": NSUUID().UUIDString
- ]
+ notification as! [String : AnyObject]
)
self.endedListings.appendContentsOf( self.userListings.filter({$0.key == ((etsyInfo as! [String : AnyObject])["listingKey"] as! String)}))
self.userListings = self.userListings.filter({$0.key != ((etsyInfo as! [String : AnyObject])["listingKey"] as! String)})
let itemsView = self.viewControllers![0] as! ItemTableViewController
- self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)/user_Listings/\(((etsyInfo as! [String : AnyObject])["listingKey"] as! String))").observeSingleEventOfType( .Value, withBlock: {
+ self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)").observeSingleEventOfType( .Value, withBlock: {
(snapshot) -> Void in
- var listingDict = snapshot.value as? [String : AnyObject]
- listingDict!["listingStatus"] = "Ended"
- self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)/user_Listings/\(((etsyInfo as! [String : AnyObject])["listingKey"] as! String))").setValue(listingDict)
+ var userDict = snapshot.value as? [String : AnyObject]
+ var notifications = userDict!["notifications"] as? [String: AnyObject]
+ if notifications == nil {
+ userDict!["notifications"] = [((etsyInfo as! [String : AnyObject])["listingKey"] as! String):notification]
+ }else {
+ notifications![((etsyInfo as! [String : AnyObject])["listingKey"] as! String)] = notification
+ userDict!["notifications"] = notifications
+ }
+ var listings = userDict!["user_Listings"] as! [String: AnyObject]
+ var listingDict = (listings[((etsyInfo as! [String : AnyObject])["listingKey"] as! String)] as! [String : AnyObject])
+ listingDict["listingStatus"] = "Ended"
+
+ //save everything back to their respective dictionaries
+ listings[((etsyInfo as! [String : AnyObject])["listingKey"] as! String)] = listingDict
+ userDict!["user_Listings"] = listings
+
+ self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)").setValue(userDict, withCompletionBlock: {
+ (error, reference) -> Void in
+
+ if error == nil {
+ //reload data for notifications
+ NSUserDefaults.standardUserDefaults().setObject(notificationArray, forKey: "notifications")
+ itemsView.itemTable.reloadData()
+ }
+ })
- //reload data for notifications
- NSUserDefaults.standardUserDefaults().setObject(notificationArray, forKey: "notifications")
- itemsView.itemTable.reloadData()
})
}
diff --git a/Vendoo/NotificationsViewController.swift b/Vendoo/NotificationsViewController.swift
index 2f14ca2..e3ec6d3 100644
--- a/Vendoo/NotificationsViewController.swift
+++ b/Vendoo/NotificationsViewController.swift
@@ -68,8 +68,48 @@ extension NotificationsViewController: UITableViewDelegate {
self.presentViewController(alert, animated: true, completion: nil)
break
case "ebay":
+ let alert = UIAlertController(title: "New Notification", message: "Would you like to dismiss this notification?", preferredStyle: .Alert)
+ alert.addAction(UIAlertAction(title: "Mark as Dismissed", style: .Default, handler: {
+ (action) -> Void in
+
+ notification["seen"] = true
+ self.notifications[indexPath.row] = notification
+ self.fireBase.ref.child("Users/\(self.fireBase.user_email)/notifications/\(notification["UUID"] as! String)").setValue(notification, withCompletionBlock: {
+ (error, reference) -> Void in
+
+ if error == nil {
+ self.notifications = self.notifications.filter({$0["seen"] as! Bool == false})
+ NSUserDefaults.standardUserDefaults().setObject(self.notifications, forKey: "notifications")
+ self.notificationTable.reloadData()
+ alert.dismissViewControllerAnimated(true, completion: nil)
+ }
+ })
+
+ }))
+ alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: {(action) -> Void in}))
+ self.presentViewController(alert, animated: true, completion: nil)
break
case "etsy":
+ let alert = UIAlertController(title: "New Notification", message: "Would you like to dismiss this notification?", preferredStyle: .Alert)
+ alert.addAction(UIAlertAction(title: "Mark as Dismissed", style: .Default, handler: {
+ (action) -> Void in
+
+ notification["seen"] = true
+ self.notifications[indexPath.row] = notification
+ self.fireBase.ref.child("Users/\(self.fireBase.user_email)/notifications/\(notification["UUID"] as! String)").setValue(notification, withCompletionBlock: {
+ (error, reference) -> Void in
+
+ if error == nil {
+ self.notifications = self.notifications.filter({$0["seen"] as! Bool == false})
+ NSUserDefaults.standardUserDefaults().setObject(self.notifications, forKey: "notifications")
+ self.notificationTable.reloadData()
+ alert.dismissViewControllerAnimated(true, completion: nil)
+ }
+ })
+
+ }))
+ alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: {(action) -> Void in}))
+ self.presentViewController(alert, animated: true, completion: nil)
break
case "amazon":
break
@@ -85,16 +125,18 @@ extension NotificationsViewController: UITableViewDataSource {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: NotificationTableViewCell! = self.notificationTable.dequeueReusableCellWithIdentifier("notification_cell") as! NotificationTableViewCell
let notification = self.notifications[indexPath.row]
- cell.message.text = notification["notification"] as! String
switch ( notification["network"] as! String) {
case "facebook":
+ cell.message.text = notification["notification"] as! String
cell.network.image = UIImage(named: "facebook_icon")
break
case "ebay":
+ cell.message.text = notification["message"] as! String
cell.network.image = UIImage(named: "ebay_icon")
break
case "etsy":
+ cell.message.text = notification["message"] as! String
cell.network.image = UIImage(named: "etsy_icon")
break
case "amazon":