"use strict";

const Promise = require("bluebird");
const mmStreamEvents = require("./");
const pipe = require("@promistream/pipe");
const simpleSink = require("@promistream/simple-sink");
const filter = require("@promistream/filter");

const mapEvent = require("../map-event");
const createSession = require("../../../../create-session");


// let session = {
// 	homeserver: "https://pixie.town",
// 	accessToken: require("../../../private/access-token")
// };

// let since = "s14011802_60514432_167714_6077759_745604_385_21833_2919406_36";
// let since = "s14886247_62932075_392219_6368720_764854_404_25467_3352546_36";
// let since = "s15392233_64465400_3129_6507625_778028_404_26822_3668302_36";
let since = "s15508519_65086739_41448_6548141_783165_404_27201_3802507_36";

return Promise.try(() => {
	return createSession("https://pixie.town", {
		accessToken: require("../../../private/access-token")
	});
}).then((session) => {
	return pipe([
		mmStreamEvents(session, since, { initialLimit: 50, eventMapper: mapEvent }),
		filter((event) => event.type === "roomTimelineEvent"),
		simpleSink((event) => console.log(event))
	]).read();
}).then(() => {
	console.log("Done");
});
