Remove the concept of keys; they can just be encoded into subject names.

This commit is contained in:
Ian Gulliver
2014-05-25 23:50:53 -07:00
parent 8e7af2f5cf
commit 898121dabd
5 changed files with 24 additions and 146 deletions

View File

@@ -132,9 +132,8 @@ Cosmopolite.prototype.shutdown = function() {
* @param {!*} subject Subject name or object
* @param {number=} messages Number of recent messages to request; 0 for none, -1 for all
* @param {number=} last_id ID of last message received; fetch all messages since
* @param {Array.<string>=} keys Key names to ensure we receive at least 1 message defining
*/
Cosmopolite.prototype.subscribe = function(subject, messages, last_id, keys) {
Cosmopolite.prototype.subscribe = function(subject, messages, last_id) {
return new Promise(function(resolve, reject) {
var canonicalSubject = this.canonicalSubject_(subject);
var subjectString = JSON.stringify(canonicalSubject);
@@ -142,7 +141,6 @@ Cosmopolite.prototype.subscribe = function(subject, messages, last_id, keys) {
this.subscriptions_[subjectString] = {
'messages': [],
'pins': [],
'keys': {},
'state': this.SubscriptionState.PENDING,
};
}
@@ -156,9 +154,6 @@ Cosmopolite.prototype.subscribe = function(subject, messages, last_id, keys) {
if (last_id != null) {
args['last_id'] = last_id;
}
if (keys != null) {
args['keys'] = keys;
}
this.sendRPC_('subscribe', args, function(response) {
// unsubscribe may have been called since we sent the RPC. That's racy
@@ -201,18 +196,14 @@ Cosmopolite.prototype.unsubscribe = function(subject) {
*
* @param {!string} subject Subject name
* @param {!*} message Message string or object
* @param {string=} key Key name to associate this message with
*/
Cosmopolite.prototype.sendMessage = function(subject, message, key) {
Cosmopolite.prototype.sendMessage = function(subject, message) {
return new Promise(function(resolve, reject) {
var args = {
'subject': this.canonicalSubject_(subject),
'message': JSON.stringify(message),
'sender_message_id': this.uuid_(),
};
if (key) {
args['key'] = key;
}
// No message left behind.
var messageQueue = JSON.parse(localStorage[this.messageQueueKey_]);
@@ -249,19 +240,6 @@ Cosmopolite.prototype.getPins = function(subject) {
return this.subscriptions_[subjectString].pins;
};
/**
* Fetch the most recent message that defined a key
*
* @param {!string} subject Subject name
* @param {!string} key Key name
* @const
*/
Cosmopolite.prototype.getKeyMessage = function(subject, key) {
var canonicalSubject = this.canonicalSubject_(subject);
var subjectString = JSON.stringify(canonicalSubject);
return this.subscriptions_[subjectString].keys[key];
};
/**
* Return a Promise for our profile ID.
*/
@@ -835,9 +813,6 @@ Cosmopolite.prototype.onMessage_ = function(e) {
}
subscription.messages.splice(insertAfter + 1, 0, e);
if (e['key']) {
subscription.keys[e['key']] = e;
}
if ('onMessage' in this.callbacks_) {
this.callbacks_['onMessage'](e);
}