| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- ;(function($){
- const sMenuId = 'data-group-id',
- sParentsGroupSelector = 'data-talks-type',
- { menuAddonCounter } = window.oMessengerSelectors.SYSTEM;
- let oMenuBubbleStructure = null;
- $.fn.extend({
- updateMenuBubbles: function(iLotId, mixedMode, bAdd = true) {
- const { oNotifications } = this.get(0),
- sLotId = iLotId.toString();
- if (oMenuBubbleStructure === null || !iLotId)
- return;
- if (bAdd)
- return executeAction(mixedMode, 'add', sLotId);
- performAction('delete', sLotId);
- },
- initMenuBubbles: function(){
- const { oNotifications } = this.get(0),
- { collapsableArea, chevronUpIcon, addonWrapper } = window.oMessengerSelectors.MENU_AREA;
- if (oMenuBubbleStructure === null)
- oMenuBubbleStructure = oNotifications;
- const fFunc = function(){
- if (+$(menuAddonCounter, this).html())
- $(addonWrapper, this).removeClass('hidden');
- };
- $(collapsableArea).on('click', function(){
- if (!$(this).find(chevronUpIcon).is(':visible'))
- $(addonWrapper, this).addClass('hidden');
- else
- fFunc.apply(this);
- }).each(fFunc);
- }
- });
- function updateInbox(bInc = true){
- let iInbox = +oMenuBubbleStructure['inbox'];
- if (iInbox > 0 && !bInc)
- iInbox--;
- if (bInc)
- iInbox++;
- oMenuBubbleStructure['inbox'] = iInbox;
- }
- function executeAction(oType, sAction, iConvoId){
- const { type, groups_type, group_id } = oType;
- try {
- switch(sAction){
- case 'delete':
- if (typeof groups_type !== 'undefined') {
- delete oMenuBubbleStructure[type][groups_type][group_id][iConvoId];
- if (!Object.keys(oMenuBubbleStructure[type][groups_type][group_id]).length){
- delete oMenuBubbleStructure[type][groups_type][group_id];
- if (!Object.keys(oMenuBubbleStructure[type][groups_type]).length)
- delete oMenuBubbleStructure[type][groups_type][group_id];
- if (!Object.keys(oMenuBubbleStructure[type]).length)
- delete oMenuBubbleStructure[type];
- }
- } else
- delete oMenuBubbleStructure[type][iConvoId];
- updateInbox(false);
- break;
- case 'add':
- let bExecute = false;
- if ( typeof groups_type !== 'undefined' ) {
- if (typeof oMenuBubbleStructure[type][groups_type] === 'undefined') {
- oMenuBubbleStructure[type][groups_type] = {[group_id]: {[iConvoId]: 1}};
- bExecute = true;
- }
- else
- if (typeof oMenuBubbleStructure[type][groups_type][group_id] === 'undefined') {
- oMenuBubbleStructure[type][groups_type][group_id] = {[iConvoId]: 1};
- bExecute = true;
- }
- else
- if (typeof oMenuBubbleStructure[type][groups_type][group_id][iConvoId] === 'undefined') {
- oMenuBubbleStructure[type][groups_type][group_id][iConvoId] = 1;
- bExecute = true;
- }
- } else
- if ( typeof oMenuBubbleStructure[type][iConvoId] === 'undefined' ) {
- oMenuBubbleStructure[type][iConvoId] = 1;
- bExecute = true;
- }
- if (bExecute)
- updateInbox();
- }
- } catch (e) {
- console.log('error counter update', e);
- }
- updateNavMenuBubbles(type, groups_type);
- }
- function performAction(sAction, iConvoId){
- for (const sType in oMenuBubbleStructure){
- if (sType === 'inbox')
- continue;
- if (sType === 'groups'){
- const oGroups = oMenuBubbleStructure[sType];
- for(const sGroup in oGroups){
- for(const iGroupId in oGroups[sGroup]){
- const aConvos = Object.keys(oGroups[sGroup][iGroupId]);
- if (~aConvos.indexOf(iConvoId)){
- return executeAction({ type: sType, groups_type: sGroup, group_id: iGroupId}, sAction, iConvoId);
- }
- }
- }
- }
- else
- {
- const oItems = oMenuBubbleStructure[sType],
- aConvosList = Object.keys(oItems);
- if (~aConvosList.indexOf(iConvoId))
- return executeAction({ type: sType }, sAction, iConvoId);
- }
- }
- }
- function updateNavMenuBubbles(sType, sSubGroup){
- let iCounter = 0;
- if (sType === 'groups' && typeof sSubGroup === 'string') {
- if (typeof oMenuBubbleStructure[sType][sSubGroup] !== 'undefined'){
- let iMainCounter = Object.keys(oMenuBubbleStructure[sType][sSubGroup]).length;
- const oTalkObject = $(`[${sParentsGroupSelector}="${sSubGroup}"]`),
- fFunc = (oGroups, iGroupId) => {
- let iCounter = oGroups[iGroupId] ? Object.keys(oGroups[iGroupId]).length : 0,
- oGroup = $(`[${sMenuId}="${iGroupId}"] ${menuAddonCounter}`);
- oGroup.html(iCounter);
- if (!iCounter)
- oGroup.parent().addClass('hidden');
- else
- oGroup.parent().removeClass('hidden');
- };
- oTalkObject.html(iMainCounter);
- if (!iMainCounter)
- oTalkObject.parent().addClass('hidden');
- else
- oTalkObject.parent().removeClass('hidden');
- const oGroupItems = oMenuBubbleStructure[sType][sSubGroup];
- if (!Object.keys(oGroupItems).length)
- $(`li[class*="${sSubGroup}"] li`).each(function(){
- let iGroupId = +$(this).data('group-id');
- if (iGroupId)
- fFunc(oGroupItems, iGroupId);
- });
- else
- Object.keys(oGroupItems).forEach((iGroupId) => fFunc(oGroupItems, iGroupId));
- }
- }
- else
- {
- let oTalkType = $(`[${sParentsGroupSelector}="${sType}"]`);
- iCounter = +Object.keys(oMenuBubbleStructure[sType]).length;
- oTalkType.html(iCounter);
- if (!iCounter)
- oTalkType
- .parent()
- .addClass('hidden');
- else
- oTalkType
- .parent()
- .removeClass('hidden');
- }
- const oIndex = $(`[${sParentsGroupSelector}="inbox"]`).html(oMenuBubbleStructure['inbox']);
- if (+oMenuBubbleStructure['inbox'])
- oIndex.parent().removeClass('hidden');
- else
- oIndex.parent().addClass('hidden');
- }
- })(jQuery);
|