var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getReactionsForFilterSort = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _getReactions = require("./getReactions");
var _selectReactionsForMessages = require("./queries/selectReactionsForMessages");
var _SqliteClient = require("../SqliteClient");
var getReactionsForFilterSort = exports.getReactionsForFilterSort = function () {
  var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref) {
    var messageId, filters, sort, limit, reactions;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          messageId = _ref.messageId, filters = _ref.filters, sort = _ref.sort, limit = _ref.limit;
          if (!(!filters && !sort)) {
            _context.next = 4;
            break;
          }
          console.warn('Please provide the query (filters/sort) to fetch channels from DB');
          return _context.abrupt("return", null);
        case 4:
          _SqliteClient.SqliteClient.logger == null || _SqliteClient.SqliteClient.logger('info', 'getReactionsForFilterSort', {
            filters: filters,
            sort: sort
          });
          _context.next = 7;
          return (0, _selectReactionsForMessages.selectReactionsForMessages)([messageId], limit, filters, sort);
        case 7:
          reactions = _context.sent;
          if (reactions) {
            _context.next = 10;
            break;
          }
          return _context.abrupt("return", null);
        case 10:
          if (!(reactions.length === 0)) {
            _context.next = 12;
            break;
          }
          return _context.abrupt("return", []);
        case 12:
          return _context.abrupt("return", (0, _getReactions.getReactions)({
            reactions: reactions
          }));
        case 13:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
  return function getReactionsForFilterSort(_x) {
    return _ref2.apply(this, arguments);
  };
}();
//# sourceMappingURL=getReactionsforFilterSort.js.map