/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}


/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	module.exports = __webpack_require__(1);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	const electron = __webpack_require__(2);
	const ipc = electron.ipcRenderer;
	const notification = __webpack_require__(3);

	window.eval = global.eval = function() {
	  throw new Error("Sorry, Mattermost does not support window.eval() for security reasons.");
	};

	var hasClass = function(element, className) {
	  var rclass = /[\t\r\n\f]/g;
	  if ((' ' + element.className + ' ').replace(rclass, ' ').indexOf(className) > -1) {
	    return true;
	  }
	  return false;
	};

	setInterval(function() {
	  if (!this.unreadCount) {
	    this.unreadCount = 0;
	  }
	  if (!this.mentionCount) {
	    this.mentionCount = 0;
	  }

	  // unreadCount in sidebar
	  // Note: the active channel doesn't have '.unread-title'.
	  var unreadCount = document.getElementsByClassName('unread-title').length;
	  // mentionCount in sidebar
	  var elem = document.getElementsByClassName('badge');
	  var mentionCount = 0;
	  for (var i = 0; i < elem.length; i++) {
	    if (isElementVisible(elem[i]) && !hasClass(elem[i], 'badge-notify')) {
	      mentionCount += Number(elem[i].innerHTML);
	    }
	  }

	  var postAttrName = 'data-reactid';
	  var lastPostElem = document.querySelector('div[' + postAttrName + '="' + this.lastCheckedPostId + '"]');
	  var isUnread = false;
	  var isMentioned = false;
	  if (lastPostElem === null || !isElementVisible(lastPostElem)) {
	    // When load channel or change channel, this.lastCheckedPostId is invalid.
	    // So we get latest post and save lastCheckedPostId.

	    // find active post-list.
	    var postLists = document.querySelectorAll('div.post-list__content');
	    if (postLists.length === 0) {
	      return;
	    }
	    var post = null;
	    for (var j = 0; j < postLists.length; j++) {
	      if (isElementVisible(postLists[j])) {
	        post = postLists[j].children[0];
	      }
	    }
	    if (post === null) {
	      return;
	    }
	    // find latest post and save.
	    while (post = post.nextSibling) {
	      if (post.nextSibling === null) {
	        if (post.getAttribute(postAttrName) !== null) {
	          this.lastCheckedPostId = post.getAttribute(postAttrName);
	        }
	      }
	    }
	  }
	  else if (lastPostElem !== null) {
	    var newPostElem = lastPostElem;
	    while (newPostElem = newPostElem.nextSibling) {
	      this.lastCheckedPostId = newPostElem.getAttribute(postAttrName);
	      isUnread = true;
	      var activeChannel = document.querySelector('.active .sidebar-channel');
	      var closeButton = activeChannel.getElementsByClassName('btn-close');
	      if (closeButton.length === 1 && closeButton[0].getAttribute('aria-describedby') === 'remove-dm-tooltip') {
	        // If active channel is DM, all posts is treated as menion.
	        isMentioned = true;
	        break;
	      }
	      else {
	        // If active channel is public/private channel, only mentioned post is treated as mention.
	        var highlight = newPostElem.getElementsByClassName('mention-highlight');
	        if (highlight.length != 0 && isElementVisible(highlight[0])) {
	          isMentioned = true;
	          break;
	        }
	      }
	    }
	  }

	  if (this.unreadCount != unreadCount || this.mentionCount != mentionCount || isUnread || isMentioned) {
	    ipc.sendToHost('onUnreadCountChange', unreadCount, mentionCount, isUnread, isMentioned);
	  }
	  this.unreadCount = unreadCount;
	  this.mentionCount = mentionCount;
	}, 1000);

	function isElementVisible(elem) {
	  return elem.offsetHeight !== 0;
	}

	notification.override({
	  // Send a notification event to the main process.
	  notification: function(title, options) {
	    ipc.send('notified', {
	      title: title,
	      options: options
	    });
	  },
	  // Show window even if it is hidden/minimized when notification is clicked.
	  onclick: function() {
	    const currentWindow = electron.remote.getCurrentWindow();
	    if (process.platform === 'win32') {
	      // show() breaks Aero Snap state.
	      if (currentWindow.isVisible()) {
	        currentWindow.focus();
	      }
	      else if (currentWindow.isMinimized()) {
	        currentWindow.restore();
	      }
	      else {
	        currentWindow.show();
	      }
	    }
	    else if (currentWindow.isMinimized()) {
	      currentWindow.restore();
	    }
	    else {
	      currentWindow.show();
	    }
	    ipc.sendToHost('onNotificationClick');
	  }
	});

	// get the last of href for the current channel in the sidebar.
	function getCurrentChannelString() {
	  const active_channel_link = document.querySelector('.active a.sidebar-channel');
	  const url_elements = active_channel_link.href.split('/');
	  return url_elements[url_elements.length - 1];
	}

	ipc.on('activate-search-box', (event) => {
	  const search_boxes = document.getElementsByClassName('search-bar'); // should use id
	  if (search_boxes.length === 0) {
	    return;
	  }
	  const search_box = search_boxes[0];
	  search_box.focus();
	  search_box.value = ``; //Clear the input box
	});

	ipc.on('activate-search-box-in-channel', (event) => {
	  const search_boxes = document.getElementsByClassName('search-bar'); // should use id
	  if (search_boxes.length === 0) {
	    return;
	  }
	  const search_box = search_boxes[0];
	  search_box.focus();
	  search_box.value = `in:${getCurrentChannelString()} `;
	});


/***/ },
/* 2 */
/***/ function(module, exports) {

	module.exports = require("electron");

/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	const OriginalNotification = Notification;

	const appIconURL = `file:///${__webpack_require__(2).remote.app.getAppPath()}/resources/appicon.png`;

	function override(eventHandlers) {
	  Notification = function(title, options) {
	    if (process.platform === 'win32') {
	      // Replace with application icon.
	      options.icon = appIconURL;
	    }
	    else if (process.platform === 'darwin') {
	      // Notification Center shows app's icon, so there were two icons on the notification.
	      delete options.icon;
	    }
	    this.notification = new OriginalNotification(title, options);
	    if (eventHandlers.notification) {
	      eventHandlers.notification(title, options);
	    }
	  };

	  // static properties
	  Notification.__defineGetter__('permission', function() {
	    return OriginalNotification.permission;
	  });

	  // instance properties
	  var defineReadProperty = function(property) {
	    Notification.prototype.__defineGetter__(property, function() {
	      return this.notification[property];
	    });
	  };
	  defineReadProperty('title');
	  defineReadProperty('dir');
	  defineReadProperty('lang');
	  defineReadProperty('body');
	  defineReadProperty('tag');
	  defineReadProperty('icon');
	  defineReadProperty('data');
	  defineReadProperty('silent');

	  // unsupported properties
	  defineReadProperty('noscreen');
	  defineReadProperty('renotify');
	  defineReadProperty('sound');
	  defineReadProperty('sticky');
	  defineReadProperty('vibrate');

	  // event handlers
	  var defineEventHandler = function(event, callback) {
	    defineReadProperty(event);
	    Notification.prototype.__defineSetter__(event, function(originalCallback) {
	      this.notification[event] = function() {
	        const callbackevent = {
	          preventDefault: function() {
	            this.isPrevented = true;
	          }
	        };
	        if (callback) {
	          callback(callbackevent);
	          if (!callbackevent.isPrevented) {
	            originalCallback();
	          }
	        }
	        else {
	          originalCallback();
	        }
	      };
	    });
	  };
	  defineEventHandler('onclick', eventHandlers.onclick);
	  defineEventHandler('onerror', eventHandlers.onerror);

	  // obsolete handlers
	  defineEventHandler('onclose', eventHandlers.onclose);
	  defineEventHandler('onshow', eventHandlers.onshow);

	  // static methods
	  Notification.requestPermission = function(callback) {
	    OriginalNotification.requestPermission(callback);
	  };

	  // instance methods
	  Notification.prototype.close = function() {
	    this.notification.close();
	  };
	}

	module.exports = {
	  override: override
	};


/***/ }
/******/ ]);