Commit f4e3f9d2 authored by Thibaut Frain's avatar Thibaut Frain

Added basic new messages notification on contactlist gadget

parent 26c08d12
......@@ -37,7 +37,7 @@
}).allowPublicAcquisition("receive", function(datas) {
datas = datas[0];
console.log("[xmpp datas input] : " + datas);
var xmlInput = parseXML(datas);
var xmlInput = parseXML(datas), gadget = this;
if (isRoster(xmlInput)) {
return this.getDeclaredGadget("contactlist").push(function(contactlist_gadget) {
return contactlist_gadget.receiveRoster(datas);
......@@ -45,11 +45,15 @@
}
if (isPresence(xmlInput)) {
return this.getDeclaredGadget("contactlist").push(function(contactlist_gadget) {
contactlist_gadget.receivePresence(datas);
return contactlist_gadget.receivePresence(datas);
});
}
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);
});
}
......@@ -82,7 +86,11 @@
});
}).allowPublicAcquisition("getHash", function(options) {
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({
page: "connection"
}).push(this.pleaseRedirectMyHash.bind(this));
......
......@@ -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);
if (!this.props.talks[from]) {
this.props.talks[from] = new Talk(from);
......
......@@ -21,6 +21,9 @@
alt="offline"
class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</li>
</script>
......@@ -30,6 +33,9 @@
alt="online"
class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</a></li>
</script>
......@@ -39,6 +45,9 @@
alt="{{status}}"
class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}&nbsp&nbsp({{status}})
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</a></li>
</script>
......
......@@ -7,7 +7,7 @@
function parseXML(xmlString) {
return new DOMParser().parseFromString(xmlString, "text/xml").children[0];
}
function updateContactElement(gadget, contact) {
function updateContactElement(gadget, contact, new_message, messages_read) {
var template, options = {};
if (contact.el) {
contact.el.remove();
......@@ -22,6 +22,7 @@
}
options.jid = contact.jid;
options.name = contact.name;
options.new_message = new_message || false;
return gadget.getConnectionJID().push(function(connection_jid) {
return gadget.getHash({
page: "chatbox",
......@@ -31,6 +32,11 @@
}).push(function(hash) {
options.hash = hash;
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) {
......@@ -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));
}).declareMethod("receivePresence", function(presence) {
return updateContactList(this, parseXML(presence));
......
......@@ -53,7 +53,8 @@
.allowPublicAcquisition('receive', function (datas) {
datas = datas[0];
console.log('[xmpp datas input] : ' + datas);
var xmlInput = parseXML(datas);
var xmlInput = parseXML(datas),
gadget = this;
if (isRoster(xmlInput)) {
return this.getDeclaredGadget("contactlist")
......@@ -64,11 +65,17 @@
if (isPresence(xmlInput)) {
return this.getDeclaredGadget("contactlist")
.push(function (contactlist_gadget) {
contactlist_gadget.receivePresence(datas);
return contactlist_gadget.receivePresence(datas);
});
}
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) {
return chatbox_gadget.receive(datas);
});
......@@ -121,6 +128,13 @@
.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({page: "connection"})
.push(this.pleaseRedirectMyHash.bind(this));
......
......@@ -124,8 +124,11 @@
}
}
});
return this.messagesAreRead(options.current_contact_jid);
})
.declareAcquiredMethod('messagesAreRead', "messagesAreRead")
.declareAcquiredMethod('send', 'send')
.declareMethod('receive', function (datas) {
......
......@@ -21,6 +21,9 @@
alt="offline"
class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</li>
</script>
......@@ -30,6 +33,9 @@
alt="online"
class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</a></li>
</script>
......@@ -39,6 +45,9 @@
alt="{{status}}"
class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}&nbsp&nbsp({{status}})
{{#if new_message}}
&nbsp&nbsp [new message(s)]
{{/if}}
</a></li>
</script>
......
......@@ -22,7 +22,7 @@
.children[0];
}
function updateContactElement(gadget, contact) {
function updateContactElement(gadget, contact, new_message, messages_read) {
var template,
options = {};
if (contact.el) { contact.el.remove(); }
......@@ -36,6 +36,7 @@
}
options.jid = contact.jid;
options.name = contact.name;
options.new_message = new_message || false;
return gadget.getConnectionJID()
.push(function (connection_jid) {
return gadget.getHash({
......@@ -47,6 +48,12 @@
.push(function (hash) {
options.hash = hash;
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 @@
.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));
})
......
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