Discriminate between which unread messages to indicate per tab
This commit is contained in:
parent
297cd601cd
commit
a128a70d41
@ -14,7 +14,7 @@
|
|||||||
"rules": {
|
"rules": {
|
||||||
"lodash/prefer-lodash-method": [2, {
|
"lodash/prefer-lodash-method": [2, {
|
||||||
"ignoreMethods": [
|
"ignoreMethods": [
|
||||||
"find", "endsWith", "startsWith", "filter",
|
"find", "endsWith", "startsWith", "filter", "reduce",
|
||||||
"map", "replace", "toLower", "split", "trim"
|
"map", "replace", "toLower", "split", "trim"
|
||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
"jquery-easing": "0.0.1",
|
"jquery-easing": "0.0.1",
|
||||||
"jquery.browser": ">=0.1.0",
|
"jquery.browser": ">=0.1.0",
|
||||||
"jshint": "^2.9.4",
|
"jshint": "^2.9.4",
|
||||||
"lodash": "^4.17.4",
|
"lodash": "4.17.4",
|
||||||
"lodash-template-loader": "^2.0.0",
|
"lodash-template-loader": "^2.0.0",
|
||||||
"moment": "~2.18.1",
|
"moment": "~2.18.1",
|
||||||
"npm": "^4.1.1",
|
"npm": "^4.1.1",
|
||||||
|
@ -2135,6 +2135,8 @@
|
|||||||
_converse, 'kitchen', 'conference.shakespeare.lit', 'fires');
|
_converse, 'kitchen', 'conference.shakespeare.lit', 'fires');
|
||||||
test_utils.openContactsPanel(_converse);
|
test_utils.openContactsPanel(_converse);
|
||||||
var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
|
var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
|
||||||
|
expect(_.isNull(roomspanel.tab_el.querySelector('.msgs-indicator'))).toBeTruthy();
|
||||||
|
|
||||||
var view = _converse.chatboxviews.get(room_jid);
|
var view = _converse.chatboxviews.get(room_jid);
|
||||||
view.model.set({'minimized': true});
|
view.model.set({'minimized': true});
|
||||||
|
|
||||||
@ -2161,8 +2163,12 @@
|
|||||||
view.handleMUCMessage(msg);
|
view.handleMUCMessage(msg);
|
||||||
expect(roomspanel.tab_el.querySelector('.msgs-indicator').textContent).toBe('2');
|
expect(roomspanel.tab_el.querySelector('.msgs-indicator').textContent).toBe('2');
|
||||||
|
|
||||||
|
var contacts_panel = _converse.chatboxviews.get('controlbox').contactspanel;
|
||||||
|
expect(_.isNull(contacts_panel.tab_el.querySelector('.msgs-indicator'))).toBeTruthy();
|
||||||
|
|
||||||
view.model.set({'minimized': false});
|
view.model.set({'minimized': false});
|
||||||
expect(_.includes(roomspanel.tab_el.firstChild.classList, 'unread-msgs')).toBeFalsy();
|
expect(_.includes(roomspanel.tab_el.firstChild.classList, 'unread-msgs')).toBeFalsy();
|
||||||
|
expect(_.isNull(roomspanel.tab_el.querySelector('.msgs-indicator'))).toBeTruthy();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1134,6 +1134,9 @@
|
|||||||
test_utils.createContacts(_converse, 'all').openControlBox();
|
test_utils.createContacts(_converse, 'all').openControlBox();
|
||||||
test_utils.openContactsPanel(_converse);
|
test_utils.openContactsPanel(_converse);
|
||||||
|
|
||||||
|
var contacts_panel = _converse.chatboxviews.get('controlbox').contactspanel;
|
||||||
|
expect(_.isNull(contacts_panel.tab_el.querySelector('.msgs-indicator'))).toBeTruthy();
|
||||||
|
|
||||||
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||||
test_utils.openChatBoxFor(_converse, sender_jid);
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
||||||
var chatview = _converse.chatboxviews.get(sender_jid);
|
var chatview = _converse.chatboxviews.get(sender_jid);
|
||||||
@ -1147,7 +1150,6 @@
|
|||||||
}).c('body').t('hello').up()
|
}).c('body').t('hello').up()
|
||||||
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
||||||
_converse.chatboxes.onMessage(msg);
|
_converse.chatboxes.onMessage(msg);
|
||||||
var contacts_panel = _converse.chatboxviews.get('controlbox').contactspanel;
|
|
||||||
expect(contacts_panel.tab_el.querySelector('.msgs-indicator').textContent).toBe('1');
|
expect(contacts_panel.tab_el.querySelector('.msgs-indicator').textContent).toBe('1');
|
||||||
|
|
||||||
msg = $msg({
|
msg = $msg({
|
||||||
@ -1160,8 +1162,12 @@
|
|||||||
_converse.chatboxes.onMessage(msg);
|
_converse.chatboxes.onMessage(msg);
|
||||||
expect(contacts_panel.tab_el.querySelector('.msgs-indicator').textContent).toBe('2');
|
expect(contacts_panel.tab_el.querySelector('.msgs-indicator').textContent).toBe('2');
|
||||||
|
|
||||||
|
var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
|
||||||
|
expect(_.isNull(roomspanel.tab_el.querySelector('.msgs-indicator'))).toBeTruthy();
|
||||||
|
|
||||||
chatview.model.set({'minimized': false});
|
chatview.model.set({'minimized': false});
|
||||||
expect(_.includes(contacts_panel.tab_el.firstChild.classList, 'unread-msgs')).toBeFalsy();
|
expect(_.includes(contacts_panel.tab_el.firstChild.classList, 'unread-msgs')).toBeFalsy();
|
||||||
|
expect(_.isNull(contacts_panel.tab_el.querySelector('.msgs-indicator'))).toBeTruthy();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
"tpl!login_tab",
|
"tpl!login_tab",
|
||||||
"tpl!search_contact",
|
"tpl!search_contact",
|
||||||
"tpl!status_option",
|
"tpl!status_option",
|
||||||
|
"lodash.fp",
|
||||||
"converse-chatview",
|
"converse-chatview",
|
||||||
"converse-rosterview"
|
"converse-rosterview"
|
||||||
], factory);
|
], factory);
|
||||||
@ -38,7 +39,8 @@
|
|||||||
tpl_login_panel,
|
tpl_login_panel,
|
||||||
tpl_login_tab,
|
tpl_login_tab,
|
||||||
tpl_search_contact,
|
tpl_search_contact,
|
||||||
tpl_status_option
|
tpl_status_option,
|
||||||
|
fp
|
||||||
) {
|
) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -590,10 +592,16 @@
|
|||||||
render: function () {
|
render: function () {
|
||||||
var controlbox = _converse.chatboxes.get('controlbox');
|
var controlbox = _converse.chatboxes.get('controlbox');
|
||||||
var is_current = controlbox.get('active-panel') === USERS_PANEL_ID;
|
var is_current = controlbox.get('active-panel') === USERS_PANEL_ID;
|
||||||
|
|
||||||
|
var isChatBox = function (item) {
|
||||||
|
return item.get('type') == 'chatbox';
|
||||||
|
}
|
||||||
|
var chatrooms = fp.filter(isChatBox, _converse.chatboxes.models);
|
||||||
|
|
||||||
this.tab_el.innerHTML = tpl_contacts_tab({
|
this.tab_el.innerHTML = tpl_contacts_tab({
|
||||||
'label_contacts': LABEL_CONTACTS,
|
'label_contacts': LABEL_CONTACTS,
|
||||||
'is_current': is_current,
|
'is_current': is_current,
|
||||||
'num_unread': _.sum(_converse.chatboxes.pluck('num_unread'))
|
'num_unread': fp.sum(fp.map(fp.curry(utils.getAttribute)('num_unread'), chatrooms))
|
||||||
});
|
});
|
||||||
|
|
||||||
var widgets = tpl_contacts_panel({
|
var widgets = tpl_contacts_panel({
|
||||||
|
@ -1352,6 +1352,7 @@
|
|||||||
this.ChatBox = Backbone.Model.extend({
|
this.ChatBox = Backbone.Model.extend({
|
||||||
|
|
||||||
defaults: {
|
defaults: {
|
||||||
|
'type': 'chatbox',
|
||||||
'bookmarked': false,
|
'bookmarked': false,
|
||||||
'chat_state': undefined,
|
'chat_state': undefined,
|
||||||
'num_unread': 0,
|
'num_unread': 0,
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
"tpl!room_description",
|
"tpl!room_description",
|
||||||
"tpl!room_item",
|
"tpl!room_item",
|
||||||
"tpl!room_panel",
|
"tpl!room_panel",
|
||||||
|
"lodash.fp",
|
||||||
"awesomplete",
|
"awesomplete",
|
||||||
"converse-chatview"
|
"converse-chatview"
|
||||||
], factory);
|
], factory);
|
||||||
@ -51,10 +52,13 @@
|
|||||||
tpl_room_description,
|
tpl_room_description,
|
||||||
tpl_room_item,
|
tpl_room_item,
|
||||||
tpl_room_panel,
|
tpl_room_panel,
|
||||||
|
fp,
|
||||||
Awesomplete
|
Awesomplete
|
||||||
) {
|
) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
var ROOMS_PANEL_ID = 'chatrooms';
|
var ROOMS_PANEL_ID = 'chatrooms';
|
||||||
|
var CHATROOMS_TYPE = 'chatroom';
|
||||||
|
|
||||||
// Strophe methods for building stanzas
|
// Strophe methods for building stanzas
|
||||||
var Strophe = converse.env.Strophe,
|
var Strophe = converse.env.Strophe,
|
||||||
@ -145,7 +149,7 @@
|
|||||||
ChatBoxes: {
|
ChatBoxes: {
|
||||||
model: function (attrs, options) {
|
model: function (attrs, options) {
|
||||||
var _converse = this.__super__._converse;
|
var _converse = this.__super__._converse;
|
||||||
if (attrs.type == 'chatroom') {
|
if (attrs.type == CHATROOMS_TYPE) {
|
||||||
return new _converse.ChatRoom(attrs, options);
|
return new _converse.ChatRoom(attrs, options);
|
||||||
} else {
|
} else {
|
||||||
return this.__super__.model.apply(this, arguments);
|
return this.__super__.model.apply(this, arguments);
|
||||||
@ -223,7 +227,7 @@
|
|||||||
onChatBoxAdded: function (item) {
|
onChatBoxAdded: function (item) {
|
||||||
var _converse = this.__super__._converse;
|
var _converse = this.__super__._converse;
|
||||||
var view = this.get(item.get('id'));
|
var view = this.get(item.get('id'));
|
||||||
if (!view && item.get('type') === 'chatroom') {
|
if (!view && item.get('type') === CHATROOMS_TYPE) {
|
||||||
view = new _converse.ChatRoomView({'model': item});
|
view = new _converse.ChatRoomView({'model': item});
|
||||||
return this.add(item.get('id'), view);
|
return this.add(item.get('id'), view);
|
||||||
} else {
|
} else {
|
||||||
@ -355,7 +359,7 @@
|
|||||||
'description': '',
|
'description': '',
|
||||||
'features_fetched': false,
|
'features_fetched': false,
|
||||||
'roomconfig': {},
|
'roomconfig': {},
|
||||||
'type': 'chatroom',
|
'type': CHATROOMS_TYPE,
|
||||||
}, settings)
|
}, settings)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -371,6 +375,7 @@
|
|||||||
// _converse.ChatBox to indicate unread messages which
|
// _converse.ChatBox to indicate unread messages which
|
||||||
// mention the user and `num_unread_general` to indicate
|
// mention the user and `num_unread_general` to indicate
|
||||||
// generally unread messages (which *includes* mentions!).
|
// generally unread messages (which *includes* mentions!).
|
||||||
|
'type': CHATROOMS_TYPE,
|
||||||
'num_unread_general': 0
|
'num_unread_general': 0
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -2394,10 +2399,12 @@
|
|||||||
});
|
});
|
||||||
var controlbox = _converse.chatboxes.get('controlbox');
|
var controlbox = _converse.chatboxes.get('controlbox');
|
||||||
var is_current = controlbox.get('active-panel') === ROOMS_PANEL_ID;
|
var is_current = controlbox.get('active-panel') === ROOMS_PANEL_ID;
|
||||||
|
var isChatroom = fp.curry(utils.isInstance)(_converse.ChatRoom)
|
||||||
|
var chatrooms = fp.filter(isChatroom, _converse.chatboxes.models);
|
||||||
this.tab_el.innerHTML = tpl_chatrooms_tab({
|
this.tab_el.innerHTML = tpl_chatrooms_tab({
|
||||||
'label_rooms': __('Rooms'),
|
'label_rooms': __('Rooms'),
|
||||||
'is_current': is_current,
|
'is_current': is_current,
|
||||||
'num_unread': _.sum(_converse.chatboxes.pluck('num_unread'))
|
'num_unread': fp.sum(fp.map(fp.curry(utils.getAttribute)('num_unread'), chatrooms))
|
||||||
});
|
});
|
||||||
if (!is_current) {
|
if (!is_current) {
|
||||||
this.el.classList.add('hidden');
|
this.el.classList.add('hidden');
|
||||||
@ -2584,7 +2591,7 @@
|
|||||||
'id': jid,
|
'id': jid,
|
||||||
'jid': jid,
|
'jid': jid,
|
||||||
'name': name || Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
|
'name': name || Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
|
||||||
'type': 'chatroom',
|
'type': CHATROOMS_TYPE,
|
||||||
'box_id': b64_sha1(jid)
|
'box_id': b64_sha1(jid)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -2638,7 +2645,7 @@
|
|||||||
'id': room_jid,
|
'id': room_jid,
|
||||||
'jid': room_jid,
|
'jid': room_jid,
|
||||||
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(room_jid)),
|
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(room_jid)),
|
||||||
'type': 'chatroom',
|
'type': CHATROOMS_TYPE,
|
||||||
'box_id': b64_sha1(room_jid),
|
'box_id': b64_sha1(room_jid),
|
||||||
'password': $x.attr('password')
|
'password': $x.attr('password')
|
||||||
});
|
});
|
||||||
@ -2684,7 +2691,7 @@
|
|||||||
'id': jid,
|
'id': jid,
|
||||||
'jid': jid,
|
'jid': jid,
|
||||||
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
|
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
|
||||||
'type': 'chatroom',
|
'type': CHATROOMS_TYPE,
|
||||||
'box_id': b64_sha1(jid)
|
'box_id': b64_sha1(jid)
|
||||||
}, attrs)));
|
}, attrs)));
|
||||||
};
|
};
|
||||||
@ -2739,7 +2746,7 @@
|
|||||||
if (_.isUndefined(jids)) {
|
if (_.isUndefined(jids)) {
|
||||||
var result = [];
|
var result = [];
|
||||||
_converse.chatboxes.each(function (chatbox) {
|
_converse.chatboxes.each(function (chatbox) {
|
||||||
if (chatbox.get('type') === 'chatroom') {
|
if (chatbox.get('type') === CHATROOMS_TYPE) {
|
||||||
result.push(_converse.getViewForChatBox(chatbox));
|
result.push(_converse.getViewForChatBox(chatbox));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -2762,7 +2769,7 @@
|
|||||||
* all the open chat rooms.
|
* all the open chat rooms.
|
||||||
*/
|
*/
|
||||||
_converse.chatboxviews.each(function (view) {
|
_converse.chatboxviews.each(function (view) {
|
||||||
if (view.model.get('type') === 'chatroom') {
|
if (view.model.get('type') === CHATROOMS_TYPE) {
|
||||||
view.model.save('connection_status', ROOMSTATUS.DISCONNECTED);
|
view.model.save('connection_status', ROOMSTATUS.DISCONNECTED);
|
||||||
view.join();
|
view.join();
|
||||||
}
|
}
|
||||||
@ -2776,7 +2783,7 @@
|
|||||||
* when fetched from session storage.
|
* when fetched from session storage.
|
||||||
*/
|
*/
|
||||||
_converse.chatboxes.each(function (model) {
|
_converse.chatboxes.each(function (model) {
|
||||||
if (model.get('type') === 'chatroom') {
|
if (model.get('type') === CHATROOMS_TYPE) {
|
||||||
model.save('connection_status', ROOMSTATUS.DISCONNECTED);
|
model.save('connection_status', ROOMSTATUS.DISCONNECTED);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<a class="s
|
<a class="s rooms-tab
|
||||||
{[ if (is_current) { ]} current {[ } ]}
|
{[ if (is_current) { ]} current {[ } ]}
|
||||||
{[ if (num_unread) { ]} unread-msgs {[ } ]}"
|
{[ if (num_unread) { ]} unread-msgs {[ } ]}"
|
||||||
data-id="chatrooms" href="#chatrooms">
|
data-id="chatrooms" href="#chatrooms">
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<a class="s
|
<a class="s contacts-tab
|
||||||
{[ if (is_current) { ]} current {[ } ]}
|
{[ if (is_current) { ]} current {[ } ]}
|
||||||
{[ if (num_unread) { ]} unread-msgs {[ } ]}"
|
{[ if (num_unread) { ]} unread-msgs {[ } ]}"
|
||||||
data-id="users" href="#users">
|
data-id="users" href="#users">
|
||||||
|
@ -471,6 +471,14 @@
|
|||||||
return utils.detectLocale(isSupportedByLibrary) || 'en';
|
return utils.detectLocale(isSupportedByLibrary) || 'en';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
utils.isInstance = function (type, item) {
|
||||||
|
return item instanceof type;
|
||||||
|
};
|
||||||
|
|
||||||
|
utils.getAttribute = function (key, item) {
|
||||||
|
return item.get(key);
|
||||||
|
};
|
||||||
|
|
||||||
utils.contains.not = function (attr, query) {
|
utils.contains.not = function (attr, query) {
|
||||||
return function (item) {
|
return function (item) {
|
||||||
return !(utils.contains(attr, query)(item));
|
return !(utils.contains(attr, query)(item));
|
||||||
|
Loading…
Reference in New Issue
Block a user