Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

Update badge counter with all unread messages locally #460

Merged
merged 3 commits into from
May 11, 2017
Merged
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
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '9.0'
platform :ios, '10.0'
use_frameworks!

def shared_pods
Expand Down
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ SPEC CHECKSUMS:
TSMarkdownParser: 114779f14d46e7fc6d9880d4797e5abcc01f92c3
URBMediaFocusViewController: 26779e301fe75ec0152fbe8b476bd06ccee9f9b3

PODFILE CHECKSUM: 08c486ad1a09fa2a611b6c59c154048f4a82e16d
PODFILE CHECKSUM: f616230e4b79b25b8a4e0f0f93067849361aafc5

COCOAPODS: 1.2.1
8 changes: 6 additions & 2 deletions Rocket.Chat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = S6UPZG7ZR3;
INFOPLIST_FILE = Rocket.Chat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = chat.rocket.ios;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1562,7 +1562,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = S6UPZG7ZR3;
INFOPLIST_FILE = Rocket.Chat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = chat.rocket.ios;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1581,6 +1581,7 @@
DEVELOPMENT_TEAM = S6UPZG7ZR3;
ENABLE_BITCODE = YES;
INFOPLIST_FILE = Rocket.ChatTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "chat.rocket.Rocket-ChatTests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1599,6 +1600,7 @@
DEVELOPMENT_TEAM = S6UPZG7ZR3;
ENABLE_BITCODE = YES;
INFOPLIST_FILE = Rocket.ChatTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "chat.rocket.Rocket-ChatTests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1613,6 +1615,7 @@
buildSettings = {
DEVELOPMENT_TEAM = S6UPZG7ZR3;
INFOPLIST_FILE = Rocket.ChatUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "chat.rocket.Rocket-ChatUITests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1626,6 +1629,7 @@
buildSettings = {
DEVELOPMENT_TEAM = S6UPZG7ZR3;
INFOPLIST_FILE = Rocket.ChatUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "chat.rocket.Rocket-ChatUITests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
12 changes: 7 additions & 5 deletions Rocket.Chat/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit
import RealmSwift
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -17,14 +18,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Launcher().prepareToLaunch(with: launchOptions)

application.registerUserNotificationSettings(UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil))
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (_, _) in }
application.registerForRemoteNotifications()

return true
}

// MARK: AppDelegate LifeCycle

func applicationDidBecomeActive(_ application: UIApplication) {
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications()
}

func applicationDidEnterBackground(_ application: UIApplication) {
if AuthManager.isAuthenticated() != nil {
UserManager.setUserPresence(status: .away) { (_) in
Expand All @@ -43,10 +49,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// MARK: Remote Notification

func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
Log.debug("Notification: \(notification)")
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
Log.debug("Notification: \(userInfo)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ extension SubscriptionsViewController {
subscriptions = auth.subscriptions.sorted(byKeyPath: "lastSeen", ascending: false)
groupSubscription()
updateCurrentUserInformation()
SubscriptionManager.updateUnreadApplicationBadge()
tableView?.reloadData()
}

Expand Down
12 changes: 12 additions & 0 deletions Rocket.Chat/Managers/Model/SubscriptionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ import RealmSwift

struct SubscriptionManager {

static func updateUnreadApplicationBadge() {
var unread = 0

Realm.execute({ (realm) in
for obj in realm.objects(Subscription.self) {
unread += obj.unread
}
}, completion: {
UIApplication.shared.applicationIconBadgeNumber = unread
})
}

// swiftlint:disable function_body_length
static func updateSubscriptions(_ auth: Auth, completion: @escaping MessageCompletion) {
var params: [[String: Any]] = []
Expand Down