Added full support for ebay and etsy limited notifications

This commit is contained in:
Okechi Onyeje 2016-11-10 21:21:09 -05:00
parent 9861802bb5
commit aa2c54afd8
4 changed files with 128 additions and 26 deletions

View File

@ -282,7 +282,9 @@
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "403"
endingLineNumber = "403">
endingLineNumber = "403"
landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
@ -296,7 +298,9 @@
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "410"
endingLineNumber = "410">
endingLineNumber = "410"
landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
@ -583,7 +587,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "310"
endingLineNumber = "310"
landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkName = "listingHasEnded(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
@ -599,7 +603,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "313"
endingLineNumber = "313"
landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkName = "listingHasEnded(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
@ -615,7 +619,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "322"
endingLineNumber = "322"
landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkName = "listingHasEnded(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
@ -631,7 +635,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "335"
endingLineNumber = "335"
landmarkName = "listingHasNewNotifications(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkName = "listingHasEnded(_:ebayInfo:amazonInfo:etsyInfo:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>

View File

@ -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()
})
}

View File

@ -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":