Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLIBZ-2213 Subscribe to user's personal collection channel #172

Merged
merged 3 commits into from
Jan 10, 2018
Merged
Changes from 1 commit
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
18 changes: 16 additions & 2 deletions packages/kinvey-live/src/collection/live-collection-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class LiveCollectionManager {
return this._makeSubscriptionRequest(name, '_subscribe')
.then(() => {
const channelName = this._buildChannelName(name);
getLiveService().subscribeToChannel(channelName, receiver);
const personalChannelName = this._buildPersonalChannelName(name);
const liveService = getLiveService();
liveService.subscribeToChannel(channelName, receiver);
liveService.subscribeToChannel(personalChannelName, receiver);
});
}

Expand All @@ -35,7 +38,10 @@ class LiveCollectionManager {
return this._makeSubscriptionRequest(name, '_unsubscribe')
.then(() => {
const channelName = this._buildChannelName(name);
getLiveService().unsubscribeFromChannel(channelName);
const personalChannelName = this._buildPersonalChannelName(name);
const liveService = getLiveService();
liveService.unsubscribeFromChannel(channelName);
liveService.unsubscribeFromChannel(personalChannelName);
});
}

Expand All @@ -48,6 +54,12 @@ class LiveCollectionManager {
return `${this._client.appKey}.c-${collectionName}`;
}

_buildPersonalChannelName(collectionName) {
const channelName = this._buildChannelName(collectionName);
const userId = this._client.getActiveUser()._id;
return `${channelName}.u-${userId}`;
}

/**
* @private
* @param {string} collectionName
Expand All @@ -61,6 +73,7 @@ class LiveCollectionManager {
});
}
}

exports.LiveCollectionManager = LiveCollectionManager;

/** @type {LiveCollectionManager} */
Expand All @@ -75,4 +88,5 @@ function getLiveCollectionManager(client) {
}
return managerInstance;
}

exports.getLiveCollectionManager = getLiveCollectionManager;