Commit f4e3f9d2 authored by Thibaut Frain's avatar Thibaut Frain

Added basic new messages notification on contactlist gadget

parent 26c08d12
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
}).allowPublicAcquisition("receive", function(datas) { }).allowPublicAcquisition("receive", function(datas) {
datas = datas[0]; datas = datas[0];
console.log("[xmpp datas input] : " + datas); console.log("[xmpp datas input] : " + datas);
var xmlInput = parseXML(datas); var xmlInput = parseXML(datas), gadget = this;
if (isRoster(xmlInput)) { if (isRoster(xmlInput)) {
return this.getDeclaredGadget("contactlist").push(function(contactlist_gadget) { return this.getDeclaredGadget("contactlist").push(function(contactlist_gadget) {
return contactlist_gadget.receiveRoster(datas); return contactlist_gadget.receiveRoster(datas);
...@@ -45,11 +45,15 @@ ...@@ -45,11 +45,15 @@
} }
if (isPresence(xmlInput)) { if (isPresence(xmlInput)) {
return this.getDeclaredGadget("contactlist").push(function(contactlist_gadget) { return this.getDeclaredGadget("contactlist").push(function(contactlist_gadget) {
contactlist_gadget.receivePresence(datas); return contactlist_gadget.receivePresence(datas);
}); });
} }
if (isMessage(xmlInput)) { if (isMessage(xmlInput)) {
return this.getDeclaredGadget("chatbox").push(function(chatbox_gadget) { return this.getDeclaredGadget("contactlist").push(function(contactlist_gadget) {
return contactlist_gadget.receiveMessage(datas);
}).push(function() {
return gadget.getDeclaredGadget("chatbox");
}).push(function(chatbox_gadget) {
return chatbox_gadget.receive(datas); return chatbox_gadget.receive(datas);
}); });
} }
...@@ -82,7 +86,11 @@ ...@@ -82,7 +86,11 @@
}); });
}).allowPublicAcquisition("getHash", function(options) { }).allowPublicAcquisition("getHash", function(options) {
return this.aq_pleasePublishMyState(options[0]); return this.aq_pleasePublishMyState(options[0]);
}).declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").allowPublicAcquisition("renderConnection", function() { }).declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").allowPublicAcquisition("messagesAreRead", function(jid) {
return this.getDeclaredGadget("contactlist").push(function(contactlist_gadget) {
return contactlist_gadget.messagesAreRead(jid[0]);
});
}).allowPublicAcquisition("renderConnection", function() {
return this.aq_pleasePublishMyState({ return this.aq_pleasePublishMyState({
page: "connection" page: "connection"
}).push(this.pleaseRedirectMyHash.bind(this)); }).push(this.pleaseRedirectMyHash.bind(this));
......
...@@ -90,7 +90,8 @@ ...@@ -90,7 +90,8 @@
} }
} }
}); });
}).declareAcquiredMethod("send", "send").declareMethod("receive", function(datas) { return this.messagesAreRead(options.current_contact_jid);
}).declareAcquiredMethod("messagesAreRead", "messagesAreRead").declareAcquiredMethod("send", "send").declareMethod("receive", function(datas) {
var xmlMessage = parseXML(datas), from = Strophe.getBareJidFromJid($(xmlMessage).attr("from")), to = Strophe.getBareJidFromJid($(xmlMessage).attr("to")), time = getTime(), content = $(xmlMessage).find("body").text(), message = new Message(from, to, time, content); var xmlMessage = parseXML(datas), from = Strophe.getBareJidFromJid($(xmlMessage).attr("from")), to = Strophe.getBareJidFromJid($(xmlMessage).attr("to")), time = getTime(), content = $(xmlMessage).find("body").text(), message = new Message(from, to, time, content);
if (!this.props.talks[from]) { if (!this.props.talks[from]) {
this.props.talks[from] = new Talk(from); this.props.talks[from] = new Talk(from);
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
alt="offline" alt="offline"
class="ui-li-icon ui-corner-none"> class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}} {{name}}&nbsp&nbsp{{jid}}
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</li> </li>
</script> </script>
...@@ -30,6 +33,9 @@ ...@@ -30,6 +33,9 @@
alt="online" alt="online"
class="ui-li-icon ui-corner-none"> class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}} {{name}}&nbsp&nbsp{{jid}}
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</a></li> </a></li>
</script> </script>
...@@ -39,6 +45,9 @@ ...@@ -39,6 +45,9 @@
alt="{{status}}" alt="{{status}}"
class="ui-li-icon ui-corner-none"> class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}&nbsp&nbsp({{status}}) {{name}}&nbsp&nbsp{{jid}}&nbsp&nbsp({{status}})
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</a></li> </a></li>
</script> </script>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
function parseXML(xmlString) { function parseXML(xmlString) {
return new DOMParser().parseFromString(xmlString, "text/xml").children[0]; return new DOMParser().parseFromString(xmlString, "text/xml").children[0];
} }
function updateContactElement(gadget, contact) { function updateContactElement(gadget, contact, new_message, messages_read) {
var template, options = {}; var template, options = {};
if (contact.el) { if (contact.el) {
contact.el.remove(); contact.el.remove();
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
} }
options.jid = contact.jid; options.jid = contact.jid;
options.name = contact.name; options.name = contact.name;
options.new_message = new_message || false;
return gadget.getConnectionJID().push(function(connection_jid) { return gadget.getConnectionJID().push(function(connection_jid) {
return gadget.getHash({ return gadget.getHash({
page: "chatbox", page: "chatbox",
...@@ -31,6 +32,11 @@ ...@@ -31,6 +32,11 @@
}).push(function(hash) { }).push(function(hash) {
options.hash = hash; options.hash = hash;
contact.el = $(template(options)); contact.el = $(template(options));
}).push(function() {
if (options.new_message || messages_read) {
gadget.contactList.el.prepend(contact.el);
gadget.contactList.el.listview("refresh");
}
}); });
} }
function updateContact(gadget, contact, presence) { function updateContact(gadget, contact, presence) {
...@@ -94,7 +100,13 @@ ...@@ -94,7 +100,13 @@
}); });
} }
} }
gadget.declareAcquiredMethod("getHash", "getHash").declareAcquiredMethod("getConnectionJID", "getConnectionJID").declareAcquiredMethod("send", "send").declareAcquiredMethod("openChat", "openChat").declareMethod("receiveRoster", function(roster) { gadget.declareAcquiredMethod("getHash", "getHash").declareAcquiredMethod("getConnectionJID", "getConnectionJID").declareAcquiredMethod("send", "send").declareAcquiredMethod("openChat", "openChat").declareMethod("messagesAreRead", function(jid) {
var contact = this.contactList.list[jid];
return updateContactElement(this, contact, false, true);
}).declareMethod("receiveMessage", function(message) {
var xmlMessage = parseXML(message), jid = Strophe.getBareJidFromJid($(xmlMessage).attr("from")), contact = this.contactList.list[jid];
return updateContactElement(this, contact, true);
}).declareMethod("receiveRoster", function(roster) {
this.contactList = new ContactList(this, parseXML(roster)); this.contactList = new ContactList(this, parseXML(roster));
}).declareMethod("receivePresence", function(presence) { }).declareMethod("receivePresence", function(presence) {
return updateContactList(this, parseXML(presence)); return updateContactList(this, parseXML(presence));
......
...@@ -53,7 +53,8 @@ ...@@ -53,7 +53,8 @@
.allowPublicAcquisition('receive', function (datas) { .allowPublicAcquisition('receive', function (datas) {
datas = datas[0]; datas = datas[0];
console.log('[xmpp datas input] : ' + datas); console.log('[xmpp datas input] : ' + datas);
var xmlInput = parseXML(datas); var xmlInput = parseXML(datas),
gadget = this;
if (isRoster(xmlInput)) { if (isRoster(xmlInput)) {
return this.getDeclaredGadget("contactlist") return this.getDeclaredGadget("contactlist")
...@@ -64,11 +65,17 @@ ...@@ -64,11 +65,17 @@
if (isPresence(xmlInput)) { if (isPresence(xmlInput)) {
return this.getDeclaredGadget("contactlist") return this.getDeclaredGadget("contactlist")
.push(function (contactlist_gadget) { .push(function (contactlist_gadget) {
contactlist_gadget.receivePresence(datas); return contactlist_gadget.receivePresence(datas);
}); });
} }
if (isMessage(xmlInput)) { if (isMessage(xmlInput)) {
return this.getDeclaredGadget("chatbox") return this.getDeclaredGadget("contactlist")
.push(function (contactlist_gadget) {
return contactlist_gadget.receiveMessage(datas);
})
.push(function () {
return gadget.getDeclaredGadget("chatbox");
})
.push(function (chatbox_gadget) { .push(function (chatbox_gadget) {
return chatbox_gadget.receive(datas); return chatbox_gadget.receive(datas);
}); });
...@@ -121,6 +128,13 @@ ...@@ -121,6 +128,13 @@
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash") .declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.allowPublicAcquisition("messagesAreRead", function (jid) {
return this.getDeclaredGadget('contactlist')
.push(function (contactlist_gadget) {
return contactlist_gadget.messagesAreRead(jid[0]);
});
})
.allowPublicAcquisition('renderConnection', function () { .allowPublicAcquisition('renderConnection', function () {
return this.aq_pleasePublishMyState({page: "connection"}) return this.aq_pleasePublishMyState({page: "connection"})
.push(this.pleaseRedirectMyHash.bind(this)); .push(this.pleaseRedirectMyHash.bind(this));
......
...@@ -124,8 +124,11 @@ ...@@ -124,8 +124,11 @@
} }
} }
}); });
return this.messagesAreRead(options.current_contact_jid);
}) })
.declareAcquiredMethod('messagesAreRead', "messagesAreRead")
.declareAcquiredMethod('send', 'send') .declareAcquiredMethod('send', 'send')
.declareMethod('receive', function (datas) { .declareMethod('receive', function (datas) {
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
alt="offline" alt="offline"
class="ui-li-icon ui-corner-none"> class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}} {{name}}&nbsp&nbsp{{jid}}
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</li> </li>
</script> </script>
...@@ -30,6 +33,9 @@ ...@@ -30,6 +33,9 @@
alt="online" alt="online"
class="ui-li-icon ui-corner-none"> class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}} {{name}}&nbsp&nbsp{{jid}}
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</a></li> </a></li>
</script> </script>
...@@ -39,6 +45,9 @@ ...@@ -39,6 +45,9 @@
alt="{{status}}" alt="{{status}}"
class="ui-li-icon ui-corner-none"> class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}&nbsp&nbsp({{status}}) {{name}}&nbsp&nbsp{{jid}}&nbsp&nbsp({{status}})
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</a></li> </a></li>
</script> </script>
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
.children[0]; .children[0];
} }
function updateContactElement(gadget, contact) { function updateContactElement(gadget, contact, new_message, messages_read) {
var template, var template,
options = {}; options = {};
if (contact.el) { contact.el.remove(); } if (contact.el) { contact.el.remove(); }
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
} }
options.jid = contact.jid; options.jid = contact.jid;
options.name = contact.name; options.name = contact.name;
options.new_message = new_message || false;
return gadget.getConnectionJID() return gadget.getConnectionJID()
.push(function (connection_jid) { .push(function (connection_jid) {
return gadget.getHash({ return gadget.getHash({
...@@ -47,6 +48,12 @@ ...@@ -47,6 +48,12 @@
.push(function (hash) { .push(function (hash) {
options.hash = hash; options.hash = hash;
contact.el = $(template(options)); contact.el = $(template(options));
})
.push(function () {
if (options.new_message || messages_read) {
gadget.contactList.el.prepend(contact.el);
gadget.contactList.el.listview('refresh');
}
}); });
} }
...@@ -134,6 +141,18 @@ ...@@ -134,6 +141,18 @@
.declareAcquiredMethod('openChat', 'openChat') .declareAcquiredMethod('openChat', 'openChat')
.declareMethod('messagesAreRead', function (jid) {
var contact = this.contactList.list[jid];
return updateContactElement(this, contact, false, true);
})
.declareMethod('receiveMessage', function (message) {
var xmlMessage = parseXML(message),
jid = Strophe.getBareJidFromJid($(xmlMessage).attr('from')),
contact = this.contactList.list[jid];
return updateContactElement(this, contact, true);
})
.declareMethod('receiveRoster', function (roster) { .declareMethod('receiveRoster', function (roster) {
this.contactList = new ContactList(this, parseXML(roster)); this.contactList = new ContactList(this, parseXML(roster));
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment