Skip to content

Commit

Permalink
Reducing repeated status notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Tsochantaris authored and Paul Tsochantaris committed Mar 10, 2015
1 parent 916701f commit ad6b0fb
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 16 deletions.
4 changes: 2 additions & 2 deletions MobileTrailer/PocketTrailer-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.2</string>
<string>1.2.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1187</string>
<string>1188</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIBackgroundModes</key>
Expand Down
16 changes: 13 additions & 3 deletions Shared/DataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,32 @@ class DataManager : NSObject {
c.postSyncAction = PostSyncAction.DoNothing.rawValue
}

var latestStatuses = PRStatus.newItemsOfType("PRStatus", inMoc: mainObjectContext) as [PRStatus]
if(Settings.notifyOnStatusUpdates) {
var latestStatuses = PRStatus.newItemsOfType("PRStatus", inMoc: mainObjectContext) as [PRStatus]
let coveredPrs = NSMutableSet()
for s in latestStatuses {
if Settings.notifyOnStatusUpdatesForAllPrs || s.pullRequest.isMine() {
let pr = s.pullRequest
if !coveredPrs.containsObject(pr) {
if let s = pr.displayedStatuses().first {
app.postNotificationOfType(PRNotificationType.NewStatus, forItem: s)
}
let displayText = s.displayText()
if pr.lastStatusNotified != displayText && pr.postSyncAction?.integerValue != PostSyncAction.NoteNew.rawValue {
app.postNotificationOfType(PRNotificationType.NewStatus, forItem: s)
pr.lastStatusNotified = displayText
}
} else {
pr.lastStatusNotified = nil
}
coveredPrs.addObject(pr)
}
}
}
}

for s in latestStatuses {
s.postSyncAction = PostSyncAction.DoNothing.rawValue
}

for p in allTouchedPrs {
p.postSyncAction = PostSyncAction.DoNothing.rawValue
}
Expand Down
1 change: 1 addition & 0 deletions Shared/PullRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class PullRequest: DataItem {
@NSManaged var userId: NSNumber?
@NSManaged var userLogin: String?
@NSManaged var webUrl: String?
@NSManaged var lastStatusNotified: String?

@NSManaged var comments: NSSet
@NSManaged var labels: NSSet
Expand Down
2 changes: 1 addition & 1 deletion Shared/Trailer.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>Trailer 19.xcdatamodel</string>
<string>Trailer 20.xcdatamodel</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions Shared/Trailer.xcdatamodeld/Trailer 19.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6254" systemVersion="14B25" minimumToolsVersion="Xcode 4.5" macOSVersion="Automatic" iOSVersion="Automatic">
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6751" systemVersion="14C1510" minimumToolsVersion="Xcode 4.5" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="ApiServer" representedClassName="ApiServer" syncable="YES">
<attribute name="apiPath" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="authToken" optional="YES" attributeType="String" syncable="YES"/>
Expand Down Expand Up @@ -134,7 +134,7 @@
<element name="PRComment" positionX="0" positionY="0" width="128" height="253"/>
<element name="PRLabel" positionX="9" positionY="153" width="128" height="178"/>
<element name="PRStatus" positionX="0" positionY="0" width="128" height="223"/>
<element name="PullRequest" positionX="0" positionY="0" width="128" height="523"/>
<element name="PullRequest" positionX="0" positionY="0" width="128" height="525"/>
<element name="Repo" positionX="0" positionY="0" width="128" height="240"/>
</elements>
</model>
141 changes: 141 additions & 0 deletions Shared/Trailer.xcdatamodeld/Trailer 20.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6751" systemVersion="14C1510" minimumToolsVersion="Xcode 4.5" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="ApiServer" representedClassName="ApiServer" syncable="YES">
<attribute name="apiPath" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="authToken" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="createdAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="label" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="lastSyncSucceeded" optional="YES" attributeType="Boolean" defaultValueString="YES" syncable="YES"/>
<attribute name="latestReceivedEventDateProcessed" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="latestReceivedEventEtag" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="latestUserEventDateProcessed" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="latestUserEventEtag" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="reportRefreshFailures" attributeType="Boolean" defaultValueString="YES" syncable="YES"/>
<attribute name="requestsLimit" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="requestsRemaining" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="resetDate" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="userId" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="userName" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="webPath" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="comments" toMany="YES" deletionRule="Cascade" destinationEntity="PRComment" inverseName="apiServer" inverseEntity="PRComment" syncable="YES"/>
<relationship name="labels" toMany="YES" deletionRule="Cascade" destinationEntity="PRLabel" inverseName="apiServer" inverseEntity="PRLabel" syncable="YES"/>
<relationship name="pullRequests" toMany="YES" deletionRule="Cascade" destinationEntity="PullRequest" inverseName="apiServer" inverseEntity="PullRequest" syncable="YES"/>
<relationship name="repos" toMany="YES" deletionRule="Cascade" destinationEntity="Repo" inverseName="apiServer" inverseEntity="Repo" syncable="YES"/>
<relationship name="statuses" toMany="YES" deletionRule="Cascade" destinationEntity="PRStatus" inverseName="apiServer" inverseEntity="PRStatus" syncable="YES"/>
</entity>
<entity name="PRComment" representedClassName="PRComment" syncable="YES">
<attribute name="avatarUrl" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="body" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="createdAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="path" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="position" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="postSyncAction" optional="YES" attributeType="Integer 16" indexed="YES" syncable="YES"/>
<attribute name="serverId" optional="YES" attributeType="Integer 64" defaultValueString="0" indexed="YES" syncable="YES"/>
<attribute name="updatedAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="url" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="userId" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="userName" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="webUrl" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="apiServer" maxCount="1" deletionRule="Nullify" destinationEntity="ApiServer" inverseName="comments" inverseEntity="ApiServer" syncable="YES"/>
<relationship name="pullRequest" maxCount="1" deletionRule="Nullify" destinationEntity="PullRequest" inverseName="comments" inverseEntity="PullRequest" syncable="YES"/>
</entity>
<entity name="PRLabel" representedClassName="PRLabel" syncable="YES">
<attribute name="color" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
<attribute name="createdAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="postSyncAction" optional="YES" attributeType="Integer 16" indexed="YES" syncable="YES"/>
<attribute name="serverId" optional="YES" attributeType="Integer 64" defaultValueString="0" indexed="YES" syncable="YES"/>
<attribute name="updatedAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="url" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="apiServer" maxCount="1" deletionRule="Nullify" destinationEntity="ApiServer" inverseName="labels" inverseEntity="ApiServer" syncable="YES"/>
<relationship name="pullRequest" maxCount="1" deletionRule="Nullify" destinationEntity="PullRequest" inverseName="labels" inverseEntity="PullRequest" syncable="YES"/>
</entity>
<entity name="PRStatus" representedClassName="PRStatus" syncable="YES">
<attribute name="createdAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="descriptionText" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="postSyncAction" optional="YES" attributeType="Integer 16" indexed="YES" syncable="YES"/>
<attribute name="serverId" optional="YES" attributeType="Integer 64" defaultValueString="0" indexed="YES" syncable="YES"/>
<attribute name="state" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="targetUrl" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="updatedAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="url" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="userId" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="userName" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="apiServer" maxCount="1" deletionRule="Nullify" destinationEntity="ApiServer" inverseName="statuses" inverseEntity="ApiServer" syncable="YES"/>
<relationship name="pullRequest" maxCount="1" deletionRule="Nullify" destinationEntity="PullRequest" inverseName="statuses" inverseEntity="PullRequest" syncable="YES"/>
</entity>
<entity name="PullRequest" representedClassName="PullRequest" syncable="YES">
<attribute name="assignedToMe" optional="YES" attributeType="Boolean" syncable="YES"/>
<attribute name="body" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="condition" optional="YES" attributeType="Integer 16" defaultValueString="0" indexed="YES" syncable="YES"/>
<attribute name="createdAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="isNewAssignment" optional="YES" attributeType="Boolean" syncable="YES"/>
<attribute name="issueCommentLink" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="issueUrl" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="lastStatusNotified" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="latestReadCommentDate" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="mergeable" optional="YES" attributeType="Boolean" syncable="YES"/>
<attribute name="number" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="pinned" optional="YES" attributeType="Boolean" defaultValueString="NO" syncable="YES"/>
<attribute name="postSyncAction" optional="YES" attributeType="Integer 16" indexed="YES" syncable="YES"/>
<attribute name="reopened" optional="YES" attributeType="Boolean" syncable="YES"/>
<attribute name="reviewCommentLink" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="sectionIndex" optional="YES" attributeType="Integer 16" defaultValueString="0" syncable="YES"/>
<attribute name="serverId" optional="YES" attributeType="Integer 64" defaultValueString="0" indexed="YES" syncable="YES"/>
<attribute name="state" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="statusesLink" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="title" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="totalComments" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="unreadComments" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="updatedAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="url" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="userAvatarUrl" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="userId" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="userLogin" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="webUrl" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="apiServer" maxCount="1" deletionRule="Nullify" destinationEntity="ApiServer" inverseName="pullRequests" inverseEntity="ApiServer" syncable="YES"/>
<relationship name="comments" toMany="YES" deletionRule="Cascade" destinationEntity="PRComment" inverseName="pullRequest" inverseEntity="PRComment" syncable="YES"/>
<relationship name="labels" toMany="YES" deletionRule="Cascade" destinationEntity="PRLabel" inverseName="pullRequest" inverseEntity="PRLabel" syncable="YES"/>
<relationship name="repo" maxCount="1" deletionRule="Nullify" destinationEntity="Repo" inverseName="pullRequests" inverseEntity="Repo" syncable="YES"/>
<relationship name="statuses" toMany="YES" deletionRule="Cascade" destinationEntity="PRStatus" inverseName="pullRequest" inverseEntity="PRStatus" syncable="YES"/>
<compoundIndexes>
<compoundIndex>
<index value="postSyncAction"/>
<index value="condition"/>
</compoundIndex>
</compoundIndexes>
</entity>
<entity name="Repo" representedClassName="Repo" syncable="YES">
<attribute name="createdAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="dirty" optional="YES" attributeType="Boolean" indexed="YES" syncable="YES"/>
<attribute name="fork" optional="YES" attributeType="Boolean" syncable="YES"/>
<attribute name="fullName" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="hidden" attributeType="Boolean" defaultValueString="NO" indexed="YES" syncable="YES"/>
<attribute name="inaccessible" optional="YES" attributeType="Boolean" syncable="YES"/>
<attribute name="lastDirtied" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="postSyncAction" optional="YES" attributeType="Integer 16" indexed="YES" syncable="YES"/>
<attribute name="serverId" optional="YES" attributeType="Integer 64" defaultValueString="0" indexed="YES" syncable="YES"/>
<attribute name="updatedAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="webUrl" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="apiServer" maxCount="1" deletionRule="Nullify" destinationEntity="ApiServer" inverseName="repos" inverseEntity="ApiServer" syncable="YES"/>
<relationship name="pullRequests" toMany="YES" deletionRule="Cascade" destinationEntity="PullRequest" inverseName="repo" inverseEntity="PullRequest" syncable="YES"/>
<compoundIndexes>
<compoundIndex>
<index value="dirty"/>
<index value="hidden"/>
</compoundIndex>
<compoundIndex>
<index value="dirty"/>
<index value="lastDirtied"/>
</compoundIndex>
</compoundIndexes>
</entity>
<elements>
<element name="ApiServer" positionX="9" positionY="153" width="128" height="358"/>
<element name="PRComment" positionX="0" positionY="0" width="128" height="253"/>
<element name="PRLabel" positionX="9" positionY="153" width="128" height="178"/>
<element name="PRStatus" positionX="0" positionY="0" width="128" height="223"/>
<element name="PullRequest" positionX="0" positionY="0" width="128" height="540"/>
<element name="Repo" positionX="0" positionY="0" width="128" height="240"/>
</elements>
</model>
4 changes: 3 additions & 1 deletion Trailer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
1628A6CA18789E73005EDA69 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
1628A6D518789E73005EDA69 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
162A29D81A4085FD008F41A9 /* API.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = API.swift; path = Shared/API.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
163D1F7F1AAFA54800E080D7 /* Trailer 20.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Trailer 20.xcdatamodel"; sourceTree = "<group>"; };
164785A91A2CE7BD00297764 /* Globals.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = Globals.swift; path = Shared/Globals.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
164785AC1A2CE7CD00297764 /* NSDictionaryExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NSDictionaryExtensions.swift; path = Shared/NSDictionaryExtensions.swift; sourceTree = "<group>"; };
164785AD1A2CE7CD00297764 /* NSStringExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NSStringExtensions.swift; path = Shared/NSStringExtensions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -814,6 +815,7 @@
16B3B33B1A34E990000BE6CC /* Trailer.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
163D1F7F1AAFA54800E080D7 /* Trailer 20.xcdatamodel */,
16B3B33C1A34E990000BE6CC /* Trailer 10.xcdatamodel */,
16B3B33D1A34E990000BE6CC /* Trailer 11.xcdatamodel */,
16B3B33E1A34E990000BE6CC /* Trailer 12.xcdatamodel */,
Expand All @@ -834,7 +836,7 @@
16B3B34D1A34E990000BE6CC /* Trailer 9.xcdatamodel */,
16B3B34E1A34E990000BE6CC /* Trailer.xcdatamodel */,
);
currentVersion = 16B3B3451A34E990000BE6CC /* Trailer 19.xcdatamodel */;
currentVersion = 163D1F7F1AAFA54800E080D7 /* Trailer 20.xcdatamodel */;
name = Trailer.xcdatamodeld;
path = ../Shared/Trailer.xcdatamodeld;
sourceTree = "<group>";
Expand Down
Loading

0 comments on commit ad6b0fb

Please sign in to comment.