Move all firbase dependencies from actions layer to firebaseService layer (#13)
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
// - Import react components
|
// - Import react components
|
||||||
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import { push } from 'react-router-redux'
|
import { push } from 'react-router-redux'
|
||||||
|
|
||||||
@@ -12,8 +11,7 @@ import { AuthorizeActionType } from 'constants/authorizeActionType'
|
|||||||
|
|
||||||
// - Import services
|
// - Import services
|
||||||
import { IAuthorizeService } from 'services/authorize'
|
import { IAuthorizeService } from 'services/authorize'
|
||||||
import { IServiceProvider } from 'factories'
|
import { IServiceProvider, ServiceProvide } from 'factories'
|
||||||
import { ServiceProvide } from 'factories'
|
|
||||||
|
|
||||||
const serviceProvider: IServiceProvider = new ServiceProvide()
|
const serviceProvider: IServiceProvider = new ServiceProvide()
|
||||||
const authorizeService: IAuthorizeService = serviceProvider.createAuthorizeService()
|
const authorizeService: IAuthorizeService = serviceProvider.createAuthorizeService()
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
// - Import firebase component
|
|
||||||
import firebase, { firebaseRef } from 'app/firebase/'
|
|
||||||
|
|
||||||
// - Import domain
|
// - Import domain
|
||||||
import { User } from 'domain/users'
|
import { User } from 'domain/users'
|
||||||
import { Circle, UserFollower } from 'domain/circles'
|
import { Circle, UserFollower } from 'domain/circles'
|
||||||
|
import { SocialError } from 'domain/common'
|
||||||
|
|
||||||
// - Import utility components
|
// - Import utility components
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
@@ -11,23 +9,23 @@ import moment from 'moment'
|
|||||||
// - Import action types
|
// - Import action types
|
||||||
import { CircleActionType } from 'constants/circleActionType'
|
import { CircleActionType } from 'constants/circleActionType'
|
||||||
|
|
||||||
|
|
||||||
// - Import actions
|
// - Import actions
|
||||||
import * as globalActions from 'actions/globalActions'
|
import * as globalActions from 'actions/globalActions'
|
||||||
import * as postActions from 'actions/postActions'
|
import * as postActions from 'actions/postActions'
|
||||||
import * as userActions from 'actions/userActions'
|
import * as userActions from 'actions/userActions'
|
||||||
import * as notifyActions from 'actions/notifyActions'
|
import * as notifyActions from 'actions/notifyActions'
|
||||||
|
|
||||||
|
import { IServiceProvider,ServiceProvide } from 'factories'
|
||||||
|
import { ICircleService } from 'services/circles'
|
||||||
|
|
||||||
|
const serviceProvider: IServiceProvider = new ServiceProvide()
|
||||||
|
const circleService: ICircleService = serviceProvider.createCircleService()
|
||||||
|
|
||||||
/* _____________ CRUD DB _____________ */
|
/* _____________ CRUD DB _____________ */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a circle
|
* Add a circle
|
||||||
* @param {string} circleName
|
* @param {string} circleName
|
||||||
*/
|
*/
|
||||||
export let dbAddCircle = (circleName: string) => {
|
export let dbAddCircle = (circleName: string) => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
@@ -38,21 +36,19 @@ export let dbAddCircle = (circleName: string) => {
|
|||||||
name: circleName,
|
name: circleName,
|
||||||
users: {}
|
users: {}
|
||||||
}
|
}
|
||||||
|
return circleService.addCircle(uid,circle).then((circleKey: string) => {
|
||||||
let circleRef = firebaseRef.child(`userCircles/${uid}/circles`).push(circle)
|
circle.id = circleKey
|
||||||
return circleRef.then(() => {
|
|
||||||
circle.id = circleRef.key
|
|
||||||
circle.ownerId = uid
|
circle.ownerId = uid
|
||||||
dispatch(addCircle(circle))
|
dispatch(addCircle(circle))
|
||||||
|
|
||||||
}, (error) => dispatch(globalActions.showErrorMessage(error.message)))
|
}, (error: SocialError) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a user in a circle
|
* Add a user in a circle
|
||||||
* @param {string} cid is circle identifier
|
* @param {string} cid is circle identifier
|
||||||
* @param {User} userFollowing is the user for following
|
* @param {User} userFollowing is the user for following
|
||||||
*/
|
*/
|
||||||
export let dbAddFollowingUser = (cid: string, userFollowing: User) => {
|
export let dbAddFollowingUser = (cid: string, userFollowing: User) => {
|
||||||
@@ -72,46 +68,42 @@ export let dbAddFollowingUser = (cid: string, userFollowing: User) => {
|
|||||||
avatar: user.avatar || '',
|
avatar: user.avatar || '',
|
||||||
approved: false
|
approved: false
|
||||||
}
|
}
|
||||||
let updates: any = {}
|
|
||||||
updates[`userCircles/${uid}/circles/${cid}/users/${userFollowing.userId}`] = userCircle
|
|
||||||
updates[`userCircles/${userFollowing.userId}/circles/-Followers/users/${uid}`] = userFollower
|
|
||||||
return firebaseRef.update(updates).then((result) => {
|
|
||||||
dispatch(addFollowingUser(uid, cid, userFollowing.userId as string, { ...userCircle } as User))
|
|
||||||
|
|
||||||
dispatch(notifyActions.dbAddNotify(
|
return circleService.addFollowingUser(uid,cid,userCircle,userFollower,userFollowing.userId as string)
|
||||||
{
|
.then(() => {
|
||||||
description: `${user.fullName} follow you.`,
|
dispatch(addFollowingUser(uid, cid, userFollowing.userId as string, { ...userCircle } as User))
|
||||||
url: `/${uid}`,
|
|
||||||
notifyRecieverUserId: userFollowing.userId as string,
|
|
||||||
notifierUserId: uid,
|
|
||||||
isSeen:false
|
|
||||||
}))
|
|
||||||
|
|
||||||
}, (error) => {
|
dispatch(notifyActions.dbAddNotification(
|
||||||
dispatch(globalActions.showErrorMessage(error.message))
|
{
|
||||||
})
|
description: `${user.fullName} follow you.`,
|
||||||
|
url: `/${uid}`,
|
||||||
|
notifyRecieverUserId: userFollowing.userId as string,
|
||||||
|
notifierUserId: uid,
|
||||||
|
isSeen: false
|
||||||
|
}))
|
||||||
|
|
||||||
|
}, (error: SocialError) => {
|
||||||
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a user from a circle
|
* Delete a user from a circle
|
||||||
* @param {string} cid is circle identifier
|
* @param {string} cid is circle identifier
|
||||||
* @param {string} followingId following user identifier
|
* @param {string} userFollowingId following user identifier
|
||||||
*/
|
*/
|
||||||
export let dbDeleteFollowingUser = (cid: string, followingId: string) => {
|
export let dbDeleteFollowingUser = (cid: string, userFollowingId: string) => {
|
||||||
return (dispatch: any, getState:Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
|
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
|
|
||||||
let updates: any = {}
|
return circleService.deleteFollowingUser(uid,cid,userFollowingId)
|
||||||
updates[`userCircles/${uid}/circles/${cid}/users/${followingId}`] = null
|
.then(() => {
|
||||||
updates[`userCircles/${followingId}/circles/-Followers/users/${uid}`] = null
|
dispatch(deleteFollowingUser(uid, cid, userFollowingId))
|
||||||
return firebaseRef.update(updates).then((result) => {
|
}, (error: SocialError) => {
|
||||||
dispatch(deleteFollowingUser(uid, cid, followingId))
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
}, (error) => {
|
})
|
||||||
dispatch(globalActions.showErrorMessage(error.message))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,23 +118,21 @@ export const dbUpdateCircle = (newCircle: Circle) => {
|
|||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
|
|
||||||
// Write the new data simultaneously in the list
|
// Write the new data simultaneously in the list
|
||||||
let updates: any = {}
|
|
||||||
let circle: Circle = getState().circle.userCircles[uid][newCircle.id!]
|
let circle: Circle = getState().circle.userCircles[uid][newCircle.id!]
|
||||||
let updatedCircle : Circle = {
|
let updatedCircle: Circle = {
|
||||||
name: newCircle.name || circle.name,
|
name: newCircle.name || circle.name,
|
||||||
users: newCircle.users ? newCircle.users : (circle.users || [])
|
users: newCircle.users ? newCircle.users : (circle.users || [])
|
||||||
}
|
}
|
||||||
updates[`userCircles/${uid}/circles/${newCircle.id}`] = updatedCircle
|
return circleService.updateCircle(uid,newCircle.id!,circle)
|
||||||
return firebaseRef.update(updates).then(() => {
|
.then(() => {
|
||||||
dispatch(updateCircle(uid,{ id: newCircle.id, ...updatedCircle }))
|
dispatch(updateCircle(uid,{ id: newCircle.id, ...updatedCircle }))
|
||||||
}, (error) => {
|
}, (error: SocialError) => {
|
||||||
dispatch(globalActions.showErrorMessage(error.message))
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a circle from database
|
* Delete a circle from database
|
||||||
* @param {string} id is circle identifier
|
* @param {string} id is circle identifier
|
||||||
@@ -153,15 +143,12 @@ export const dbDeleteCircle = (id: string) => {
|
|||||||
// Get current user id
|
// Get current user id
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
|
|
||||||
// Write the new data simultaneously in the list
|
return circleService.deleteCircle(uid,id)
|
||||||
let updates: any = {}
|
.then(() => {
|
||||||
updates[`userCircles/${uid}/circles/${id}`] = null
|
dispatch(deleteCircle(uid, id))
|
||||||
|
}, (error: SocialError) => {
|
||||||
return firebaseRef.update(updates).then((result) => {
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
dispatch(deleteCircle(uid, id))
|
})
|
||||||
}, (error) => {
|
|
||||||
dispatch(globalActions.showErrorMessage(error.message))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -173,32 +160,28 @@ export const dbGetCircles = () => {
|
|||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let circlesRef: any = firebaseRef.child(`userCircles/${uid}/circles`)
|
|
||||||
|
|
||||||
return circlesRef.once('value').then((snapshot: any) => {
|
return circleService.getCircles(uid)
|
||||||
let circles: any = snapshot.val() || {}
|
.then((circles: { [circleId: string]: Circle }) => {
|
||||||
let parsedCircles: { [circleId: string]: Circle } = {}
|
Object.keys(circles).forEach((circleId) => {
|
||||||
Object.keys(circles).forEach((circleId) => {
|
if (circleId !== '-Followers' && circles[circleId].users) {
|
||||||
if (circleId !== '-Followers' && circles[circleId].users) {
|
Object.keys(circles[circleId].users).filter((v, i, a) => a.indexOf(v) === i).forEach((userId) => {
|
||||||
Object.keys(circles[circleId].users).filter((v, i, a) => a.indexOf(v) === i).forEach((userId) => {
|
dispatch(postActions.dbGetPostsByUserId(userId))
|
||||||
dispatch(postActions.dbGetPostsByUserId(userId))
|
dispatch(userActions.dbGetUserInfoByUserId(userId, ''))
|
||||||
dispatch(userActions.dbGetUserInfoByUserId(userId, ''))
|
})
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
parsedCircles[circleId] = {
|
|
||||||
id: circleId,
|
dispatch(addCircles(uid, circles))
|
||||||
...circles[circleId]
|
})
|
||||||
}
|
.catch((error: SocialError) => {
|
||||||
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
})
|
})
|
||||||
|
|
||||||
dispatch(addCircles(uid, parsedCircles))
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all user circles from data base by user id
|
* Get all user circles from data base by user id
|
||||||
* @param uid user identifier
|
* @param uid user identifier
|
||||||
@@ -207,35 +190,23 @@ export const dbGetCirclesByUserId = (uid: string) => {
|
|||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
|
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let circlesRef = firebaseRef.child(`userCircles/${uid}/circles`)
|
return circleService.getCircles(uid)
|
||||||
|
.then((circles: { [circleId: string]: Circle }) => {
|
||||||
return circlesRef.once('value').then((snapshot) => {
|
dispatch(addCircles(uid, circles))
|
||||||
let circles = snapshot.val() || {}
|
})
|
||||||
let parsedCircles: { [circleId: string]: Circle } = {}
|
.catch((error: SocialError) => {
|
||||||
Object.keys(circles).forEach((circleId) => {
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
parsedCircles[circleId] = {
|
})
|
||||||
id: circleId,
|
|
||||||
...circles[circleId]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
dispatch(addCircles(uid, parsedCircles))
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* _____________ CRUD State _____________ */
|
/* _____________ CRUD State _____________ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a normal circle
|
* Add a normal circle
|
||||||
* @param {string} uid is user identifier
|
* @param {string} uid is user identifier
|
||||||
* @param {Circle} circle
|
* @param {Circle} circle
|
||||||
*/
|
*/
|
||||||
export const addCircle = (circle: Circle) => {
|
export const addCircle = (circle: Circle) => {
|
||||||
return {
|
return {
|
||||||
@@ -247,7 +218,7 @@ export const addCircle = (circle: Circle) => {
|
|||||||
/**
|
/**
|
||||||
* Update a circle
|
* Update a circle
|
||||||
* @param {string} uid is user identifier
|
* @param {string} uid is user identifier
|
||||||
* @param {Circle} circle
|
* @param {Circle} circle
|
||||||
*/
|
*/
|
||||||
export const updateCircle = (uid: string, circle: Circle) => {
|
export const updateCircle = (uid: string, circle: Circle) => {
|
||||||
return {
|
return {
|
||||||
@@ -268,11 +239,10 @@ export const deleteCircle = (uid: string, id: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a list of circle
|
* Add a list of circle
|
||||||
* @param {string} uid
|
* @param {string} uid
|
||||||
* @param {circleId: string]: Circle} circles
|
* @param {circleId: string]: Circle} circles
|
||||||
*/
|
*/
|
||||||
export const addCircles = (uid: string, circles: { [circleId: string]: Circle }) => {
|
export const addCircles = (uid: string, circles: { [circleId: string]: Circle }) => {
|
||||||
return {
|
return {
|
||||||
@@ -290,7 +260,6 @@ export const clearAllCircles = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open circle settings
|
* Open circle settings
|
||||||
* @param uid user idenifier
|
* @param uid user idenifier
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// - Import react components
|
// - Import react components
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import { firebaseRef } from 'app/firebase/'
|
|
||||||
|
|
||||||
// - Import domain
|
// - Import domain
|
||||||
import { Comment } from 'domain/comments'
|
import { Comment } from 'domain/comments'
|
||||||
|
import { SocialError } from 'domain/common'
|
||||||
|
|
||||||
// - Import action types
|
// - Import action types
|
||||||
import { CommentActionType } from 'constants/commentActionType'
|
import { CommentActionType } from 'constants/commentActionType'
|
||||||
@@ -12,6 +12,12 @@ import { CommentActionType } from 'constants/commentActionType'
|
|||||||
import * as globalActions from 'actions/globalActions'
|
import * as globalActions from 'actions/globalActions'
|
||||||
import * as notifyActions from 'actions/notifyActions'
|
import * as notifyActions from 'actions/notifyActions'
|
||||||
|
|
||||||
|
import { IServiceProvider, ServiceProvide } from 'factories'
|
||||||
|
import { ICommentService } from 'services/comments'
|
||||||
|
|
||||||
|
const serviceProvider: IServiceProvider = new ServiceProvide()
|
||||||
|
const commentService: ICommentService = serviceProvider.createCommentService()
|
||||||
|
|
||||||
/* _____________ CRUD DB _____________ */
|
/* _____________ CRUD DB _____________ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,28 +43,27 @@ export const dbAddComment = (ownerPostUserId: string,newComment: Comment, callBa
|
|||||||
text: newComment.text
|
text: newComment.text
|
||||||
}
|
}
|
||||||
|
|
||||||
let commentRef: any = firebaseRef.child(`postComments/${newComment.postId}`).push(comment)
|
return commentService.addComment(newComment.postId,comment)
|
||||||
return commentRef.then(() => {
|
.then((commentKey: string) => {
|
||||||
dispatch(addComment(newComment))
|
dispatch(addComment({id: commentKey! ,...comment}))
|
||||||
callBack()
|
callBack()
|
||||||
dispatch(globalActions.hideTopLoading())
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
|
||||||
if (ownerPostUserId && ownerPostUserId !== uid) {
|
if (ownerPostUserId && ownerPostUserId !== uid) {
|
||||||
dispatch(notifyActions.dbAddNotify(
|
dispatch(notifyActions.dbAddNotification(
|
||||||
{
|
{
|
||||||
description: 'Add comment on your post.',
|
description: 'Add comment on your post.',
|
||||||
url: `/${ownerPostUserId}/posts/${newComment.postId}`,
|
url: `/${ownerPostUserId}/posts/${comment.postId}`,
|
||||||
notifyRecieverUserId: ownerPostUserId, notifierUserId: uid,
|
notifyRecieverUserId: ownerPostUserId, notifierUserId: uid,
|
||||||
isSeen: false
|
isSeen: false
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
}, (error: any) => {
|
}, (error: SocialError) => {
|
||||||
dispatch(globalActions.showErrorMessage(error.message))
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
dispatch(globalActions.hideTopLoading())
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,14 +74,14 @@ export const dbGetComments = () => {
|
|||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let commentsRef: any = firebaseRef.child(`postComments`)
|
|
||||||
|
|
||||||
return commentsRef.on('value', (snapshot: any) => {
|
return commentService.getComments()
|
||||||
let comments: {[postId: string]: {[commentId: string]: Comment}} = snapshot!.val() || {}
|
.then((comments: {[postId: string]: {[commentId: string]: Comment}}) => {
|
||||||
dispatch(addCommentList(comments))
|
dispatch(addCommentList(comments))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
.catch((error: SocialError) => {
|
||||||
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,9 +101,8 @@ export const dbUpdateComment = (id: string, postId: string, text: string) => {
|
|||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
|
|
||||||
// Write the new data simultaneously in the list
|
// Write the new data simultaneously in the list
|
||||||
let updates: any = {}
|
|
||||||
let comment: Comment = getState().comment.postComments[postId][id]
|
let comment: Comment = getState().comment.postComments[postId][id]
|
||||||
updates[`postComments/${postId}/${id}`] = {
|
let updatedComment: Comment = {
|
||||||
postId: postId,
|
postId: postId,
|
||||||
score: comment.score,
|
score: comment.score,
|
||||||
text: text,
|
text: text,
|
||||||
@@ -107,15 +111,17 @@ export const dbUpdateComment = (id: string, postId: string, text: string) => {
|
|||||||
userAvatar: comment.userAvatar,
|
userAvatar: comment.userAvatar,
|
||||||
userId: uid
|
userId: uid
|
||||||
}
|
}
|
||||||
return firebaseRef.update(updates).then((result) => {
|
|
||||||
dispatch(updateComment( id, postId, text))
|
|
||||||
dispatch(globalActions.hideTopLoading())
|
|
||||||
|
|
||||||
}, (error) => {
|
return commentService.updateComment(uid,postId,updatedComment)
|
||||||
dispatch(globalActions.showErrorMessage(error.message))
|
.then(() => {
|
||||||
dispatch(globalActions.hideTopLoading())
|
dispatch(updateComment( id, postId, text))
|
||||||
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
|
||||||
})
|
}, (error: SocialError) => {
|
||||||
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -128,24 +134,28 @@ export const dbUpdateComment = (id: string, postId: string, text: string) => {
|
|||||||
export const dbDeleteComment = (id: string, postId: string) => {
|
export const dbDeleteComment = (id: string, postId: string) => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
|
|
||||||
|
if (id === undefined || id === null) {
|
||||||
|
dispatch(globalActions.showErrorMessage('comment id can not be null or undefined'))
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('====================================')
|
||||||
|
console.log(id,postId)
|
||||||
|
console.log('====================================')
|
||||||
dispatch(globalActions.showTopLoading())
|
dispatch(globalActions.showTopLoading())
|
||||||
|
|
||||||
// Get current user id
|
// Get current user id
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
|
|
||||||
// Write the new data simultaneously in the list
|
return commentService.deleteComment(id,postId)
|
||||||
let updates: any = {}
|
.then(() => {
|
||||||
updates[`postComments/${postId}/${id}`] = null
|
dispatch(deleteComment(id, postId))
|
||||||
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
|
||||||
return firebaseRef.update(updates).then((result) => {
|
}, (error: SocialError) => {
|
||||||
dispatch(deleteComment(id, postId))
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
dispatch(globalActions.hideTopLoading())
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
|
||||||
}, (error) => {
|
})
|
||||||
dispatch(globalActions.showErrorMessage(error.message))
|
|
||||||
dispatch(globalActions.hideTopLoading())
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// - Import image gallery action types
|
// - Import image gallery action types
|
||||||
import {GlobalActionType} from 'constants/globalActionType'
|
import { GlobalActionType } from 'constants/globalActionType'
|
||||||
|
|
||||||
// - Import actions
|
// - Import actions
|
||||||
import * as postActions from 'actions/postActions'
|
import * as postActions from 'actions/postActions'
|
||||||
@@ -8,8 +8,8 @@ import * as userActions from 'actions/userActions'
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Progress change
|
* Progress change
|
||||||
* @param {string} percent
|
* @param {string} percent
|
||||||
* @param {boolean} visible
|
* @param {boolean} visible
|
||||||
*/
|
*/
|
||||||
export const progressChange = (percent: number, visible: Boolean) => {
|
export const progressChange = (percent: number, visible: Boolean) => {
|
||||||
return {
|
return {
|
||||||
@@ -38,16 +38,15 @@ export const defaultDataDisable = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// - Show notification of request
|
// - Show notification of request
|
||||||
export const showNotificationRequest = () => {
|
export const showNotificationRequest = () => {
|
||||||
return{
|
return{
|
||||||
type: GlobalActionType.SHOW_SEND_REQUEST_MESSAGE_GLOBAL
|
type: GlobalActionType.SHOW_SEND_REQUEST_MESSAGE_GLOBAL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// - Show notification of success
|
// - Show notification of success
|
||||||
export const showNotificationSuccess = () => {
|
export const showNotificationSuccess = () => {
|
||||||
return{
|
return{
|
||||||
type: GlobalActionType.SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL
|
type: GlobalActionType.SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL
|
||||||
}
|
}
|
||||||
@@ -65,9 +64,9 @@ export const hideMessage = () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Show error message
|
* Show error message
|
||||||
* @param {string} message
|
* @param {string} message
|
||||||
*/
|
*/
|
||||||
export const showErrorMessage = (message: string) => {
|
export const showErrorMessage = (message: string) => {
|
||||||
return {
|
return {
|
||||||
type: GlobalActionType.SHOW_ERROR_MESSAGE_GLOBAL,
|
type: GlobalActionType.SHOW_ERROR_MESSAGE_GLOBAL,
|
||||||
payload: message
|
payload: message
|
||||||
@@ -85,7 +84,6 @@ export const setHeaderTitleOpt = (callerKey: string,payload: any) => {
|
|||||||
const userName = getState().user.info && getState().user.info[payload] ? getState().user.info[payload].fullName : ''
|
const userName = getState().user.info && getState().user.info[payload] ? getState().user.info[payload].fullName : ''
|
||||||
dispatch(setHeaderTitle(userName))
|
dispatch(setHeaderTitle(userName))
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -145,9 +143,6 @@ export const hideTopLoading = () => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store temp data
|
* Store temp data
|
||||||
*/
|
*/
|
||||||
@@ -159,11 +154,10 @@ export const temp = (data: string) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// - Load data for guest
|
// - Load data for guest
|
||||||
export const loadDataGuest = () => {
|
export const loadDataGuest = () => {
|
||||||
|
// tslint:disable-next-line:no-empty
|
||||||
return (dispatch: any,getState: Function) => {
|
return (dispatch: any,getState: Function) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// - Import react componetns
|
// - Import react componetns
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import { firebaseRef, firebaseAuth, storageRef } from 'app/firebase/'
|
|
||||||
|
|
||||||
// - Import domain
|
// - Import domain
|
||||||
import { Image } from 'domain/imageGallery'
|
import { Image } from 'domain/imageGallery'
|
||||||
|
import { SocialError } from 'domain/common'
|
||||||
|
|
||||||
// - Import action types
|
// - Import action types
|
||||||
import { ImageGalleryActionType } from 'constants/imageGalleryActionType'
|
import { ImageGalleryActionType } from 'constants/imageGalleryActionType'
|
||||||
@@ -14,29 +14,29 @@ import * as globalActions from 'actions/globalActions'
|
|||||||
// - Import app API
|
// - Import app API
|
||||||
import FileAPI from 'api/FileAPI'
|
import FileAPI from 'api/FileAPI'
|
||||||
|
|
||||||
|
import { IServiceProvider, ServiceProvide } from 'factories'
|
||||||
|
import { IImageGalleryService } from 'services/imageGallery'
|
||||||
|
|
||||||
|
const serviceProvider: IServiceProvider = new ServiceProvide()
|
||||||
|
const imageGalleryService: IImageGalleryService = serviceProvider.createImageGalleryService()
|
||||||
|
|
||||||
/* _____________ UI Actions _____________ */
|
/* _____________ UI Actions _____________ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download images for image gallery
|
* Download images for image gallery
|
||||||
*/
|
*/
|
||||||
export const downloadForImageGallery = () => {
|
export const dbGetImageGallery = () => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let imagesRef: any = firebaseRef.child(`userFiles/${uid}/files/images`)
|
|
||||||
|
|
||||||
return imagesRef.once('value').then((snapshot: any) => {
|
return imageGalleryService.getImageGallery(uid)
|
||||||
let images = snapshot.val() || {}
|
.then((images: Image[]) => {
|
||||||
let parsedImages: Image[] = []
|
dispatch(addImageList(images))
|
||||||
Object.keys(images).forEach((imageId) => {
|
})
|
||||||
parsedImages.push({
|
.catch((error: SocialError) => {
|
||||||
id: imageId,
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
...images[imageId]
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
dispatch(addImageList(parsedImages))
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,15 +62,16 @@ export const dbSaveImage = (imageURL: string,imageFullPath: string) => {
|
|||||||
lastEditDate: 0,
|
lastEditDate: 0,
|
||||||
deleted: false
|
deleted: false
|
||||||
}
|
}
|
||||||
|
return imageGalleryService.saveImage(uid,image)
|
||||||
let imageRef = firebaseRef.child(`userFiles/${uid}/files/images`).push(image)
|
.then((imageKey: string) => {
|
||||||
return imageRef.then(() => {
|
dispatch(addImage({
|
||||||
dispatch(addImage({
|
...image,
|
||||||
...image,
|
id: imageKey
|
||||||
id: imageRef.key
|
}))
|
||||||
}))
|
})
|
||||||
})
|
.catch((error: SocialError) => {
|
||||||
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,16 +85,13 @@ export const dbDeleteImage = (id: string) => {
|
|||||||
// Get current user id
|
// Get current user id
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
|
|
||||||
// Write the new data simultaneously in the list
|
return imageGalleryService.deleteImage(uid,id)
|
||||||
let updates: any = {}
|
.then(() => {
|
||||||
updates[`userFiles/${uid}/files/images/${id}`] = null
|
dispatch(deleteImage(id))
|
||||||
|
})
|
||||||
return firebaseRef.update(updates).then((result) => {
|
.catch((error: SocialError) => {
|
||||||
dispatch(deleteImage(id))
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
console.log('image removed: ', id)
|
})
|
||||||
}, (error) => {
|
|
||||||
console.log(error)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -105,27 +103,19 @@ export const dbDeleteImage = (id: string) => {
|
|||||||
*/
|
*/
|
||||||
export const dbUploadImage = (file: any, fileName: string) => {
|
export const dbUploadImage = (file: any, fileName: string) => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
// Create a storage refrence
|
|
||||||
let storegeFile: any = storageRef.child(`images/${fileName}`)
|
|
||||||
|
|
||||||
// Upload file
|
return imageGalleryService
|
||||||
let task: any = storegeFile.put(file)
|
.uploadImage(file,fileName, (percentage: number) => {
|
||||||
dispatch(globalActions.showTopLoading())
|
|
||||||
|
|
||||||
// Upload storage bar
|
|
||||||
task.on('state_changed', (snapshot: any) => {
|
|
||||||
let percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100
|
|
||||||
dispatch(globalActions.progressChange(percentage, true))
|
dispatch(globalActions.progressChange(percentage, true))
|
||||||
|
})
|
||||||
}, (error: any) => {
|
.then(() => {
|
||||||
dispatch(globalActions.showErrorMessage(error.code))
|
|
||||||
dispatch(globalActions.hideTopLoading())
|
|
||||||
|
|
||||||
}, (complete?: any ) => {
|
|
||||||
dispatch(globalActions.progressChange(100, false))
|
dispatch(globalActions.progressChange(100, false))
|
||||||
dispatch(dbSaveImage(fileName,''))
|
dispatch(dbSaveImage(fileName,''))
|
||||||
dispatch(globalActions.hideTopLoading())
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
})
|
||||||
|
.catch((error: SocialError) => {
|
||||||
|
dispatch(globalActions.showErrorMessage(error.code))
|
||||||
|
dispatch(globalActions.hideTopLoading())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,44 +133,20 @@ export const dbDownloadImage = (fileName: string) => {
|
|||||||
if (getState().imageGallery.imageURLList[fileName] && fileName !== '') {
|
if (getState().imageGallery.imageURLList[fileName] && fileName !== '') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (getState().imageGallery.imageRequests.indexOf(fileName) > -1){
|
if (getState().imageGallery.imageRequests.indexOf(fileName) > -1) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dispatch(sendImageRequest(fileName))
|
dispatch(sendImageRequest(fileName))
|
||||||
|
|
||||||
// Create a reference to the file we want to download
|
return imageGalleryService.downloadImage(fileName)
|
||||||
let starsRef: any = storageRef.child(`images/${fileName}`)
|
.then((url: string) => {
|
||||||
|
|
||||||
// Get the download URL
|
|
||||||
starsRef.getDownloadURL().then((url: string) => {
|
|
||||||
// Insert url into an <img> tag to 'download'
|
// Insert url into an <img> tag to 'download'
|
||||||
if (!getState().imageGallery.imageURLList[fileName] || fileName === '')
|
if (!getState().imageGallery.imageURLList[fileName] || fileName === '') {
|
||||||
dispatch(setImageURL(fileName, url))
|
dispatch(setImageURL(fileName, url))
|
||||||
}).catch((error: any) => {
|
}
|
||||||
|
})
|
||||||
// A full list of error codes is available at
|
.catch((error: SocialError) => {
|
||||||
// https://firebase.google.com/docs/storage/web/handle-errors
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
switch (error.code) {
|
|
||||||
case 'storage/object_not_found':
|
|
||||||
// File doesn't exist
|
|
||||||
dispatch(globalActions.showErrorMessage('storage/object_not_found'))
|
|
||||||
break
|
|
||||||
|
|
||||||
case 'storage/unauthorized':
|
|
||||||
// User doesn't have permission to access the object
|
|
||||||
dispatch(globalActions.showErrorMessage('storage/unauthorized'))
|
|
||||||
break
|
|
||||||
|
|
||||||
case 'storage/canceled':
|
|
||||||
// User canceled the upload
|
|
||||||
dispatch(globalActions.showErrorMessage('storage/canceled'))
|
|
||||||
break
|
|
||||||
|
|
||||||
case 'storage/unknown':
|
|
||||||
// Unknown error occurred, inspect the server response
|
|
||||||
dispatch(globalActions.showErrorMessage('storage/unknown'))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
// - Import react components
|
// - Import react components
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import { firebaseRef } from 'app/firebase/'
|
|
||||||
|
|
||||||
// - Import domain
|
// - Import domain
|
||||||
import { Notification } from 'domain/notifications'
|
import { Notification } from 'domain/notifications'
|
||||||
|
import { SocialError } from 'domain/common'
|
||||||
|
|
||||||
// - Import action types
|
// - Import action types
|
||||||
import {NotificationActionType} from 'constants/notificationActionType'
|
import { NotificationActionType } from 'constants/notificationActionType'
|
||||||
|
|
||||||
// - Import actions
|
// - Import actions
|
||||||
import * as globalActions from 'actions/globalActions'
|
import * as globalActions from 'actions/globalActions'
|
||||||
import * as userActions from 'actions/userActions'
|
import * as userActions from 'actions/userActions'
|
||||||
|
|
||||||
|
import { IServiceProvider, ServiceProvide } from 'factories'
|
||||||
|
import { INotificationService } from 'services/notifications'
|
||||||
|
|
||||||
|
const serviceProvider: IServiceProvider = new ServiceProvide()
|
||||||
|
const notificationService: INotificationService = serviceProvider.createNotificationService()
|
||||||
|
|
||||||
/* _____________ CRUD DB _____________ */
|
/* _____________ CRUD DB _____________ */
|
||||||
|
|
||||||
@@ -19,7 +24,7 @@ import * as userActions from 'actions/userActions'
|
|||||||
* Add notificaition to database
|
* Add notificaition to database
|
||||||
* @param {object} newNotify user notificaition
|
* @param {object} newNotify user notificaition
|
||||||
*/
|
*/
|
||||||
export const dbAddNotify = (newNotify: Notification) => {
|
export const dbAddNotification = (newNotify: Notification) => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
|
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
@@ -32,10 +37,11 @@ export const dbAddNotify = (newNotify: Notification) => {
|
|||||||
notifyRecieverUserId: newNotify.notifyRecieverUserId
|
notifyRecieverUserId: newNotify.notifyRecieverUserId
|
||||||
}
|
}
|
||||||
|
|
||||||
let notifyRef: any = firebaseRef.child(`userNotifies/${newNotify.notifyRecieverUserId}`).push(notify)
|
return notificationService.addNotification(notify)
|
||||||
return notifyRef.then(() => {
|
.then(() => {
|
||||||
dispatch(addNotify())
|
dispatch(addNotify())
|
||||||
}, (error: any) => dispatch(globalActions.showErrorMessage(error.message)))
|
})
|
||||||
|
.catch((error: SocialError) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,84 +49,74 @@ export const dbAddNotify = (newNotify: Notification) => {
|
|||||||
/**
|
/**
|
||||||
* Get all notificaitions from database
|
* Get all notificaitions from database
|
||||||
*/
|
*/
|
||||||
export const dbGetNotifies = () => {
|
export const dbGetNotifications = () => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let notifiesRef: any = firebaseRef.child(`userNotifies/${uid}`)
|
|
||||||
|
|
||||||
return notifiesRef.on('value', (snapshot: any) => {
|
|
||||||
let notifies: {[notifyId: string]: Notification} = snapshot.val() || {}
|
|
||||||
|
|
||||||
Object.keys(notifies).forEach((key => {
|
|
||||||
if (!getState().user.info[notifies[key].notifierUserId]) {
|
|
||||||
dispatch(userActions.dbGetUserInfoByUserId(notifies[key].notifierUserId,''))
|
|
||||||
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
dispatch(addNotifyList(notifies))
|
|
||||||
})
|
|
||||||
|
|
||||||
|
return notificationService.getNotifications(uid)
|
||||||
|
.then((notifies: { [notifyId: string]: Notification }) => {
|
||||||
|
Object.keys(notifies).forEach((key => {
|
||||||
|
if (!getState().user.info[notifies[key].notifierUserId]) {
|
||||||
|
dispatch(userActions.dbGetUserInfoByUserId(notifies[key].notifierUserId,''))
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
dispatch(addNotifyList(notifies))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a notificaition from database
|
* Delete a notificaition from database
|
||||||
* @param {string} id of notificaition
|
* @param {string} id of notificaition
|
||||||
*/
|
*/
|
||||||
export const dbDeleteNotify = (id: string) => {
|
export const dbDeleteNotification = (id: string) => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
|
|
||||||
// Get current user id
|
// Get current user id
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
|
|
||||||
// Write the new data simultaneously in the list
|
return notificationService.deleteNotification(id,uid).then(() => {
|
||||||
let updates: any = {}
|
|
||||||
updates[`userNotifies/${uid}/${id}`] = null
|
|
||||||
|
|
||||||
return firebaseRef.update(updates).then((result) => {
|
|
||||||
dispatch(deleteNotify(id))
|
dispatch(deleteNotify(id))
|
||||||
}, (error) => dispatch(globalActions.showErrorMessage(error.message)))
|
})
|
||||||
|
.catch((error: SocialError) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make seen a notificaition from database
|
* Make seen a notificaition from database
|
||||||
* @param {string} id of notificaition
|
* @param {string} id of notificaition
|
||||||
*/
|
*/
|
||||||
export const dbSeenNotify = (id: string) => {
|
export const dbSeenNotification = (id: string) => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
|
|
||||||
// Get current user id
|
// Get current user id
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
let notify: Notification = getState().notify.userNotifies[id]
|
let notify: Notification = getState().notify.userNotifies[id]
|
||||||
|
|
||||||
|
let updatedNotification: Notification = {
|
||||||
let updates: any = {}
|
|
||||||
updates[`userNotifies/${uid}/${id}`] = {
|
|
||||||
description: notify.description,
|
description: notify.description,
|
||||||
url: notify.url,
|
url: notify.url,
|
||||||
notifierUserId: notify.notifierUserId,
|
notifierUserId: notify.notifierUserId,
|
||||||
|
notifyRecieverUserId: uid,
|
||||||
isSeen: true
|
isSeen: true
|
||||||
}
|
}
|
||||||
|
|
||||||
return firebaseRef.update(updates).then((result) => {
|
return notificationService.setSeenNotification(id,uid,updatedNotification)
|
||||||
|
.then(() => {
|
||||||
dispatch(seenNotify(id))
|
dispatch(seenNotify(id))
|
||||||
}, (error) => dispatch(globalActions.showErrorMessage(error.message)))
|
})
|
||||||
|
.catch((error) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _____________ CRUD State _____________ */
|
/* _____________ CRUD State _____________ */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add notificaition
|
* Add notificaition
|
||||||
*/
|
*/
|
||||||
export const addNotify = () => {
|
export const addNotify = () => {
|
||||||
|
|
||||||
@@ -141,7 +137,6 @@ export const addNotifyList = (userNotifies: {[notifyId: string]: Notification})
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a notificaition
|
* Delete a notificaition
|
||||||
* @param {string} id of notificaition
|
* @param {string} id of notificaition
|
||||||
@@ -168,5 +163,3 @@ export const clearAllNotifications = () => {
|
|||||||
type: NotificationActionType.CLEAR_ALL_DATA_NOTIFY
|
type: NotificationActionType.CLEAR_ALL_DATA_NOTIFY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
// - Import react components
|
// - Import react components
|
||||||
import { Action } from 'redux'
|
import { Action } from 'redux'
|
||||||
|
|
||||||
// - Import firebase component
|
|
||||||
import firebase, { firebaseRef } from '../firebase'
|
|
||||||
|
|
||||||
// - Import domain
|
// - Import domain
|
||||||
import { Post } from 'domain/posts'
|
import { Post } from 'domain/posts'
|
||||||
|
import { SocialError } from 'domain/common'
|
||||||
|
|
||||||
// - Import utility components
|
// - Import utility components
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
@@ -16,6 +14,12 @@ import { PostActionType } from 'constants/postActionType'
|
|||||||
// - Import actions
|
// - Import actions
|
||||||
import * as globalActions from 'actions/globalActions'
|
import * as globalActions from 'actions/globalActions'
|
||||||
|
|
||||||
|
import { IServiceProvider, ServiceProvide } from 'factories'
|
||||||
|
import { IPostService } from 'services/posts'
|
||||||
|
|
||||||
|
const serviceProvider: IServiceProvider = new ServiceProvide()
|
||||||
|
const postService: IPostService = serviceProvider.createPostService()
|
||||||
|
|
||||||
/* _____________ CRUD DB _____________ */
|
/* _____________ CRUD DB _____________ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,14 +52,14 @@ export let dbAddPost = (newPost: any, callBack: Function) => {
|
|||||||
deleted: false
|
deleted: false
|
||||||
}
|
}
|
||||||
|
|
||||||
let postRef: any = firebaseRef.child(`userPosts/${uid}/posts`).push(post)
|
return postService.addPost(uid,post).then((postKey: string) => {
|
||||||
return postRef.then(() => {
|
|
||||||
dispatch(addPost(uid, {
|
dispatch(addPost(uid, {
|
||||||
...post,
|
...post,
|
||||||
id: postRef.key
|
id: postKey
|
||||||
}))
|
}))
|
||||||
callBack()
|
callBack()
|
||||||
}, (error: any) => dispatch(globalActions.showErrorMessage(error.message)))
|
})
|
||||||
|
.catch((error: SocialError) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,16 +95,17 @@ export const dbAddImagePost = (newPost: any, callBack: Function) => {
|
|||||||
deleted: false
|
deleted: false
|
||||||
}
|
}
|
||||||
|
|
||||||
let postRef: any = firebaseRef.child(`userPosts/${uid}/posts`).push(post)
|
return postService.addPost(uid,post).then((postKey: string) => {
|
||||||
return postRef.then(() => {
|
|
||||||
dispatch(addPost(uid, {
|
dispatch(addPost(uid, {
|
||||||
...post,
|
...post,
|
||||||
id: postRef.key
|
id: postKey
|
||||||
}))
|
}))
|
||||||
callBack()
|
callBack()
|
||||||
dispatch(globalActions.hideTopLoading())
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
|
||||||
})
|
})
|
||||||
|
.catch((error: SocialError) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -142,14 +147,15 @@ export const dbUpdatePost = (newPost: any, callBack: Function) => {
|
|||||||
disableSharing: newPost.disableSharing !== undefined ? newPost.disableSharing : (post.disableSharing ? post.disableSharing : false),
|
disableSharing: newPost.disableSharing !== undefined ? newPost.disableSharing : (post.disableSharing ? post.disableSharing : false),
|
||||||
deleted: false
|
deleted: false
|
||||||
}
|
}
|
||||||
updates[`userPosts/${uid}/posts/${newPost.id}`] = updatedPost
|
|
||||||
return firebaseRef.update(updates).then((result) => {
|
return postService.updatePost(uid,newPost.id,updatedPost).then(() => {
|
||||||
|
|
||||||
dispatch(updatePost(uid, { id: newPost.id, ...updatedPost }))
|
dispatch(updatePost(uid, { id: newPost.id, ...updatedPost }))
|
||||||
callBack()
|
callBack()
|
||||||
dispatch(globalActions.hideTopLoading())
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
|
||||||
}, (error) => {
|
})
|
||||||
|
.catch((error: SocialError) => {
|
||||||
dispatch(globalActions.showErrorMessage(error.message))
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
dispatch(globalActions.hideTopLoading())
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
|
||||||
@@ -170,15 +176,12 @@ export const dbDeletePost = (id: string) => {
|
|||||||
// Get current user id
|
// Get current user id
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
|
|
||||||
// Write the new data simultaneously in the list
|
return postService.deletePost(uid,id).then(() => {
|
||||||
let updates: any = {}
|
|
||||||
updates[`userPosts/${uid}/posts/${id}`] = null
|
|
||||||
|
|
||||||
return firebaseRef.update(updates).then((result) => {
|
|
||||||
dispatch(deletePost(uid, id))
|
dispatch(deletePost(uid, id))
|
||||||
dispatch(globalActions.hideTopLoading())
|
dispatch(globalActions.hideTopLoading())
|
||||||
|
|
||||||
}, (error) => {
|
})
|
||||||
|
.catch((error: SocialError) => {
|
||||||
dispatch(globalActions.showErrorMessage(error.message))
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
dispatch(globalActions.hideTopLoading())
|
dispatch(globalActions.hideTopLoading())
|
||||||
})
|
})
|
||||||
@@ -190,22 +193,15 @@ export const dbDeletePost = (id: string) => {
|
|||||||
* Get all user posts from data base
|
* Get all user posts from data base
|
||||||
*/
|
*/
|
||||||
export const dbGetPosts = () => {
|
export const dbGetPosts = () => {
|
||||||
return (dispatch: any, getState: any) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let postsRef: any = firebaseRef.child(`userPosts/${uid}/posts`)
|
|
||||||
|
|
||||||
return postsRef.once('value').then((snapshot: any) => {
|
return postService.getPosts(uid).then((posts: { [postId: string]: Post }) => {
|
||||||
let posts: any = snapshot.val() || {}
|
dispatch(addPosts(uid, posts))
|
||||||
let parsedPosts: { [postId: string]: Post } = {}
|
})
|
||||||
Object.keys(posts).forEach((postId) => {
|
.catch((error: SocialError) => {
|
||||||
parsedPosts[postId] = {
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
id: postId,
|
|
||||||
...posts[postId]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
dispatch(addPosts(uid, parsedPosts))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -220,22 +216,18 @@ export const dbGetPosts = () => {
|
|||||||
export const dbGetPostById = (uid: string, postId: string) => {
|
export const dbGetPostById = (uid: string, postId: string) => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let postsRef: any = firebaseRef.child(`userPosts/${uid}/posts/${postId}`)
|
|
||||||
|
|
||||||
return postsRef.once('value').then((snapshot: any) => {
|
return postService.getPostById(uid,postId).then((post: Post) => {
|
||||||
const newPost = snapshot.val() || {}
|
|
||||||
const post = {
|
|
||||||
id: postId,
|
|
||||||
...newPost
|
|
||||||
}
|
|
||||||
dispatch(addPost(uid, post))
|
dispatch(addPost(uid, post))
|
||||||
})
|
})
|
||||||
|
.catch((error: SocialError) => {
|
||||||
|
dispatch(globalActions.showErrorMessage(error.message))
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all user posts from data base by user id
|
* Get all user posts from data base by user id
|
||||||
* @param uid posts owner identifier
|
* @param uid posts owner identifier
|
||||||
@@ -244,19 +236,8 @@ export const dbGetPostsByUserId = (uid: string) => {
|
|||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
|
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let postsRef: any = firebaseRef.child(`userPosts/${uid}/posts`)
|
return postService.getPosts(uid).then((posts: { [postId: string]: Post }) => {
|
||||||
|
dispatch(addPosts(uid, posts))
|
||||||
return postsRef.once('value').then((snapshot: any) => {
|
|
||||||
let posts: any = snapshot.val() || {}
|
|
||||||
let parsedPosts: { [postId: string]: Post } = {}
|
|
||||||
Object.keys(posts).forEach((postId) => {
|
|
||||||
parsedPosts[postId] = {
|
|
||||||
id: postId,
|
|
||||||
...posts[postId]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
dispatch(addPosts(uid, parsedPosts))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -268,7 +249,7 @@ export const dbGetPostsByUserId = (uid: string) => {
|
|||||||
/**
|
/**
|
||||||
* Add a normal post
|
* Add a normal post
|
||||||
* @param {string} uid is user identifier
|
* @param {string} uid is user identifier
|
||||||
* @param {Post} post
|
* @param {Post} post
|
||||||
*/
|
*/
|
||||||
export const addPost = (uid: string, post: Post) => {
|
export const addPost = (uid: string, post: Post) => {
|
||||||
return {
|
return {
|
||||||
@@ -303,8 +284,8 @@ export const deletePost = (uid: string, id: string) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a list of post
|
* Add a list of post
|
||||||
* @param {string} uid
|
* @param {string} uid
|
||||||
* @param {[object]} posts
|
* @param {[object]} posts
|
||||||
*/
|
*/
|
||||||
export const addPosts = (uid: string, posts: { [postId: string]: Post }) => {
|
export const addPosts = (uid: string, posts: { [postId: string]: Post }) => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
// - Import react components
|
// - Import react components
|
||||||
import { firebaseRef } from 'app/firebase/'
|
|
||||||
|
|
||||||
// - Import domain
|
// - Import domain
|
||||||
import { Profile } from 'domain/users'
|
import { Profile } from 'domain/users'
|
||||||
|
import { SocialError } from 'domain/common'
|
||||||
|
|
||||||
// - Import action types
|
// - Import action types
|
||||||
import {UserActionType} from 'constants/userActionType'
|
import { UserActionType } from 'constants/userActionType'
|
||||||
|
|
||||||
// - Import actions
|
// - Import actions
|
||||||
import * as globalActions from 'actions/globalActions'
|
import * as globalActions from 'actions/globalActions'
|
||||||
import * as userActions from 'actions/userActions'
|
import * as userActions from 'actions/userActions'
|
||||||
|
|
||||||
declare const console: any
|
import { IServiceProvider, ServiceProvide } from 'factories'
|
||||||
|
import { IUserService } from 'services/users'
|
||||||
|
|
||||||
|
const serviceProvider: IServiceProvider = new ServiceProvide()
|
||||||
|
const userService: IUserService = serviceProvider.createUserService()
|
||||||
|
|
||||||
/* _____________ CRUD DB _____________ */
|
/* _____________ CRUD DB _____________ */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user info from database
|
* Get user info from database
|
||||||
*/
|
*/
|
||||||
@@ -23,11 +26,8 @@ export const dbGetUserInfo = () => {
|
|||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let userProfileRef: any = firebaseRef.child(`users/${uid}/info`)
|
|
||||||
|
|
||||||
return userProfileRef.once('value').then((snapshot: any) => {
|
return userService.getUserProfile(uid).then((userProfile: Profile) => {
|
||||||
let userProfile: Profile = snapshot.val() || {}
|
|
||||||
|
|
||||||
dispatch(addUserInfo(uid, {
|
dispatch(addUserInfo(uid, {
|
||||||
avatar: userProfile.avatar,
|
avatar: userProfile.avatar,
|
||||||
email: userProfile.email,
|
email: userProfile.email,
|
||||||
@@ -35,7 +35,8 @@ export const dbGetUserInfo = () => {
|
|||||||
banner: userProfile.banner,
|
banner: userProfile.banner,
|
||||||
tagLine: userProfile.tagLine
|
tagLine: userProfile.tagLine
|
||||||
}))
|
}))
|
||||||
}, (error: any) => console.log(error))
|
})
|
||||||
|
.catch((error: SocialError) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,16 +44,15 @@ export const dbGetUserInfo = () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user info from database
|
* Get user info from database
|
||||||
* @param {string} uid
|
* @param {string} uid
|
||||||
* @param {string} callerKey
|
* @param {string} callerKey
|
||||||
*/
|
*/
|
||||||
export const dbGetUserInfoByUserId = (uid: string, callerKey: string) => {
|
export const dbGetUserInfoByUserId = (uid: string, callerKey: string) => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let userProfileRef: any = firebaseRef.child(`users/${uid}/info`)
|
|
||||||
|
|
||||||
return userProfileRef.once('value').then((snapshot: any) => {
|
return userService.getUserProfile(uid).then((userProfile: Profile) => {
|
||||||
let userProfile = snapshot.val() || {}
|
|
||||||
dispatch(addUserInfo(uid, {
|
dispatch(addUserInfo(uid, {
|
||||||
avatar: userProfile.avatar,
|
avatar: userProfile.avatar,
|
||||||
email: userProfile.email,
|
email: userProfile.email,
|
||||||
@@ -60,6 +60,7 @@ export const dbGetUserInfoByUserId = (uid: string, callerKey: string) => {
|
|||||||
banner: userProfile.banner,
|
banner: userProfile.banner,
|
||||||
tagLine: userProfile.tagLine
|
tagLine: userProfile.tagLine
|
||||||
}))
|
}))
|
||||||
|
|
||||||
switch (callerKey) {
|
switch (callerKey) {
|
||||||
case 'header':
|
case 'header':
|
||||||
dispatch(globalActions.setHeaderTitle(userProfile.fullName))
|
dispatch(globalActions.setHeaderTitle(userProfile.fullName))
|
||||||
@@ -69,7 +70,8 @@ export const dbGetUserInfoByUserId = (uid: string, callerKey: string) => {
|
|||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}, (error: any) => console.log(error))
|
})
|
||||||
|
.catch((error: SocialError) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +79,7 @@ export const dbGetUserInfoByUserId = (uid: string, callerKey: string) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updata user information
|
* Updata user information
|
||||||
* @param {object} newInfo
|
* @param {object} newInfo
|
||||||
*/
|
*/
|
||||||
export const dbUpdateUserInfo = (newProfile: Profile) => {
|
export const dbUpdateUserInfo = (newProfile: Profile) => {
|
||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
@@ -85,24 +87,22 @@ export const dbUpdateUserInfo = (newProfile: Profile) => {
|
|||||||
// Get current user id
|
// Get current user id
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
|
|
||||||
// Write the new data simultaneously in the list
|
let profile: Profile = getState().user.info[uid]
|
||||||
let updates: any = {}
|
let updatedProfie: Profile = {
|
||||||
let profile = getState().user.info[uid]
|
|
||||||
let updateProfie: Profile = {
|
|
||||||
avatar: newProfile.avatar || profile.avatar || '',
|
avatar: newProfile.avatar || profile.avatar || '',
|
||||||
banner: newProfile.banner || profile.banner || 'https://firebasestorage.googleapis.com/v0/b/open-social-33d92.appspot.com/o/images%2F751145a1-9488-46fd-a97e-04018665a6d3.JPG?alt=media&token=1a1d5e21-5101-450e-9054-ea4a20e06c57',
|
banner: newProfile.banner || profile.banner || 'https://firebasestorage.googleapis.com/v0/b/open-social-33d92.appspot.com/o/images%2F751145a1-9488-46fd-a97e-04018665a6d3.JPG?alt=media&token=1a1d5e21-5101-450e-9054-ea4a20e06c57',
|
||||||
email: newProfile.email || profile.email || '',
|
email: newProfile.email || profile.email || '',
|
||||||
fullName: newProfile.fullName || profile.fullName || '',
|
fullName: newProfile.fullName || profile.fullName || '',
|
||||||
tagLine: newProfile.tagLine || profile.tagLine || ''
|
tagLine: newProfile.tagLine || profile.tagLine || ''
|
||||||
}
|
}
|
||||||
updates[`users/${uid}/info`] = updateProfie
|
|
||||||
return firebaseRef.update(updates).then((result) => {
|
|
||||||
|
|
||||||
dispatch(updateUserInfo(uid, updateProfie))
|
return userService.updateUserProfile(uid,updatedProfie).then(() => {
|
||||||
|
|
||||||
|
dispatch(updateUserInfo(uid, updatedProfie))
|
||||||
dispatch(closeEditProfile())
|
dispatch(closeEditProfile())
|
||||||
}, (error) => {
|
|
||||||
dispatch(globalActions.showErrorMessage(error.message))
|
|
||||||
})
|
})
|
||||||
|
.catch((error: SocialError) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -112,27 +112,11 @@ export const dbGetPeopleInfo = () => {
|
|||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let peopleRef: any = firebaseRef.child(`users`)
|
return userService.getUsersProfile(uid)
|
||||||
|
.then((usersProfile: {[userId: string]: Profile}) => {
|
||||||
return peopleRef.once('value').then((snapshot: any) => {
|
dispatch(addPeopleInfo(usersProfile))
|
||||||
let people = snapshot.val() || {}
|
})
|
||||||
|
.catch((error: SocialError) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
let parsedPeople: {[userId: string]: Profile} = {}
|
|
||||||
Object.keys(people).forEach((userId) => {
|
|
||||||
if (userId !== uid) {
|
|
||||||
let userInfo = people[userId].info
|
|
||||||
parsedPeople[userId] = {
|
|
||||||
avatar: userInfo.avatar,
|
|
||||||
email: userInfo.email,
|
|
||||||
fullName: userInfo.fullName,
|
|
||||||
banner: userInfo.banner,
|
|
||||||
tagLine: userInfo.tagLine
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
dispatch(addPeopleInfo(parsedPeople))
|
|
||||||
}, (error: any) => console.log(error))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,7 +124,6 @@ export const dbGetPeopleInfo = () => {
|
|||||||
|
|
||||||
/* _____________ CRUD State _____________ */
|
/* _____________ CRUD State _____________ */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add user information
|
* Add user information
|
||||||
* @param {string} uid is the user identifier
|
* @param {string} uid is the user identifier
|
||||||
@@ -178,7 +161,7 @@ export const updateUserInfo = (uid: string, info: Profile) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* User info
|
* User info
|
||||||
* @param {Profile} info
|
* @param {Profile} info
|
||||||
*/
|
*/
|
||||||
export const userInfo = (info: Profile) => {
|
export const userInfo = (info: Profile) => {
|
||||||
return {
|
return {
|
||||||
@@ -193,7 +176,6 @@ export const clearAllData = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open edit profile
|
* Open edit profile
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import { firebaseRef } from 'app/firebase/'
|
|
||||||
|
|
||||||
// - Import action types
|
// - Import action types
|
||||||
import {VoteActionType} from 'constants/voteActionType'
|
import { VoteActionType } from 'constants/voteActionType'
|
||||||
|
|
||||||
// - Import domain
|
// - Import domain
|
||||||
import { Vote } from 'domain/votes'
|
import { Vote } from 'domain/votes'
|
||||||
@@ -11,7 +10,12 @@ import { Vote } from 'domain/votes'
|
|||||||
import * as globalActions from 'actions/globalActions'
|
import * as globalActions from 'actions/globalActions'
|
||||||
import * as notifyActions from 'actions/notifyActions'
|
import * as notifyActions from 'actions/notifyActions'
|
||||||
|
|
||||||
declare const console: any
|
import { IServiceProvider, ServiceProvide } from 'factories'
|
||||||
|
import { IVoteService } from 'services/votes'
|
||||||
|
|
||||||
|
const serviceProvider: IServiceProvider = new ServiceProvide()
|
||||||
|
const voteService: IVoteService = serviceProvider.createVoteService()
|
||||||
|
|
||||||
/* _____________ CRUD DB _____________ */
|
/* _____________ CRUD DB _____________ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,24 +35,24 @@ export const dbAddVote = (postId: string,ownerPostUserId: string) => {
|
|||||||
userId: uid
|
userId: uid
|
||||||
}
|
}
|
||||||
|
|
||||||
let voteRef = firebaseRef.child(`postVotes/${postId}`).push(vote)
|
return voteService.addVote(vote).then((voteKey: string) => {
|
||||||
return voteRef.then(() => {
|
|
||||||
dispatch(addVote(
|
dispatch(addVote(
|
||||||
{
|
{
|
||||||
...vote,
|
...vote,
|
||||||
postId: postId,
|
id: voteKey
|
||||||
id: voteRef.key
|
|
||||||
}))
|
}))
|
||||||
if(uid !== ownerPostUserId)
|
if (uid !== ownerPostUserId) {
|
||||||
dispatch(notifyActions.dbAddNotify(
|
dispatch(notifyActions.dbAddNotification(
|
||||||
{
|
{
|
||||||
description:'Vote on your post.',
|
description: 'Vote on your post.',
|
||||||
url:`/${ownerPostUserId}/posts/${postId}`,
|
url: `/${ownerPostUserId}/posts/${postId}`,
|
||||||
notifyRecieverUserId:ownerPostUserId,notifierUserId:uid,
|
notifyRecieverUserId: ownerPostUserId,notifierUserId:uid,
|
||||||
isSeen:false
|
isSeen: false
|
||||||
}))
|
}))
|
||||||
|
}
|
||||||
}, (error) => dispatch(globalActions.showErrorMessage(error.message)))
|
|
||||||
|
})
|
||||||
|
.catch((error) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,18 +64,17 @@ export const dbGetVotes = () => {
|
|||||||
return (dispatch: any, getState: Function) => {
|
return (dispatch: any, getState: Function) => {
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
if (uid) {
|
if (uid) {
|
||||||
let votesRef: any = firebaseRef.child(`postVotes`)
|
|
||||||
|
|
||||||
return votesRef.on('value',(snapshot: any) => {
|
return voteService
|
||||||
let postVotes: {[postId:string]: {[voteId: string]: Vote}} = snapshot.val() || {}
|
.getVotes()
|
||||||
|
.then((postVotes: { [postId: string]: { [voteId: string]: Vote } }) => {
|
||||||
dispatch(addVoteList(postVotes))
|
dispatch(addVoteList(postVotes))
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a vote from database
|
* Delete a vote from database
|
||||||
* @param {string} id of vote
|
* @param {string} id of vote
|
||||||
@@ -83,25 +86,19 @@ export const dbDeleteVote = (postId: string) => {
|
|||||||
// Get current user id
|
// Get current user id
|
||||||
let uid: string = getState().authorize.uid
|
let uid: string = getState().authorize.uid
|
||||||
|
|
||||||
// Write the new data simultaneously in the list
|
|
||||||
let updates: any = {}
|
|
||||||
let votes: {[voteId: string]: Vote} = getState().vote.postVotes[postId]
|
let votes: {[voteId: string]: Vote} = getState().vote.postVotes[postId]
|
||||||
let id: string = Object.keys(votes).filter((key)=> votes[key].userId === uid)[0]
|
let id: string = Object.keys(votes).filter((key) => votes[key].userId === uid)[0]
|
||||||
|
|
||||||
|
return voteService.deleteVote(id,postId).then(() => {
|
||||||
updates[`postVotes/${postId}/${id}`] = null
|
|
||||||
|
|
||||||
return firebaseRef.update(updates).then((result) => {
|
|
||||||
dispatch(deleteVote(id, postId))
|
dispatch(deleteVote(id, postId))
|
||||||
})
|
})
|
||||||
.catch((error: any) => dispatch(globalActions.showErrorMessage(error.message)))
|
.catch((error: any) => dispatch(globalActions.showErrorMessage(error.message)))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a vote
|
* Add a vote
|
||||||
* @param {Vote} vote
|
* @param {Vote} vote
|
||||||
*/
|
*/
|
||||||
export const addVote = (vote: Vote) => {
|
export const addVote = (vote: Vote) => {
|
||||||
return { type: VoteActionType.ADD_VOTE, payload: vote }
|
return { type: VoteActionType.ADD_VOTE, payload: vote }
|
||||||
@@ -122,7 +119,7 @@ export const deleteVote = (id: string, postId: string) => {
|
|||||||
* Ad a list of vote
|
* Ad a list of vote
|
||||||
* @param {[postId:string]: {[voteId: string]: Vote}} votes a list of vote
|
* @param {[postId:string]: {[voteId: string]: Vote}} votes a list of vote
|
||||||
*/
|
*/
|
||||||
export const addVoteList = (votes: {[postId:string]: {[voteId: string]: Vote}}) => {
|
export const addVoteList = (votes: {[postId: string]: {[voteId: string]: Vote}}) => {
|
||||||
return { type: VoteActionType.ADD_VOTE_LIST, payload: votes }
|
return { type: VoteActionType.ADD_VOTE_LIST, payload: votes }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,101 +1,100 @@
|
|||||||
export interface IMasterProps{
|
export interface IMasterProps {
|
||||||
/**
|
/**
|
||||||
* Close gloal message
|
* Close gloal message
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
closeMessage: Function,
|
closeMessage: Function,
|
||||||
/**
|
/**
|
||||||
* Show progress bar information
|
* Show progress bar information
|
||||||
*
|
*
|
||||||
* @type {*}
|
* @type {*}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
progress:any,
|
progress: any,
|
||||||
/**
|
/**
|
||||||
* Login a user
|
* Login a user
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
login: Function,
|
login: Function,
|
||||||
/**
|
/**
|
||||||
* Global state
|
* Global state
|
||||||
*
|
*
|
||||||
* @type {*}
|
* @type {*}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
global:any,
|
global: any,
|
||||||
/**
|
/**
|
||||||
* Set flag {false} which user data has not loaded
|
* Set flag {false} which user data has not loaded
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
defaultDataDisable: Function,
|
defaultDataDisable: Function,
|
||||||
/**
|
/**
|
||||||
* Logout current user
|
* Logout current user
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
logout: Function,
|
logout: Function,
|
||||||
/**
|
/**
|
||||||
* Clear user date from store
|
* Clear user date from store
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
clearData: Function,
|
clearData: Function,
|
||||||
/**
|
/**
|
||||||
* Prepare default data for a guest user
|
* Prepare default data for a guest user
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
loadDataGuest: Function,
|
loadDataGuest: Function,
|
||||||
/**
|
/**
|
||||||
* Set flag {true} which all user data has loaded
|
* Set flag {true} which all user data has loaded
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
defaultDataEnable: Function,
|
defaultDataEnable: Function,
|
||||||
/**
|
/**
|
||||||
* Load user data into store
|
* Load user data into store
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
loadData: Function,
|
loadData: Function,
|
||||||
/**
|
/**
|
||||||
* If all data from all entities are loaded {true} if not {false}
|
* If all data from all entities are loaded {true} if not {false}
|
||||||
*
|
*
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
loaded:Boolean,
|
loaded: Boolean,
|
||||||
/**
|
/**
|
||||||
* If current user is guest {true} if no
|
* If current user is guest {true} if no
|
||||||
*
|
*
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
guest:Boolean,
|
guest: Boolean,
|
||||||
/**
|
/**
|
||||||
* If current user is authed {true} if not {false}
|
* If current user is authed {true} if not {false}
|
||||||
*
|
*
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
authed: Boolean,
|
authed: Boolean,
|
||||||
/**
|
/**
|
||||||
* Authed user identifier
|
* Authed user identifier
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof IMasterProps
|
* @memberof IMasterProps
|
||||||
*/
|
*/
|
||||||
uid: string
|
uid: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/// <reference types="@types/material-ui" />
|
||||||
// - Import react components
|
// - Import react components
|
||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
@@ -33,7 +34,7 @@ import * as notifyActions from 'actions/notifyActions'
|
|||||||
/* ------------------------------------ */
|
/* ------------------------------------ */
|
||||||
|
|
||||||
// - Create Master component class
|
// - Create Master component class
|
||||||
export class Master extends Component<IMasterProps,IMasterState> {
|
export class Master extends Component<IMasterProps, IMasterState> {
|
||||||
|
|
||||||
static isPrivate = true
|
static isPrivate = true
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -108,45 +109,44 @@ export class Master extends Component<IMasterProps,IMasterState> {
|
|||||||
*/
|
*/
|
||||||
public render (): React.ReactElement<{}> {
|
public render (): React.ReactElement<{}> {
|
||||||
|
|
||||||
const {progress, global} = this.props
|
const { progress, global } = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id='master'>
|
<div id='master'>
|
||||||
|
|
||||||
<div className='master__progress' style={{display: (progress.visible ? 'block' : 'none' )}}>
|
<div className='master__progress' style={{ display: (progress.visible ? 'block' : 'none') }}>
|
||||||
<LinearProgress mode='determinate' value={progress.percent} />
|
<LinearProgress mode='determinate' value={progress.percent} />
|
||||||
</div>
|
</div>
|
||||||
<div className='master__loading animate-fading2' style={{display: ( global.showTopLoading ? 'flex' : 'none' )}}>
|
<div className='master__loading animate-fading2' style={{ display: (global.showTopLoading ? 'flex' : 'none') }}>
|
||||||
<div className='title'>Loading ... </div>
|
<div className='title'>Loading ... </div>
|
||||||
</div>
|
</div>
|
||||||
<MasterLoading activeLoading={this.state.loading || !(this.props.loaded || this.props.guest)} handleLoading={this.handleLoading} />
|
<MasterLoading activeLoading={this.state.loading || !(this.props.loaded || this.props.guest)} handleLoading={this.handleLoading} />
|
||||||
|
|
||||||
{(!this.state.loading && (this.props.loaded || this.props.guest))
|
{(!this.state.loading && (this.props.loaded || this.props.guest))
|
||||||
? (<Switch>
|
? (<Switch>
|
||||||
<Route path='/signup' component={Signup} />
|
<Route path='/signup' component={Signup} />
|
||||||
<Route path='/settings' component={Settings} />
|
<Route path='/settings' component={Settings} />
|
||||||
<Route path='/login' render={() => {
|
<Route path='/login' render={() => {
|
||||||
console.log('this.props.authed: ', this.props.authed, 'this.props: ', this.props)
|
console.log('this.props.authed: ', this.props.authed, 'this.props: ', this.props)
|
||||||
return (
|
return (
|
||||||
this.props.authed
|
this.props.authed
|
||||||
? <Redirect to='/' />
|
? <Redirect to='/' />
|
||||||
: <Login />
|
: <Login />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} />
|
} />
|
||||||
<Route render={() => <Home uid={this.props.uid}/>} />
|
<Route render={() => <Home uid={this.props.uid} />} />
|
||||||
|
|
||||||
</Switch>) : ''
|
</Switch>) : ''
|
||||||
}
|
}
|
||||||
<Snackbar
|
<Snackbar
|
||||||
open={this.props.global.messageOpen}
|
open={this.props.global.messageOpen}
|
||||||
message={this.props.global.message}
|
message={this.props.global.message}
|
||||||
autoHideDuration={4000}
|
autoHideDuration={4000}
|
||||||
style={{left: '1%', transform: 'none'}}
|
style={{ left: '1%', transform: 'none' }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,11 +157,11 @@ const mapDispatchToProps = (dispatch: any, ownProps: any) => {
|
|||||||
return {
|
return {
|
||||||
loadData: () => {
|
loadData: () => {
|
||||||
dispatch(commentActions.dbGetComments())
|
dispatch(commentActions.dbGetComments())
|
||||||
dispatch(imageGalleryActions.downloadForImageGallery())
|
dispatch(imageGalleryActions.dbGetImageGallery())
|
||||||
dispatch(postActions.dbGetPosts())
|
dispatch(postActions.dbGetPosts())
|
||||||
dispatch(userActions.dbGetUserInfo())
|
dispatch(userActions.dbGetUserInfo())
|
||||||
dispatch(voteActions.dbGetVotes())
|
dispatch(voteActions.dbGetVotes())
|
||||||
dispatch(notifyActions.dbGetNotifies())
|
dispatch(notifyActions.dbGetNotifications())
|
||||||
dispatch(circleActions.dbGetCircles())
|
dispatch(circleActions.dbGetCircles())
|
||||||
|
|
||||||
},
|
},
|
||||||
@@ -202,7 +202,7 @@ const mapDispatchToProps = (dispatch: any, ownProps: any) => {
|
|||||||
* @param {object} state
|
* @param {object} state
|
||||||
*/
|
*/
|
||||||
const mapStateToProps = (state: any) => {
|
const mapStateToProps = (state: any) => {
|
||||||
const {authorize, global, user, post, comment, imageGallery , vote, notify,circle } = state
|
const { authorize, global, user, post, comment, imageGallery, vote, notify, circle } = state
|
||||||
return {
|
return {
|
||||||
guest: authorize.guest,
|
guest: authorize.guest,
|
||||||
uid: authorize.uid,
|
uid: authorize.uid,
|
||||||
|
|||||||
@@ -1,61 +1,69 @@
|
|||||||
import { BaseDomain } from 'domain/common'
|
import { BaseDomain } from 'domain/common'
|
||||||
|
|
||||||
export class Comment extends BaseDomain {
|
export class Comment extends BaseDomain {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post identifier that comment belong to
|
* Comment identifier
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Comment
|
* @memberof Comment
|
||||||
*/
|
*/
|
||||||
public postId: string
|
public id?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment text
|
* Post identifier that comment belong to
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Comment
|
* @memberof Comment
|
||||||
*/
|
*/
|
||||||
public text: string
|
public postId: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment score
|
* Comment text
|
||||||
*
|
*
|
||||||
* @type {number}
|
* @type {string}
|
||||||
* @memberof Comment
|
* @memberof Comment
|
||||||
*/
|
*/
|
||||||
public score: number
|
public text: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment creation date
|
* Comment score
|
||||||
*
|
*
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @memberof Comment
|
* @memberof Comment
|
||||||
*/
|
*/
|
||||||
public creationDate:number
|
public score: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment owner full name
|
* Comment creation date
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {number}
|
||||||
* @memberof Comment
|
* @memberof Comment
|
||||||
*/
|
*/
|
||||||
public userDisplayName: string
|
public creationDate: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment owner avater address
|
* Comment owner full name
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Comment
|
* @memberof Comment
|
||||||
*/
|
*/
|
||||||
public userAvatar: string
|
public userDisplayName: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment owner identifier
|
* Comment owner avater address
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Comment
|
* @memberof Comment
|
||||||
*/
|
*/
|
||||||
public userId: string
|
public userAvatar: string
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Comment owner identifier
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Comment
|
||||||
|
*/
|
||||||
|
public userId: string
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,45 +1,43 @@
|
|||||||
export class SocialError{
|
export class SocialError {
|
||||||
|
|
||||||
constructor(code: string, description: string){
|
|
||||||
this._code = code
|
|
||||||
this._description = description
|
|
||||||
this._isError = true
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error code
|
* Error code
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof SocialError
|
* @memberof SocialError
|
||||||
*/
|
*/
|
||||||
private _code : string
|
private _code: string
|
||||||
public get code() : string {
|
public get code (): string {
|
||||||
return this._code
|
return this._code
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error description
|
* Error message
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof SocialError
|
* @memberof SocialError
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private _description : string
|
private _message: string
|
||||||
public get description() : string {
|
public get message (): string {
|
||||||
return this._description
|
return this._message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If is error {true} if not {false}
|
* If is error {true} if not {false}
|
||||||
*
|
*
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
* @memberof SocialError
|
* @memberof SocialError
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private _isError : Boolean
|
private _isError: Boolean
|
||||||
public get isError() : Boolean {
|
public get isError (): Boolean {
|
||||||
return this._isError
|
return this._isError
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
constructor (code: string, message: string) {
|
||||||
|
this._code = code
|
||||||
|
this._message = message
|
||||||
|
this._isError = true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,66 +4,66 @@ export class Image extends BaseDomain {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Image identifier
|
* Image identifier
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Image
|
* @memberof Image
|
||||||
*/
|
*/
|
||||||
public id?: string | null
|
public id?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image creation date
|
* Image creation date
|
||||||
*
|
*
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @memberof Image
|
* @memberof Image
|
||||||
*/
|
*/
|
||||||
public creationDate: number
|
public creationDate: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image delete date
|
* Image delete date
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Image
|
* @memberof Image
|
||||||
*/
|
*/
|
||||||
public deleteDate: string
|
public deleteDate: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image URL address
|
* Image URL address
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Image
|
* @memberof Image
|
||||||
*/
|
*/
|
||||||
public URL: string
|
public URL: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image folder name with image name {folderName/imageName}
|
* Image folder name with image name {folderName/imageName}
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Image
|
* @memberof Image
|
||||||
*/
|
*/
|
||||||
public fullPath: string
|
public fullPath: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image owner identifier
|
* Image owner identifier
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Image
|
* @memberof Image
|
||||||
*/
|
*/
|
||||||
public ownerUserId: string
|
public ownerUserId: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last edit date
|
* Last edit date
|
||||||
*
|
*
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @memberof Image
|
* @memberof Image
|
||||||
*/
|
*/
|
||||||
public lastEditDate: number
|
public lastEditDate: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the image was deleted {true} or not {false}
|
* If the image was deleted {true} or not {false}
|
||||||
*
|
*
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
* @memberof Image
|
* @memberof Image
|
||||||
*/
|
*/
|
||||||
public deleted: Boolean
|
public deleted: Boolean
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,45 @@
|
|||||||
import { BaseDomain } from 'domain/common'
|
import { BaseDomain } from 'domain/common'
|
||||||
|
|
||||||
export class Notification extends BaseDomain {
|
export class Notification extends BaseDomain {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of notification
|
* Description of notification
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Notification
|
* @memberof Notification
|
||||||
*/
|
*/
|
||||||
public description: string
|
public description: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL which notification refer to
|
* The URL which notification refer to
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Notification
|
* @memberof Notification
|
||||||
*/
|
*/
|
||||||
public url: string
|
public url: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The identifier of the user who makes the notification
|
* The identifier of the user who makes the notification
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Notification
|
* @memberof Notification
|
||||||
*/
|
*/
|
||||||
public notifierUserId: string
|
public notifierUserId: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The identifier of the user who receive the notification
|
* The identifier of the user who receive the notification
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof Notification
|
* @memberof Notification
|
||||||
*/
|
*/
|
||||||
public notifyRecieverUserId: string
|
public notifyRecieverUserId: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the notification is seen {true} or not {false}
|
* If the notification is seen {true} or not {false}
|
||||||
*
|
*
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
* @memberof Notification
|
* @memberof Notification
|
||||||
*/
|
*/
|
||||||
public isSeen: Boolean
|
public isSeen: Boolean
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,76 @@
|
|||||||
import {IAuthorizeService} from 'services/authorize/IAuthorizeService'
|
import { IAuthorizeService } from 'services/authorize/IAuthorizeService'
|
||||||
export interface IServiceProvider{
|
import { ICircleService } from 'services/circles'
|
||||||
/**
|
import { ICommentService } from 'services/comments'
|
||||||
* Create authorize service
|
import { ICommonService } from 'services/common'
|
||||||
*
|
import { IImageGalleryService } from 'services/imageGallery'
|
||||||
* @memberof IServiceProvider
|
import { INotificationService } from 'services/notifications'
|
||||||
*/
|
import { IPostService } from 'services/posts'
|
||||||
createAuthorizeService : () => IAuthorizeService
|
import { IUserService } from 'services/users'
|
||||||
|
import { IVoteService } from 'services/votes'
|
||||||
|
|
||||||
}
|
export interface IServiceProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create authorize service
|
||||||
|
*
|
||||||
|
* @memberof IServiceProvider
|
||||||
|
*/
|
||||||
|
createAuthorizeService: () => IAuthorizeService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Circle Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createCircleService: () => ICircleService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Comment Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createCommentService: () => ICommentService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Common Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createCommonService: () => ICommonService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for ImageGallery Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createImageGalleryService: () => IImageGalleryService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Notification Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createNotificationService: () => INotificationService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Post Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createPostService: () => IPostService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for User Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createUserService: () => IUserService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Vote Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createVoteService: () => IVoteService
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,25 +2,114 @@
|
|||||||
|
|
||||||
import { IServiceProvider } from 'factories'
|
import { IServiceProvider } from 'factories'
|
||||||
import { IAuthorizeService } from 'services/authorize'
|
import { IAuthorizeService } from 'services/authorize'
|
||||||
|
import { ICircleService } from 'services/circles'
|
||||||
|
import { ICommentService } from 'services/comments'
|
||||||
|
import { ICommonService } from 'services/common'
|
||||||
|
import { IImageGalleryService } from 'services/imageGallery'
|
||||||
|
import { INotificationService } from 'services/notifications'
|
||||||
|
import { IPostService } from 'services/posts'
|
||||||
|
import { IUserService } from 'services/users'
|
||||||
|
import { IVoteService } from 'services/votes'
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Service implemented classes
|
//#region Service implemented classes
|
||||||
|
|
||||||
// - Firebase services
|
// - Firebase services
|
||||||
import { AuthorizeService } from 'firebaseServices/authorize'
|
import { AuthorizeService } from 'firebaseServices/authorize'
|
||||||
|
import { CircleService } from 'firebaseServices/circles'
|
||||||
|
import { CommentService } from 'firebaseServices/comments'
|
||||||
|
import { CommonService } from 'firebaseServices/common'
|
||||||
|
import { ImageGalleryService } from 'firebaseServices/imageGallery'
|
||||||
|
import { NotificationService } from 'firebaseServices/notifications'
|
||||||
|
import { PostService } from 'firebaseServices/posts'
|
||||||
|
import { UserService } from 'firebaseServices/users'
|
||||||
|
import { VoteService } from 'firebaseServices/votes'
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
export class ServiceProvide implements IServiceProvider {
|
export class ServiceProvide implements IServiceProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create instant for AuthorizeService
|
* Create instant for Authorize Service
|
||||||
*
|
*
|
||||||
* @memberof ServiceProvide
|
* @memberof ServiceProvide
|
||||||
*/
|
*/
|
||||||
createAuthorizeService: () => IAuthorizeService = () => {
|
createAuthorizeService: () => IAuthorizeService = () => {
|
||||||
return new AuthorizeService()
|
return new AuthorizeService()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Create instant for Circle Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createCircleService: () => ICircleService = () => {
|
||||||
|
return new CircleService()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Comment Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createCommentService: () => ICommentService = () => {
|
||||||
|
return new CommentService()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Common Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createCommonService: () => ICommonService = () => {
|
||||||
|
return new CommonService()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for ImageGallery Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createImageGalleryService: () => IImageGalleryService = () => {
|
||||||
|
return new ImageGalleryService()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Notification Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createNotificationService: () => INotificationService = () => {
|
||||||
|
return new NotificationService()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Post Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createPostService: () => IPostService = () => {
|
||||||
|
return new PostService()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for User Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createUserService: () => IUserService = () => {
|
||||||
|
return new UserService()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create instant for Vote Service
|
||||||
|
*
|
||||||
|
* @memberof ServiceProvide
|
||||||
|
*/
|
||||||
|
createVoteService: () => IVoteService = () => {
|
||||||
|
return new VoteService()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ export class AuthorizeService implements IAuthorizeService {
|
|||||||
resolve(new LoginUser(result.uid))
|
resolve(new LoginUser(result.uid))
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
reject(new SocialError(error.code, error.message))
|
reject(new SocialError(error.code, error.message))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs out the user
|
* Logs out the user
|
||||||
@@ -41,19 +41,19 @@ export class AuthorizeService implements IAuthorizeService {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
* @memberof IAuthorizeService
|
* @memberof IAuthorizeService
|
||||||
*/
|
*/
|
||||||
public logout: () => Promise<void> = () => {
|
public logout: () => Promise<void> = () => {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
firebaseAuth()
|
firebaseAuth()
|
||||||
.signOut()
|
.signOut()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
|
|
||||||
reject(new SocialError(error.code, error.message))
|
reject(new SocialError(error.code, error.message))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a user
|
* Register a user
|
||||||
@@ -61,24 +61,24 @@ export class AuthorizeService implements IAuthorizeService {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
* @memberof IAuthorizeService
|
* @memberof IAuthorizeService
|
||||||
*/
|
*/
|
||||||
public registerUser: (user: User) => Promise<RegisterUserResult> = (user) => {
|
public registerUser: (user: User) => Promise<RegisterUserResult> = (user) => {
|
||||||
return new Promise<RegisterUserResult>((resolve, reject) => {
|
return new Promise<RegisterUserResult>((resolve, reject) => {
|
||||||
firebaseAuth()
|
firebaseAuth()
|
||||||
.createUserWithEmailAndPassword(user.email as string, user.password as string)
|
.createUserWithEmailAndPassword(user.email as string, user.password as string)
|
||||||
.then((signupResult) => {
|
.then((signupResult) => {
|
||||||
firebaseRef.child(`users/${signupResult.uid}/info`)
|
firebaseRef.child(`users/${signupResult.uid}/info`)
|
||||||
.set({
|
.set({
|
||||||
...user,
|
...user,
|
||||||
avatar: 'noImage'
|
avatar: 'noImage'
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
resolve(new RegisterUserResult(signupResult.uid))
|
resolve(new RegisterUserResult(signupResult.uid))
|
||||||
})
|
})
|
||||||
.catch((error: any) => reject(new SocialError(error.name, error.message)))
|
.catch((error: any) => reject(new SocialError(error.name, error.message)))
|
||||||
})
|
})
|
||||||
.catch((error: any) => reject(new SocialError(error.code, error.message)))
|
.catch((error: any) => reject(new SocialError(error.code, error.message)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update user password
|
* Update user password
|
||||||
@@ -87,25 +87,20 @@ export class AuthorizeService implements IAuthorizeService {
|
|||||||
* @memberof IAuthorizeService
|
* @memberof IAuthorizeService
|
||||||
*/
|
*/
|
||||||
public updatePassword: (newPassword: string) => Promise<void> = (newPassword) => {
|
public updatePassword: (newPassword: string) => Promise<void> = (newPassword) => {
|
||||||
console.log('====================================')
|
|
||||||
console.log('update password')
|
|
||||||
console.log('====================================')
|
|
||||||
return new Promise<void>((resolve, reject) => {
|
|
||||||
let user = firebaseAuth().currentUser
|
|
||||||
console.log('====================================')
|
|
||||||
console.log(user)
|
|
||||||
console.log('====================================')
|
|
||||||
if (user) {
|
|
||||||
user.updatePassword(newPassword).then(() => {
|
|
||||||
// Update successful.
|
|
||||||
resolve()
|
|
||||||
}).catch((error: any) => {
|
|
||||||
// An error happened.
|
|
||||||
reject(new SocialError(error.code, error.message))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
let user = firebaseAuth().currentUser
|
||||||
|
if (user) {
|
||||||
|
user.updatePassword(newPassword).then(() => {
|
||||||
|
// Update successful.
|
||||||
|
resolve()
|
||||||
|
}).catch((error: any) => {
|
||||||
|
// An error happened.
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// - Import react components
|
// - Import react components
|
||||||
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
||||||
|
|
||||||
|
|
||||||
import { SocialError } from 'domain/common'
|
import { SocialError } from 'domain/common'
|
||||||
import { ICircleService } from 'services/circles'
|
import { ICircleService } from 'services/circles'
|
||||||
import { Circle, UserFollower } from 'domain/circles'
|
import { Circle, UserFollower } from 'domain/circles'
|
||||||
@@ -9,19 +8,113 @@ import { User } from 'domain/users'
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Firbase circle service
|
* Firbase circle service
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @class CircleService
|
* @class CircleService
|
||||||
* @implements {ICircleService}
|
* @implements {ICircleService}
|
||||||
*/
|
*/
|
||||||
export class CircleService implements ICircleService {
|
export class CircleService implements ICircleService {
|
||||||
|
|
||||||
addCircle: (userId: string, circle: Circle) => Promise<string>
|
public addCircle: (userId: string, circle: Circle)
|
||||||
addFollowingUser: (userId: string, circleId: string, userCircle: User, userFollower: UserFollower, userFollowingId: string) => Promise<void>
|
=> Promise<string> = (userId, circle) => {
|
||||||
deleteFollowingUser: (userId: string, circleId: string, userFollowingId: string) => Promise<void>
|
return new Promise<string>((resolve,reject) => {
|
||||||
updateCircle: (userId: string, circle: Circle, circleId: string) => Promise<void>
|
let circleRef = firebaseRef.child(`userCircles/${userId}/circles`).push(circle)
|
||||||
deleteCircle: (circleId: string, userId: string) => Promise<void>
|
circleRef.then(() => {
|
||||||
getCircles: () => Promise<{ [circleId: string]: Circle }>
|
resolve(circleRef.key as string)
|
||||||
getCirclesByUserId: (userId: string) => Promise<{ [circleId: string]: Circle }>
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
|
||||||
}
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public addFollowingUser: (userId: string, circleId: string, userCircle: User, userFollower: UserFollower, userFollowingId: string)
|
||||||
|
=> Promise<void> = (userId, circleId, userCircle, userFollower, userFollowingId) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`userCircles/${userId}/circles/${circleId}/users/${userFollowingId}`] = userCircle
|
||||||
|
updates[`userCircles/${userFollowingId}/circles/-Followers/users/${userId}`] = userFollower
|
||||||
|
|
||||||
|
firebaseRef.update(updates).then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
public deleteFollowingUser: (userId: string, circleId: string, userFollowingId: string)
|
||||||
|
=> Promise<void> = (userId, circleId, userFollowingId) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`userCircles/${userId}/circles/${circleId}/users/${userFollowingId}`] = null
|
||||||
|
updates[`userCircles/${userFollowingId}/circles/-Followers/users/${userId}`] = null
|
||||||
|
|
||||||
|
firebaseRef.update(updates).then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
public updateCircle: (userId: string, circleId: string, circle: Circle)
|
||||||
|
=> Promise<void> = (userId, circleId, circle) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`userCircles/${userId}/circles/${circleId}`] = circle
|
||||||
|
firebaseRef.update(updates).then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public deleteCircle: (userId: string, circleId: string)
|
||||||
|
=> Promise<void> = (userId, circleId) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`userCircles/${userId}/circles/${circleId}`] = null
|
||||||
|
firebaseRef.update(updates).then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
public getCircles: (userId: string) => Promise<{ [circleId: string]: Circle }> = (userId) => {
|
||||||
|
return new Promise<{ [circleId: string]: Circle }>((resolve,reject) => {
|
||||||
|
let circlesRef: any = firebaseRef.child(`userCircles/${userId}/circles`)
|
||||||
|
|
||||||
|
circlesRef.once('value').then((snapshot: any) => {
|
||||||
|
let circles: any = snapshot.val() || {}
|
||||||
|
let parsedCircles: { [circleId: string]: Circle } = {}
|
||||||
|
Object.keys(circles).forEach((circleId) => {
|
||||||
|
|
||||||
|
parsedCircles[circleId] = {
|
||||||
|
id: circleId,
|
||||||
|
...circles[circleId]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
resolve(parsedCircles)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { AuthorizeService } from './CircleService'
|
import { CircleService } from './CircleService'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
AuthorizeService
|
CircleService
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,69 @@ import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
|||||||
|
|
||||||
import { SocialError } from 'domain/common'
|
import { SocialError } from 'domain/common'
|
||||||
import { ICommentService } from 'services/comments'
|
import { ICommentService } from 'services/comments'
|
||||||
|
import { Comment } from 'domain/comments'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Firbase comment service
|
* Firbase comment service
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @class CommentService
|
* @class CommentService
|
||||||
* @implements {ICommentService}
|
* @implements {ICommentService}
|
||||||
*/
|
*/
|
||||||
export class CommentService implements ICommentService {
|
export class CommentService implements ICommentService {
|
||||||
|
public addComment: (postId: string, comment: Comment)
|
||||||
|
=> Promise<string> = (postId, comment) => {
|
||||||
|
return new Promise<string>((resolve,reject) => {
|
||||||
|
let commentRef: any = firebaseRef.child(`postComments/${postId}`).push(comment)
|
||||||
|
commentRef.then(() => {
|
||||||
|
resolve(commentRef.key)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public getComments: ()
|
||||||
|
=> Promise<{ [postId: string]: { [commentId: string]: Comment } }> = () => {
|
||||||
|
return new Promise<{ [postId: string]: { [commentId: string]: Comment }}>((resolve,reject) => {
|
||||||
|
let commentsRef: any = firebaseRef.child(`postComments`)
|
||||||
|
commentsRef.on('value', (snapshot: any) => {
|
||||||
|
let comments: {[postId: string]: {[commentId: string]: Comment}} = snapshot!.val() || {}
|
||||||
|
resolve(comments)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public updateComment: (userId: string, postId: string, comment: Comment)
|
||||||
|
=> Promise<void> = (userId, postId, comment) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`postComments/${postId}/${userId}`] = comment
|
||||||
|
firebaseRef.update(updates)
|
||||||
|
.then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public deleteComment: (commentId: string, postId: string)
|
||||||
|
=> Promise<void> = (commentId, postId) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`postComments/${postId}/${commentId}`] = null
|
||||||
|
firebaseRef.update(updates)
|
||||||
|
.then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,17 +1,110 @@
|
|||||||
// - Import react components
|
// - Import react components
|
||||||
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
import { firebaseRef, firebaseAuth, storageRef } from 'app/firebase/'
|
||||||
|
|
||||||
import { SocialError } from 'domain/common'
|
import { SocialError } from 'domain/common'
|
||||||
import { IImageGalleryService } from 'services/imageGallery'
|
import { IImageGalleryService } from 'services/imageGallery'
|
||||||
|
import { Image } from 'domain/imageGallery'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Firbase image gallery service
|
* Firbase image gallery service
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @class ImageGalleryService
|
* @class ImageGalleryService
|
||||||
* @implements {IImageGalleryService}
|
* @implements {IImageGalleryService}
|
||||||
*/
|
*/
|
||||||
export class ImageGalleryService implements IImageGalleryService {
|
export class ImageGalleryService implements IImageGalleryService {
|
||||||
|
|
||||||
|
public getImageGallery: (userId: string)
|
||||||
|
=> Promise<Image[]> = (userId) => {
|
||||||
|
return new Promise<Image[]>((resolve,reject) => {
|
||||||
|
let imagesRef: any = firebaseRef.child(`userFiles/${userId}/files/images`)
|
||||||
|
|
||||||
}
|
imagesRef.once('value').then((snapshot: any) => {
|
||||||
|
let images = snapshot.val() || {}
|
||||||
|
let parsedImages: Image[] = []
|
||||||
|
Object.keys(images).forEach((imageId) => {
|
||||||
|
parsedImages.push({
|
||||||
|
id: imageId,
|
||||||
|
...images[imageId]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
resolve(parsedImages)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public saveImage: (userId: string, image: Image)
|
||||||
|
=> Promise<string> = (userId, image) => {
|
||||||
|
return new Promise<string>((resolve,reject) => {
|
||||||
|
|
||||||
|
let imageRef = firebaseRef.child(`userFiles/${userId}/files/images`).push(image)
|
||||||
|
imageRef.then(() => {
|
||||||
|
resolve(imageRef.key!)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public deleteImage: (userId: string, imageId: string)
|
||||||
|
=> Promise<void> = (userId, imageId) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`userFiles/${userId}/files/images/${imageId}`] = null
|
||||||
|
|
||||||
|
firebaseRef.update(updates).then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public uploadImage: (file: any, fileName: string, progressCallback: Function)
|
||||||
|
=> Promise<void> = (file, fileName, progressCallback) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
|
||||||
|
let storegeFile: any = storageRef.child(`images/${fileName}`)
|
||||||
|
|
||||||
|
// Upload file
|
||||||
|
let task: any = storegeFile.put(file)
|
||||||
|
|
||||||
|
// Upload storage bar
|
||||||
|
task.on('state_changed', (snapshot: any) => {
|
||||||
|
let percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100
|
||||||
|
progressCallback(percentage)
|
||||||
|
|
||||||
|
}, (error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
}, () => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public downloadImage: (fileName: string)
|
||||||
|
=> Promise<string> = (fileName) => {
|
||||||
|
return new Promise<string>((resolve,reject) => {
|
||||||
|
|
||||||
|
// Create a reference to the file we want to download
|
||||||
|
let starsRef: any = storageRef.child(`images/${fileName}`)
|
||||||
|
|
||||||
|
// Get the download URL
|
||||||
|
starsRef.getDownloadURL().then((url: string) => {
|
||||||
|
resolve(url)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,16 +2,71 @@
|
|||||||
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
||||||
|
|
||||||
import { SocialError } from 'domain/common'
|
import { SocialError } from 'domain/common'
|
||||||
|
import { Notification } from 'domain/notifications'
|
||||||
import { INotificationService } from 'services/notifications'
|
import { INotificationService } from 'services/notifications'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Firbase notification service
|
* Firbase notification service
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @class NotificationService
|
* @class NotificationService
|
||||||
* @implements {INotificationService}
|
* @implements {INotificationService}
|
||||||
*/
|
*/
|
||||||
export class NotificationService implements INotificationService {
|
export class NotificationService implements INotificationService {
|
||||||
|
|
||||||
|
public addNotification: (notification: Notification)
|
||||||
|
=> Promise<void> = (notification: Notification) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
firebaseRef.child(`userNotifies/${notification.notifyRecieverUserId}`)
|
||||||
|
.push(notification)
|
||||||
|
.then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public getNotifications: (userId: string)
|
||||||
|
=> Promise<{ [notifyId: string]: Notification }> = (userId) => {
|
||||||
|
return new Promise<{ [notifyId: string]: Notification }>((resolve,reject) => {
|
||||||
|
let notifiesRef: any = firebaseRef.child(`userNotifies/${userId}`)
|
||||||
|
notifiesRef.on('value', (snapshot: any) => {
|
||||||
|
let notifies: {[notifyId: string]: Notification} = snapshot.val() || {}
|
||||||
|
resolve(notifies)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public deleteNotification: (notificationId: string, userId: string)
|
||||||
|
=> Promise <void> = (notificationId, userId) => {
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`userNotifies/${userId}/${notificationId}`] = null
|
||||||
|
firebaseRef.update(updates)
|
||||||
|
.then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public setSeenNotification: (notificationId: string, userId: string, notification: Notification)
|
||||||
|
=> Promise <void> = (notificationId, userId, notification) => {
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`userNotifies/${userId}/${notificationId}`] = notification
|
||||||
|
firebaseRef.update(updates)
|
||||||
|
.then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code, error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,16 +2,100 @@
|
|||||||
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
||||||
|
|
||||||
import { SocialError } from 'domain/common'
|
import { SocialError } from 'domain/common'
|
||||||
|
import { Post } from 'domain/posts'
|
||||||
import { IPostService } from 'services/posts'
|
import { IPostService } from 'services/posts'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Firbase post service
|
* Firbase post service
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @class PostService
|
* @class PostService
|
||||||
* @implements {IPostService}
|
* @implements {IPostService}
|
||||||
*/
|
*/
|
||||||
export class PostService implements IPostService {
|
export class PostService implements IPostService {
|
||||||
|
|
||||||
|
public addPost: (userId: string, post: Post)
|
||||||
|
=> Promise<string> = (userId, post) => {
|
||||||
|
return new Promise<string>((resolve,reject) => {
|
||||||
|
let postRef: any = firebaseRef.child(`userPosts/${userId}/posts`).push(post)
|
||||||
|
postRef.then(() => {
|
||||||
|
resolve(postRef.key)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public updatePost: (userId: string, postId: string, post: Post)
|
||||||
|
=> Promise<void> = (userId, postId, post) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`userPosts/${userId}/posts/${postId}`] = post
|
||||||
|
firebaseRef.update(updates).then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public deletePost: (userId: string, postId: string)
|
||||||
|
=> Promise<void> = (userId, postId) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`userPosts/${userId}/posts/${postId}`] = null
|
||||||
|
firebaseRef.update(updates).then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public getPosts: (userId: string)
|
||||||
|
=> Promise<{ [postId: string]: Post }> = (userId) => {
|
||||||
|
return new Promise<{ [postId: string]: Post }>((resolve,reject) => {
|
||||||
|
|
||||||
|
let postsRef: any = firebaseRef.child(`userPosts/${userId}/posts`)
|
||||||
|
postsRef.once('value').then((snapshot: any) => {
|
||||||
|
let posts: any = snapshot.val() || {}
|
||||||
|
let parsedPosts: { [postId: string]: Post } = {}
|
||||||
|
|
||||||
|
Object.keys(posts).forEach((postId) => {
|
||||||
|
parsedPosts[postId] = {
|
||||||
|
id: postId,
|
||||||
|
...posts[postId]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
resolve(parsedPosts)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public getPostById: (userId: string, postId: string)
|
||||||
|
=> Promise<Post> = (userId, postId) => {
|
||||||
|
return new Promise<Post>((resolve,reject) => {
|
||||||
|
|
||||||
|
let postsRef: any = firebaseRef.child(`userPosts/${userId}/posts/${postId}`)
|
||||||
|
|
||||||
|
postsRef.once('value').then((snapshot: any) => {
|
||||||
|
let newPost = snapshot.val() || {}
|
||||||
|
let post: Post = {
|
||||||
|
id: postId,
|
||||||
|
...newPost
|
||||||
|
}
|
||||||
|
resolve(post)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,16 +2,72 @@
|
|||||||
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
||||||
|
|
||||||
import { SocialError } from 'domain/common'
|
import { SocialError } from 'domain/common'
|
||||||
|
import { Profile } from 'domain/users'
|
||||||
import { IUserService } from 'services/users'
|
import { IUserService } from 'services/users'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Firbase user service
|
* Firbase user service
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @class UserService
|
* @class UserService
|
||||||
* @implements {IUserService}
|
* @implements {IUserService}
|
||||||
*/
|
*/
|
||||||
export class UserService implements IUserService {
|
export class UserService implements IUserService {
|
||||||
|
public getUserProfile: (userId: string)
|
||||||
|
=> Promise<Profile> = (userId) => {
|
||||||
|
return new Promise<Profile>((resolve,reject) => {
|
||||||
|
let userProfileRef: any = firebaseRef.child(`users/${userId}/info`)
|
||||||
|
|
||||||
|
userProfileRef.once('value').then((snapshot: any) => {
|
||||||
|
let userProfile: Profile = snapshot.val() || {}
|
||||||
|
resolve(userProfile)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public updateUserProfile: (userId: string, profile: Profile)
|
||||||
|
=> Promise<void> = (userId, profile) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
let updates: any = {}
|
||||||
|
|
||||||
|
updates[`users/${userId}/info`] = profile
|
||||||
|
firebaseRef.update(updates).then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
public getUsersProfile: (userId: string)
|
||||||
|
=> Promise<{ [userId: string]: Profile }> = (userId) => {
|
||||||
|
return new Promise<{ [userId: string]: Profile }>((resolve,reject) => {
|
||||||
|
let usersProfileRef: any = firebaseRef.child(`users`)
|
||||||
|
|
||||||
|
usersProfileRef.once('value').then((snapshot: any) => {
|
||||||
|
let usersProfile: any = snapshot.val() || {}
|
||||||
|
let parsedusersProfile: {[userId: string]: Profile} = {}
|
||||||
|
Object.keys(usersProfile).forEach((userId) => {
|
||||||
|
if (userId !== userId) {
|
||||||
|
let userInfo = usersProfile[userId].info
|
||||||
|
parsedusersProfile[userId] = {
|
||||||
|
avatar: userInfo.avatar,
|
||||||
|
email: userInfo.email,
|
||||||
|
fullName: userInfo.fullName,
|
||||||
|
banner: userInfo.banner,
|
||||||
|
tagLine: userInfo.tagLine
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
resolve(parsedusersProfile)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,16 +2,56 @@
|
|||||||
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
import { firebaseRef, firebaseAuth } from 'app/firebase/'
|
||||||
|
|
||||||
import { SocialError } from 'domain/common'
|
import { SocialError } from 'domain/common'
|
||||||
|
import { Vote } from 'domain/votes'
|
||||||
import { IVoteService } from 'services/votes'
|
import { IVoteService } from 'services/votes'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Firbase vote service
|
* Firbase vote service
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @class VoteService
|
* @class VoteService
|
||||||
* @implements {IVoteService}
|
* @implements {IVoteService}
|
||||||
*/
|
*/
|
||||||
export class VoteService implements IVoteService {
|
export class VoteService implements IVoteService {
|
||||||
|
|
||||||
|
public addVote: (vote: Vote)
|
||||||
|
=> Promise<string> = (vote) => {
|
||||||
|
return new Promise<string>((resolve,reject) => {
|
||||||
|
let voteRef = firebaseRef.child(`postVotes/${vote.postId}`)
|
||||||
|
.push(vote)
|
||||||
|
voteRef.then(() => {
|
||||||
|
resolve(voteRef.key!)
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
public getVotes: ()
|
||||||
|
=> Promise<{ [postId: string]: { [voteId: string]: Vote } }> = () => {
|
||||||
|
return new Promise<{ [postId: string]: { [voteId: string]: Vote } }>((resolve,reject) => {
|
||||||
|
let votesRef: any = firebaseRef.child(`postVotes`)
|
||||||
|
|
||||||
}
|
votesRef.on('value',(snapshot: any) => {
|
||||||
|
let postVotes: {[postId: string]: {[voteId: string]: Vote}} = snapshot.val() || {}
|
||||||
|
resolve(postVotes)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public deleteVote: (voteId: string, postId: string)
|
||||||
|
=> Promise<void> = (voteId, postId) => {
|
||||||
|
return new Promise<void>((resolve,reject) => {
|
||||||
|
let updates: any = {}
|
||||||
|
updates[`postVotes/${postId}/${voteId}`] = null
|
||||||
|
firebaseRef.update(updates).then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
reject(new SocialError(error.code,error.message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ import { VoteService } from './VoteService'
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
VoteService
|
VoteService
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
import { Circle } from 'domain/circles'
|
import { Circle } from 'domain/circles'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Circle state
|
* Circle state
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @class CircleState
|
* @class CircleState
|
||||||
*/
|
*/
|
||||||
export class CircleState {
|
export class CircleState {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of Circles belong to users
|
* The list of Circles belong to users
|
||||||
*
|
*
|
||||||
* @type {({[userId: string]: {[circleId: string]: Circle}} | null)}
|
* @type {({[userId: string]: {[circleId: string]: Circle}} | null)}
|
||||||
* @memberof CircleState
|
* @memberof CircleState
|
||||||
*/
|
*/
|
||||||
userCircles: {[userId: string]: {[circleId: string]: Circle}} = {}
|
userCircles: {[userId: string]: {[circleId: string]: Circle}} = {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If user circles are loaded {true} or not {false}
|
* If user circles are loaded {true} or not {false}
|
||||||
*
|
*
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
* @memberof CircleState
|
* @memberof CircleState
|
||||||
*/
|
*/
|
||||||
loaded: Boolean = false
|
loaded: Boolean = false
|
||||||
}
|
}
|
||||||
@@ -7,16 +7,15 @@ import { User } from 'domain/users'
|
|||||||
import { Comment } from 'domain/comments'
|
import { Comment } from 'domain/comments'
|
||||||
|
|
||||||
// - Import action types
|
// - Import action types
|
||||||
import {CommentActionType} from 'constants/commentActionType'
|
import { CommentActionType } from 'constants/commentActionType'
|
||||||
|
|
||||||
|
|
||||||
import { CommentState } from './CommentState'
|
import { CommentState } from './CommentState'
|
||||||
import { ICommentAction } from './ICommentAction'
|
import { ICommentAction } from './ICommentAction'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment reducer
|
* Comment reducer
|
||||||
* @param state
|
* @param state
|
||||||
* @param action
|
* @param action
|
||||||
*/
|
*/
|
||||||
export let commentReducer = (state: CommentState = new CommentState(), action: ICommentAction) => {
|
export let commentReducer = (state: CommentState = new CommentState(), action: ICommentAction) => {
|
||||||
let { payload } = action
|
let { payload } = action
|
||||||
@@ -31,7 +30,7 @@ export let commentReducer = (state: CommentState = new CommentState(), action: I
|
|||||||
[payload.postId]: {
|
[payload.postId]: {
|
||||||
...state.postComments![payload.postId],
|
...state.postComments![payload.postId],
|
||||||
[payload.id]: {
|
[payload.id]: {
|
||||||
...payload.comment,
|
...payload,
|
||||||
editorStatus: false
|
editorStatus: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,7 +43,7 @@ export let commentReducer = (state: CommentState = new CommentState(), action: I
|
|||||||
postComments: {
|
postComments: {
|
||||||
...payload
|
...payload
|
||||||
},
|
},
|
||||||
loaded:true
|
loaded: true
|
||||||
}
|
}
|
||||||
case CommentActionType.UPDATE_COMMENT:
|
case CommentActionType.UPDATE_COMMENT:
|
||||||
return {
|
return {
|
||||||
@@ -112,12 +111,9 @@ export let commentReducer = (state: CommentState = new CommentState(), action: I
|
|||||||
|
|
||||||
case CommentActionType.CLEAR_ALL_DATA_COMMENT:
|
case CommentActionType.CLEAR_ALL_DATA_COMMENT:
|
||||||
return new CommentState()
|
return new CommentState()
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import {ImageGalleryActionType} from 'constants/imageGalleryActionType'
|
import { ImageGalleryActionType } from 'constants/imageGalleryActionType'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageGallery action interface
|
* ImageGallery action interface
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface IImageGalleryAction
|
* @interface IImageGalleryAction
|
||||||
*/
|
*/
|
||||||
export interface IImageGalleryAction {
|
export interface IImageGalleryAction {
|
||||||
payload: any,
|
payload: any,
|
||||||
type: ImageGalleryActionType
|
type: ImageGalleryActionType
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,16 +6,15 @@ import _ from 'lodash'
|
|||||||
import { Notification } from 'domain/notifications'
|
import { Notification } from 'domain/notifications'
|
||||||
|
|
||||||
// - Import action types
|
// - Import action types
|
||||||
import {NotificationActionType} from 'constants/notificationActionType'
|
import { NotificationActionType } from 'constants/notificationActionType'
|
||||||
|
|
||||||
import { NotificationState } from './NotificationState'
|
import { NotificationState } from './NotificationState'
|
||||||
import { INotificationAction } from './INotificationAction'
|
import { INotificationAction } from './INotificationAction'
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify actions
|
* Notify actions
|
||||||
* @param {object} state
|
* @param {object} state
|
||||||
* @param {object} action
|
* @param {object} action
|
||||||
*/
|
*/
|
||||||
export let notificationReducer = (state: NotificationState = new NotificationState(), action: INotificationAction) => {
|
export let notificationReducer = (state: NotificationState = new NotificationState(), action: INotificationAction) => {
|
||||||
let { payload } = action
|
let { payload } = action
|
||||||
@@ -24,29 +23,29 @@ export let notificationReducer = (state: NotificationState = new NotificationSta
|
|||||||
/* _____________ CRUD _____________ */
|
/* _____________ CRUD _____________ */
|
||||||
case NotificationActionType.ADD_NOTIFY:
|
case NotificationActionType.ADD_NOTIFY:
|
||||||
return state
|
return state
|
||||||
|
|
||||||
case NotificationActionType.ADD_NOTIFY_LIST:
|
case NotificationActionType.ADD_NOTIFY_LIST:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
userNotifies: {
|
userNotifies: {
|
||||||
...payload
|
...payload
|
||||||
},
|
},
|
||||||
loaded:true
|
loaded: true
|
||||||
}
|
}
|
||||||
|
|
||||||
case NotificationActionType.SEEN_NOTIFY:
|
case NotificationActionType.SEEN_NOTIFY:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
userNotifies: {
|
userNotifies: {
|
||||||
...state.userNotifies,
|
...state.userNotifies,
|
||||||
[payload]:{
|
[payload]: {
|
||||||
...state.userNotifies![payload],
|
...state.userNotifies![payload],
|
||||||
isSeen:true
|
isSeen: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loaded:true
|
loaded: true
|
||||||
}
|
}
|
||||||
|
|
||||||
case NotificationActionType.DELETE_NOTIFY:
|
case NotificationActionType.DELETE_NOTIFY:
|
||||||
let parsedNotifies = {}
|
let parsedNotifies = {}
|
||||||
Object.keys(state.userNotifies!).map((id) => {
|
Object.keys(state.userNotifies!).map((id) => {
|
||||||
@@ -58,19 +57,16 @@ export let notificationReducer = (state: NotificationState = new NotificationSta
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
userNotifies: {
|
userNotifies: {
|
||||||
...parsedNotifies
|
...parsedNotifies
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case NotificationActionType.CLEAR_ALL_DATA_NOTIFY:
|
case NotificationActionType.CLEAR_ALL_DATA_NOTIFY:
|
||||||
return new NotificationState()
|
return new NotificationState()
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import {UserActionType} from 'constants/userActionType'
|
import { UserActionType } from 'constants/userActionType'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User action interface
|
* User action interface
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface IUserAction
|
* @interface IUserAction
|
||||||
*/
|
*/
|
||||||
export interface IUserAction {
|
export interface IUserAction {
|
||||||
payload: any,
|
payload: any,
|
||||||
type: UserActionType
|
type: UserActionType
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import { User } from 'domain/users'
|
import { User } from 'domain/users'
|
||||||
import { LoginUser, RegisterUserResult } from 'domain/authorize'
|
import { LoginUser, RegisterUserResult } from 'domain/authorize'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authentication service interface
|
* Authentication service interface
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface IAuthorizeService
|
* @interface IAuthorizeService
|
||||||
*/
|
*/
|
||||||
@@ -14,28 +11,28 @@ export interface IAuthorizeService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Login the user
|
* Login the user
|
||||||
*
|
*
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
* @memberof IAuthorizeService
|
* @memberof IAuthorizeService
|
||||||
*/
|
*/
|
||||||
login: (email: string, password: string) => Promise<LoginUser>
|
login: (email: string, password: string) => Promise<LoginUser>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs out the user
|
* Logs out the user
|
||||||
*
|
*
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
* @memberof IAuthorizeService
|
* @memberof IAuthorizeService
|
||||||
*/
|
*/
|
||||||
logout: () => Promise<void>
|
logout: () => Promise<void>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
updatePassword: (newPassword: string) => Promise<void>
|
updatePassword: (newPassword: string) => Promise<void>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
registerUser: (user: User) => Promise<RegisterUserResult>
|
registerUser: (user: User) => Promise<RegisterUserResult>
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,4 +2,4 @@ import { IAuthorizeService } from './IAuthorizeService'
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
IAuthorizeService
|
IAuthorizeService
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,16 @@ import { Circle, UserFollower } from 'domain/circles'
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Circle service interface
|
* Circle service interface
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface ICircleService
|
* @interface ICircleService
|
||||||
*/
|
*/
|
||||||
export interface ICircleService {
|
export interface ICircleService {
|
||||||
|
|
||||||
addCircle: (userId: string, circle: Circle) => Promise<string>
|
addCircle: (userId: string, circle: Circle) => Promise<string>
|
||||||
addFollowingUser: (userId: string, circleId:string, userCircle: User, userFollower: UserFollower, userFollowingId: string) => Promise<void>
|
addFollowingUser: (userId: string, circleId: string, userCircle: User, userFollower: UserFollower, userFollowingId: string) => Promise<void>
|
||||||
deleteFollowingUser: (userId: string, circleId: string,userFollowingId: string) => Promise<void>
|
deleteFollowingUser: (userId: string, circleId: string,userFollowingId: string) => Promise<void>
|
||||||
updateCircle: (userId: string, circle: Circle, circleId: string) => Promise<void>
|
updateCircle: (userId: string, circleId: string, circle: Circle) => Promise<void>
|
||||||
deleteCircle: (circleId: string, userId: string) => Promise<void>
|
deleteCircle: (userId: string, circleId: string) => Promise<void>
|
||||||
getCircles: () => Promise<{ [circleId: string]: Circle }>
|
getCircles: (userId: string) => Promise<{ [circleId: string]: Circle }>
|
||||||
getCirclesByUserId: (userId: string) => Promise<{ [circleId: string]: Circle }>
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
import { User } from 'domain/users'
|
import { User } from 'domain/users'
|
||||||
|
|
||||||
|
import { Comment } from 'domain/comments'
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment service interface
|
* Comment service interface
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface ICommentService
|
* @interface ICommentService
|
||||||
*/
|
*/
|
||||||
export interface ICommentService {
|
export interface ICommentService {
|
||||||
|
|
||||||
|
addComment: (postId: string, comment: Comment) => Promise<string>
|
||||||
|
getComments: () => Promise< {[postId: string]: {[commentId: string]: Comment}} >
|
||||||
|
updateComment: (userId: string, postId: string, comment: Comment) => Promise<void>
|
||||||
|
deleteComment: (commentId: string, postId: string) => Promise<void>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ import { ICommentService } from './ICommentService'
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
ICommentService
|
ICommentService
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
import { User } from 'domain/users'
|
import { User } from 'domain/users'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common service interface
|
* Common service interface
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface ICommonService
|
* @interface ICommonService
|
||||||
*/
|
*/
|
||||||
export interface ICommonService {
|
export interface ICommonService {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ import { ICommonService } from './ICommonService'
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
ICommonService
|
ICommonService
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import { User } from 'domain/users'
|
import { User } from 'domain/users'
|
||||||
|
import { Image } from 'domain/imageGallery'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image gallery service interface
|
* Image gallery service interface
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface IImageGalleryService
|
* @interface IImageGalleryService
|
||||||
*/
|
*/
|
||||||
export interface IImageGalleryService {
|
export interface IImageGalleryService {
|
||||||
|
getImageGallery: (userId: string) => Promise<Image[]>
|
||||||
|
saveImage: (userId: string, image: Image) => Promise<string>
|
||||||
}
|
deleteImage: (userId: string, imageId: string) => Promise<void>
|
||||||
|
uploadImage: (file: any, fileName: string, progressCallback: Function) => Promise<void>
|
||||||
|
downloadImage: (fileName: string) => Promise<string>
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ import { IImageGalleryService } from './IImageGalleryService'
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
IImageGalleryService
|
IImageGalleryService
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import { User } from 'domain/users'
|
import { User } from 'domain/users'
|
||||||
|
|
||||||
|
import { Notification } from 'domain/notifications'
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification service interface
|
* Notification service interface
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface INotificationService
|
* @interface INotificationService
|
||||||
*/
|
*/
|
||||||
export interface INotificationService {
|
export interface INotificationService {
|
||||||
|
addNotification: (notification: Notification) => Promise<void>
|
||||||
|
getNotifications: (userId: string) => Promise<{[notifyId: string]: Notification}>
|
||||||
}
|
deleteNotification: (notificationId: string, userId: string) => Promise<void>
|
||||||
|
setSeenNotification: (notificationId: string, userId: string, notification: Notification) => Promise<void>
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import { User } from 'domain/users'
|
import { User } from 'domain/users'
|
||||||
|
import { Post } from 'domain/posts'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post service interface
|
* Post service interface
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface IPostService
|
* @interface IPostService
|
||||||
*/
|
*/
|
||||||
export interface IPostService {
|
export interface IPostService {
|
||||||
|
addPost: (userId: string, post: Post) => Promise<string>
|
||||||
|
updatePost: (userId: string, postId: string, post: Post) => Promise<void>
|
||||||
}
|
deletePost: (userId: string,postId: string) => Promise<void>
|
||||||
|
getPosts: (userId: string) => Promise<{ [postId: string]: Post }>
|
||||||
|
getPostById: (userId: string, postId: string) => Promise<Post>
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ import { IPostService } from './IPostService'
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
IPostService
|
IPostService
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
import { User } from 'domain/users'
|
import { User, Profile } from 'domain/users'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User service interface
|
* User service interface
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface IUserService
|
* @interface IUserService
|
||||||
*/
|
*/
|
||||||
export interface IUserService {
|
export interface IUserService {
|
||||||
|
getUserProfile: (userId: string) => Promise<Profile>
|
||||||
|
updateUserProfile: (userId: string, profile: Profile) => Promise<void>
|
||||||
}
|
getUsersProfile: (userId: string) => Promise<{[userId: string]: Profile}>
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ import { IUserService } from './IUserService'
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
IUserService
|
IUserService
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { User } from 'domain/users'
|
import { User } from 'domain/users'
|
||||||
|
import { Vote } from 'domain/votes'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vote service interface
|
* Vote service interface
|
||||||
@@ -7,5 +8,7 @@ import { User } from 'domain/users'
|
|||||||
* @interface IVoteService
|
* @interface IVoteService
|
||||||
*/
|
*/
|
||||||
export interface IVoteService {
|
export interface IVoteService {
|
||||||
|
addVote: (vote: Vote) => Promise<string>
|
||||||
|
getVotes: () => Promise<{[postId: string]: {[voteId: string]: Vote}}>
|
||||||
|
deleteVote: (voteId: string, postId: string) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ import { IVoteService } from './IVoteService'
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
IVoteService
|
IVoteService
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user