<commit_before>import firebase from 'firebase'
import GeoFire from 'geofire'
import MapManager from '../Containers/Map/MapManager'
import * as Actions from '../Actions'
import Store from '../Store'
import {Platform} from 'react-native'
import RNFetchBlob from 'react-native-fetch-blob'

const Blob = RNFetchBlob.polyfill.Blob
const fs = RNFetchBlob.fs
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
window.Blob = Blob

class FirebaseDao {
	
	static instance = null;
	
	constructor() {
		if (FirebaseDao.instance == null) {
			FirebaseDao.instance = this;
			this._geofire = null
			this._initGeofire();
			this._geofireQuery = null;
			this._initStore()
			this._mapManager = new MapManager()
		}
		return FirebaseDao.instance;
	}
	
	async _initStore() {
		this.store = await Store()
		// this.store.subscribe(() => this._storeListener())
	}
	
	// _storeListener() {
	//
	// }
	
	updateLocation(latitude, longitude) {
		// console.warn("location updated to lat: " + latitude + ", long: " + longitude)
		if (!this._geofireQuery) {
			this._geofireQuery = this._geofire.query({
				center: [latitude, longitude],
				radius: 0.1
			})
			this._geofireQuery.on('key_entered', (key) => {
				this._setMarkerVisible(key)
			})
			this._geofireQuery.on('key_exited', (key) => {
				this._setMarkerHidden(key)
			})
		} else {
			this._geofireQuery.updateCriteria({center: [latitude, longitude]})
		}
	}
	
	_initGeofire() {
		let reference = firebase.database().ref("/markers/markers_locations")
		this._geofire = new GeoFire(reference)
	}
	
	async addUser() {
		let reference = await firebase.database().ref("/users/" + firebase.auth().currentUser.uid)
		reference.set({
			email: firebase.auth().currentUser.email
		})
	}
	
	async addMarker(marker) {
		marker = await this._addInfoToMarker(marker)
		let markers = await firebase.database().ref("/markers/markers_info")
		let markerRef = await markers.push()
		let key = markerRef.key
		await markerRef.set(marker)
		this._addGeofireLocation(key, marker.latitude, marker.longitude)
		this._addMarkerToCurrentUser(key)
		if (marker.images.length > 0) {
			marker.images = await this._uploadImages(key, marker.images)
			await markerRef.set(marker)
		}
	}
	
	async _addInfoToMarker(marker) {
		let currentUser = await this.getCurrentUser()
		marker = {
			...marker,
			creationInfo: {<commit_msg>one set per new marker<commit_after>import firebase from 'firebase'
import GeoFire from 'geofire'
import MapManager from '../Containers/Map/MapManager'
import * as Actions from '../Actions'
import Store from '../Store'
import {Platform} from 'react-native'
import RNFetchBlob from 'react-native-fetch-blob'

const Blob = RNFetchBlob.polyfill.Blob
const fs = RNFetchBlob.fs
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
window.Blob = Blob

class FirebaseDao {
	
	static instance = null;
	
	constructor() {
		if (FirebaseDao.instance == null) {
			FirebaseDao.instance = this;
			this._geofire = null
			this._initGeofire();
			this._geofireQuery = null;
			this._initStore()
			this._mapManager = new MapManager()
		}
		return FirebaseDao.instance;
	}
	
	async _initStore() {
		this.store = await Store()
		// this.store.subscribe(() => this._storeListener())
	}
	
	// _storeListener() {
	//
	// }
	
	updateLocation(latitude, longitude) {
		// console.warn("location updated to lat: " + latitude + ", long: " + longitude)
		if (!this._geofireQuery) {
			this._geofireQuery = this._geofire.query({
				center: [latitude, longitude],
				radius: 0.1
			})
			this._geofireQuery.on('key_entered', (key) => {
				this._setMarkerVisible(key)
			})
			this._geofireQuery.on('key_exited', (key) => {
				this._setMarkerHidden(key)
			})
		} else {
			this._geofireQuery.updateCriteria({center: [latitude, longitude]})
		}
	}
	
	_initGeofire() {
		let reference = firebase.database().ref("/markers/markers_locations")
		this._geofire = new GeoFire(reference)
	}
	
	async addUser() {
		let reference = await firebase.database().ref("/users/" + firebase.auth().currentUser.uid)
		reference.set({
			email: firebase.auth().currentUser.email
		})
	}
	
	async addMarker(marker) {
		marker = await this._addInfoToMarker(marker)
		let markers = await firebase.database().ref("/markers/markers_info")
		let markerRef = await markers.push()
		let key = markerRef.key
		this._addGeofireLocation(key, marker.latitude, marker.longitude)
		this._addMarkerToCurrentUser(key)
		if (marker.images.length > 0) {
			marker.images = await this._uploadImages(key, marker.images)
		}
		markerRef.set(marker)
	}
	
	async _addInfoToMarker(marker) {
		let currentUser = await this.getCurrentUser()
		marker = {
			...marker,
			creationInfo: {
{'fraction_non_alphanumeric': 0.13537211291702309, 'fraction_numerical': 0.0012831479897348161, 'mean_word_length': 3.91281512605042, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7431049', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1541, 'n_words': 309}