Created
March 18, 2019 15:24
-
-
Save yurafuca/f91622c6fd8cd4dc99d0aecf2c6de10c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { interval, Subject } from 'rxjs'; | |
| import {filter} from "rxjs/operators"; | |
| import bucket from "./Bucket"; | |
| import {Poster} from "./NoticeLetter"; | |
| import store from "store"; | |
| import Api from '../api/Api'; | |
| import { CommunityBuilder, ProgramBuilder } from './CheckableBuilder'; | |
| const AUTOMATIC_VISITING_KEY = "autoEnterProgramList"; | |
| interval(1000 * 30).subscribe( | |
| _ => { | |
| const communities = bucket.communitiesShouldPoll(); | |
| communities.forEach((community, i) => { | |
| const delay = i * 3000; | |
| setTimeout(() => { | |
| Api.isOpen(community.id).then(result => { | |
| if (result.isOpen) { | |
| // Build Manageable objects. | |
| const communityBuilder = new CommunityBuilder() | |
| .id(community.id); | |
| const programBuilder = new ProgramBuilder() | |
| .id(result.nextLiveId) | |
| .title(result.title) | |
| .isVisiting(false) | |
| .shouldOpenAutomatically(true); | |
| // Assign. | |
| bucket.assign(communityBuilder, programBuilder); | |
| } | |
| }) | |
| }, delay); | |
| }); | |
| } | |
| ); | |
| interval(1000).subscribe( | |
| _ => { | |
| const programs = bucket.programsShouldPoll(); | |
| programs.forEach(program => { | |
| const programsShouldOpen = store.get(AUTOMATIC_VISITING_KEY, {}); | |
| const openDate = programsShouldOpen[program.id] && programsShouldOpen[program.id].openDate; | |
| const isStarted = new Date(openDate) < new Date(); | |
| if (isStarted) { | |
| const builder = new ProgramBuilder().id(program.id); | |
| bucket.assignOrphan(builder); | |
| } | |
| }); | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment