Skip to content

Commit

Permalink
Deprecate -[PTPusher unsubscribeFromChannel] in favour of
Browse files Browse the repository at this point in the history
-[PTPusherChannel unsubscribe]. Closes #43.
  • Loading branch information
lukeredpath committed Apr 26, 2012
1 parent 8924d6a commit 1f38510
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Library/PTPusher.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ extern NSString *const PTPusherErrorUnderlyingEventKey;

/** Unsubscribes from the specified channel.
This method is deprecated. You should use -[PTPusherChannel unsubscribe] instead.
@param channel The channel to unsubscribe from.
*/
- (void)unsubscribeFromChannel:(PTPusherChannel *)channel;
- (void)unsubscribeFromChannel:(PTPusherChannel *)channel __PUSHER_DEPRECATED__;

/** Returns a previously subscribed channel with the given name.
Expand Down
17 changes: 15 additions & 2 deletions Library/PTPusher.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,27 @@ - (PTPusherChannel *)channelNamed:(NSString *)name
return [channels objectForKey:name];
}

- (void)unsubscribeFromChannel:(PTPusherChannel *)channel
- (void)__unsubscribeFromChannel:(PTPusherChannel *)channel
{
NSParameterAssert(channel != nil);

[channel unsubscribe];
[self sendEventNamed:@"pusher:unsubscribe"
data:[NSDictionary dictionaryWithObject:channel.name forKey:@"channel"]];

[channel markAsUnsubscribed];

if ([self.delegate respondsToSelector:@selector(pusher:didUnsubscribeFromChannel:)]) {
[self.delegate pusher:self didUnsubscribeFromChannel:channel];
}

[channels removeObjectForKey:channel.name];
}

- (void)unsubscribeFromChannel:(PTPusherChannel *)channel
{
[self __unsubscribeFromChannel:channel];
}

- (void)subscribeToChannel:(PTPusherChannel *)channel
{
[channel authorizeWithCompletionHandler:^(BOOL isAuthorized, NSDictionary *authData, NSError *underlyingError) {
Expand Down
8 changes: 8 additions & 0 deletions Library/PTPusherChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@

- (void)authorizeWithCompletionHandler:(void(^)(BOOL, NSDictionary *, NSError *))completionHandler;

///------------------------------------------------------------------------------------/
/// @name Unsubscribing
///------------------------------------------------------------------------------------/

/** Unsubscribes from the channel.
*/
- (void)unsubscribe;

@end

/** A PTPusherPrivateChannel object represents a private Pusher channel.
Expand Down
14 changes: 5 additions & 9 deletions Library/PTPusherChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#import "PTPusherChannelAuthorizationOperation.h"
#import "PTPusherErrors.h"

@interface PTPusher ()
- (void)__unsubscribeFromChannel:(PTPusherChannel *)channel;
@end

@interface PTPusherChannel ()
@property (nonatomic, assign, readwrite) BOOL subscribed;
Expand Down Expand Up @@ -150,15 +153,7 @@ - (void)subscribeWithAuthorization:(NSDictionary *)authData

- (void)unsubscribe
{
[pusher sendEventNamed:@"pusher:unsubscribe"
data:[NSDictionary dictionaryWithObject:self.name forKey:@"channel"]
channel:nil];

self.subscribed = NO;

if ([pusher.delegate respondsToSelector:@selector(pusher:didUnsubscribeFromChannel:)]) {
[pusher.delegate pusher:pusher didUnsubscribeFromChannel:self];
}
[pusher __unsubscribeFromChannel:self];
}

- (void)markAsUnsubscribed
Expand Down Expand Up @@ -211,6 +206,7 @@ - (void)subscribeWithAuthorization:(NSDictionary *)authData

NSMutableDictionary *eventData = [authData mutableCopy];
[eventData setObject:self.name forKey:@"channel"];

[pusher sendEventNamed:@"pusher:subscribe"
data:eventData
channel:nil];
Expand Down

1 comment on commit 1f38510

@soffes
Copy link

@soffes soffes commented on 1f38510 Apr 28, 2012

Choose a reason for hiding this comment

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

:D thanks!

Please sign in to comment.