2
0
Эх сурвалжийг харах

Presence priority NOT handled correctly #785 (#787)

w3host 8 жил өмнө
parent
commit
15d2640c43

+ 1 - 0
docs/CHANGES.md

@@ -16,6 +16,7 @@
     * Templates are no longer stored as attributes on the `_converse` object.
     * Templates are no longer stored as attributes on the `_converse` object.
       If you need a particular template, use `require` to load it.
       If you need a particular template, use `require` to load it.
 
 
+- Add Presence Priority Handling [w3host]
 - The chat room `description` is now shown in the heading, not the `subject`.
 - The chat room `description` is now shown in the heading, not the `subject`.
   [jcbrand]
   [jcbrand]
 - Chat room features are shown in the sidebar. [jcbrand]
 - Chat room features are shown in the sidebar. [jcbrand]

+ 30 - 2
src/converse-core.js

@@ -1038,6 +1038,29 @@
                     }
                     }
                 }
                 }
             },
             },
+            
+            setPriority: function (bare_jid, resource, priority) {
+                var item = this.get(bare_jid),
+                    stored_priority;
+                if (item) {
+                    stored_priority = item.get('priority');
+                    if (stored_priority) {
+                        if (priority >= stored_priority) {
+                            item.set({'priority': priority});
+                            item.set({'priority_updated_by': resource});
+                            return true;
+                        } else if (resource === item.get('priority_updated_by')) {
+                                item.set({'priority': priority});
+                                return true;
+                        }
+                    } else  {
+                        item.set({'priority': priority});
+                        item.set({'priority_updated_by': resource});
+                        return true;
+                    }
+                }
+                return false;
+            },
 
 
             subscribeBack: function (bare_jid) {
             subscribeBack: function (bare_jid) {
                 var contact = this.get(bare_jid);
                 var contact = this.get(bare_jid);
@@ -1212,8 +1235,9 @@
                     resource = Strophe.getResourceFromJid(jid),
                     resource = Strophe.getResourceFromJid(jid),
                     chat_status = _.propertyOf(presence.querySelector('show'))('textContent') || 'online',
                     chat_status = _.propertyOf(presence.querySelector('show'))('textContent') || 'online',
                     status_message = _.propertyOf(presence.querySelector('status'))('textContent'),
                     status_message = _.propertyOf(presence.querySelector('status'))('textContent'),
+                    priority = _.propertyOf(presence.querySelector('priority'))('textContent') || 0,
                     contact = this.get(bare_jid);
                     contact = this.get(bare_jid);
-
+            
                 if (this.isSelf(bare_jid)) {
                 if (this.isSelf(bare_jid)) {
                     if ((_converse.connection.jid !== jid) &&
                     if ((_converse.connection.jid !== jid) &&
                         (presence_type !== 'unavailable') &&
                         (presence_type !== 'unavailable') &&
@@ -1243,6 +1267,8 @@
                 } else if (presence_type === 'subscribe') {
                 } else if (presence_type === 'subscribe') {
                     this.handleIncomingSubscription(presence);
                     this.handleIncomingSubscription(presence);
                 } else if (presence_type === 'unavailable' && contact) {
                 } else if (presence_type === 'unavailable' && contact) {
+                    // update priority to default level
+                    this.setPriority(bare_jid, resource, 0);
                     // Only set the user to offline if there aren't any
                     // Only set the user to offline if there aren't any
                     // other resources still available.
                     // other resources still available.
                     if (contact.removeResource(resource) === 0) {
                     if (contact.removeResource(resource) === 0) {
@@ -1250,7 +1276,9 @@
                     }
                     }
                 } else if (contact) { // presence_type is undefined
                 } else if (contact) { // presence_type is undefined
                     this.addResource(bare_jid, resource);
                     this.addResource(bare_jid, resource);
-                    contact.save({'chat_status': chat_status});
+                    if (this.setPriority(bare_jid, resource, priority)) {
+                            contact.save({'chat_status': chat_status});
+                    }
                 }
                 }
             }
             }
         });
         });