Skip to content

Commit 05215fb

Browse files
greenimpalabrowniefed
authored andcommitted
add WINDOW_DID_SHOW_NOTIFICATION event (#251)
1 parent e5c81d1 commit 05215fb

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ _onUnreadChange = ({ count }) => {
281281
```javascript
282282
// The window was hidden
283283
Intercom.Notifications.WINDOW_DID_HIDE
284+
285+
// The window was shown
286+
Intercom.Notifications.WINDOW_DID_SHOW
284287
```
285288
286289
### Send FCM token directly to Intercom for push notifications (Android only)

iOS/IntercomEventEmitter.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,29 @@ - (void)handleWindowDidHideNotification:(NSNotification *)notification {
3232
});
3333
}
3434

35+
- (void)handleWindowDidShowNotification:(NSNotification *)notification {
36+
__weak IntercomEventEmitter *weakSelf = self;
37+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
38+
IntercomEventEmitter *strongSelf = weakSelf;
39+
[strongSelf sendEventWithName:IntercomWindowDidShowNotification body:@"Window Was Shown"];
40+
});
41+
}
42+
3543
- (NSDictionary<NSString *, NSString *> *)constantsToExport {
3644
return @{@"UNREAD_CHANGE_NOTIFICATION": IntercomUnreadConversationCountDidChangeNotification,
37-
@"WINDOW_DID_HIDE_NOTIFICATION": IntercomWindowDidHideNotification};
45+
@"WINDOW_DID_HIDE_NOTIFICATION": IntercomWindowDidHideNotification,
46+
@"WINDOW_DID_SHOW_NOTIFICATION": IntercomWindowDidShowNotification
47+
};
3848
}
3949

4050
- (NSArray<NSString *> *)supportedEvents {
41-
return @[IntercomUnreadConversationCountDidChangeNotification, IntercomWindowDidHideNotification];
51+
return @[IntercomUnreadConversationCountDidChangeNotification, IntercomWindowDidHideNotification, IntercomWindowDidShowNotification];
4252
}
4353

4454
-(void)startObserving {
4555
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUpdateUnreadCount:) name:IntercomUnreadConversationCountDidChangeNotification object:nil];
4656
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleWindowDidHideNotification:) name:IntercomWindowDidHideNotification object:nil];
57+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleWindowDidShowNotification:) name:IntercomWindowDidShowNotification object:nil];
4758
}
4859

4960
- (void)stopObserving {

lib/IntercomClient.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class IntercomClient {
1616

1717
Notifications = {
1818
UNREAD_COUNT: IntercomEventEmitter.UNREAD_CHANGE_NOTIFICATION,
19-
WINDOW_DID_HIDE: IntercomEventEmitter.WINDOW_DID_HIDE_NOTIFICATION
19+
WINDOW_DID_HIDE: IntercomEventEmitter.WINDOW_DID_HIDE_NOTIFICATION,
20+
WINDOW_DID_SHOW: IntercomEventEmitter.WINDOW_DID_SHOW_NOTIFICATION
2021
};
2122

2223
_eventEmitter;
@@ -27,7 +28,8 @@ class IntercomClient {
2728
constructor() {
2829
this._eventHandlers = {
2930
[IntercomEventEmitter.UNREAD_CHANGE_NOTIFICATION]: new Map(),
30-
[IntercomEventEmitter.WINDOW_DID_HIDE_NOTIFICATION]: new Map()
31+
[IntercomEventEmitter.WINDOW_DID_HIDE_NOTIFICATION]: new Map(),
32+
[IntercomEventEmitter.WINDOW_DID_SHOW_NOTIFICATION]: new Map()
3133
};
3234

3335
// the first item in the chain needs to be a succesfull promise

0 commit comments

Comments
 (0)