'use strict';

const Redis = require('ioredis');
const Rx = require('rx');
const config = require('./config');

const CHATS_SET_KEY = 'chats';

class BotRepository {
  constructor() {
    this.redis = new Redis({
      port: config.redis.port,
      host: config.redis.host,
      password: config.redis.password
    });
  }

  addChat(chatId) {
    this.redis.sadd(CHATS_SET_KEY, chatId);
  };

  delChat(chatId) {
    this.redis.srem(CHATS_SET_KEY, chatId);
  };

  getAllChats() {
    return Rx.Observable.fromPromise(this.redis.smembers(CHATS_SET_KEY))
      .flatMap(el => el);
  }

}

module.exports = BotRepository;

@@ -135,16 +135,59 @@
 'chats';
+%0Aconst LAST_POLLED_DATE = 'lastPolledDate';
 %0A%0Aclass 
@@ -425,25 +425,24 @@
 chatId);%0A  %7D
-;
 %0A%0A  delChat(
@@ -498,17 +498,16 @@
 Id);%0A  %7D
-;
 %0A%0A  getA
@@ -591,16 +591,16 @@
 T_KEY))%0A
-
       .f
@@ -622,16 +622,196 @@
 );%0A  %7D%0A%0A
+  getLastPolledDate() %7B%0A    return Rx.Observable.fromPromise(this.redis.get(LAST_POLLED_DATE));%0A  %7D%0A%0A  setLastPolledDate() %7B%0A    this.redis.set(LAST_POLLED_DATE, new Date());%0A  %7D%0A%0A
 %7D%0A%0Amodul

add polling persistance methods