Skip to content

Commit

Permalink
extend nc contact menu
Browse files Browse the repository at this point in the history
- click on avatar opens chat window
- last message is shown below the name
- aggregated avatar presence icon

ref #21
  • Loading branch information
sualko committed Jun 27, 2017
1 parent f7614a4 commit 27e7b9d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 10 deletions.
64 changes: 64 additions & 0 deletions js/ojsxc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

$(mutation.target).find('[href^="xmpp:"]').addClass('jsxc_statusIndicator');

$(mutation.target).find('.contact').each(function(){
updateContactItem($(this));
});

jsxc.gui.detectUriScheme(mutation.target);
});
});
Expand All @@ -30,6 +34,66 @@
observer.observe(target, config);
}

function updateContactItem(contactElement) {
var xmppAddresses = contactElement.find('[href^="xmpp:"]').map(function(){
return $(this).attr('href').replace(/^xmpp:/, '');
});

if (xmppAddresses.length === 0) {
return;
}

var lastMessages = [];
var highestPresent = jsxc.CONST.STATUS.indexOf('offline');
var highestPresentBid = xmppAddresses.get(0);

xmppAddresses.each(function(index, bid){
var lastMsg = jsxc.getLastMsg(bid);

if (lastMsg) {
lastMessages.push(lastMsg);
}

var data = jsxc.storage.getUserItem('buddy', bid) || {};

if (data.status > highestPresent) {
highestPresent = data.status;
highestPresentBid = bid;
}
});

var latestMsg = {date: 0};
$(lastMessages).each(function(index, msg){
if (msg.date > latestMsg.date) {
latestMsg = msg;
}
});

if (latestMsg.date > 0) {
// replace emoticons from XEP-0038 and pidgin with shortnames
$.each(jsxc.gui.emotions, function(i, val) {
latestMsg.text = latestMsg.text.replace(val[2], ':' + val[1] + ':');
});

// translate shortnames to images
latestMsg.text = jsxc.gui.shortnameToImage(latestMsg.text);

contactElement.find('.last-message').html(latestMsg.text);
}

if (highestPresent > 0) {
var status = jsxc.CONST.STATUS[highestPresent];

contactElement.removeClass('jsxc_' + jsxc.CONST.STATUS.join(' jsxc_')).addClass('jsxc_' + status);
}

if (highestPresentBid) {
contactElement.find('.avatar').click(function() {
jsxc.gui.queryActions.message(highestPresentBid);
});
}
}

function injectChatIcon() {
var div = $('<div/>');

Expand Down
32 changes: 22 additions & 10 deletions scss/_oc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,27 @@
}

#contactsmenu-contacts {
.jsxc_statusIndicator {
position: relative;

&:before {
width: 6px;
height: 6px;
right: 13px;
top: 13px;
position: absolute;
.jsxc_statusIndicator {
position: relative;

&:before {
width: 6px;
height: 6px;
right: 13px;
top: 13px;
position: absolute;
}
}
}

.contact {
&:before {
position: absolute;
top: 7px;
left: 7px;
}

.avatar {
cursor: pointer;
}
}
}

0 comments on commit 27e7b9d

Please sign in to comment.