|
|
|
@ -1,14 +1,14 @@
|
|
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
|
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
|
|
|
|
|
import {Post} from 'src/app/models/post';
|
|
|
|
|
import {Author} from 'src/app/models/author';
|
|
|
|
|
import {environment} from 'src/environments/environment';
|
|
|
|
|
import {Activity} from 'src/app/models/activity';
|
|
|
|
|
import {BehaviorSubject, Observable} from 'rxjs';
|
|
|
|
|
import {tap} from 'rxjs/operators';
|
|
|
|
|
import {BaseService} from '../base.service';
|
|
|
|
|
import {formatDate} from '@angular/common';
|
|
|
|
|
import {IFileUploadResult} from '../../models/interfaces/IFileUploadResult';
|
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
|
|
|
|
import { Post } from 'src/app/models/post';
|
|
|
|
|
import { Author } from 'src/app/models/author';
|
|
|
|
|
import { environment } from 'src/environments/environment';
|
|
|
|
|
import { Activity } from 'src/app/models/activity';
|
|
|
|
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
|
|
|
import { tap } from 'rxjs/operators';
|
|
|
|
|
import { BaseService } from '../base.service';
|
|
|
|
|
import { formatDate } from '@angular/common';
|
|
|
|
|
import { IFileUploadResult } from '../../models/interfaces/IFileUploadResult';
|
|
|
|
|
import { IErrorResponse } from 'src/app/models/interfaces/IErrorResponse';
|
|
|
|
|
|
|
|
|
|
const createPostGqlQuery = `mutation($content: String!, $type: PostType) {
|
|
|
|
@ -71,6 +71,12 @@ const downvotePostGqlQuery = `mutation($postId: ID!) {
|
|
|
|
|
}
|
|
|
|
|
}`;
|
|
|
|
|
|
|
|
|
|
const reportPostGqlQuery = `mutation($reasonId: ID!, $postId: ID!) {
|
|
|
|
|
reportPost(postId: $postId, reasonId: $reasonId) {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
}`;
|
|
|
|
|
|
|
|
|
|
const getPostsGqlQuery = `query($first: Int, $offset: Int, $sort: SortType){
|
|
|
|
|
getPosts (first: $first, offset: $offset, sort: $sort) {
|
|
|
|
|
id,
|
|
|
|
@ -300,6 +306,22 @@ export class FeedService extends BaseService {
|
|
|
|
|
return this.postGraphql(body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* reports a post
|
|
|
|
|
* @param postId
|
|
|
|
|
* @param reasonId
|
|
|
|
|
*/
|
|
|
|
|
public reportPost(reasonId: number, postId: number): any {
|
|
|
|
|
const body = {
|
|
|
|
|
query: reportPostGqlQuery, variables: {
|
|
|
|
|
postId,
|
|
|
|
|
reasonId
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return this.postGraphql(body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deletes a post
|
|
|
|
|
* @param pPostID
|
|
|
|
@ -312,7 +334,7 @@ export class FeedService extends BaseService {
|
|
|
|
|
postId: pPostID
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return this.http.post(environment.graphQLUrl, body, {headers: this.headers})
|
|
|
|
|
return this.http.post(environment.graphQLUrl, body, { headers: this.headers })
|
|
|
|
|
.pipe(this.retryRated());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -325,7 +347,7 @@ export class FeedService extends BaseService {
|
|
|
|
|
this.postsAvailable.next(true);
|
|
|
|
|
this.posts.next([]);
|
|
|
|
|
return this.http.post(environment.graphQLUrl, FeedService.buildGetPostBody(sort, 0),
|
|
|
|
|
{headers: this.headers})
|
|
|
|
|
{ headers: this.headers })
|
|
|
|
|
.pipe(this.retryRated())
|
|
|
|
|
.subscribe(response => {
|
|
|
|
|
this.posts.next(this.constructAllPosts(response.data.getPosts));
|
|
|
|
@ -339,7 +361,7 @@ export class FeedService extends BaseService {
|
|
|
|
|
public getNextPosts() {
|
|
|
|
|
this.offset += this.offsetStep;
|
|
|
|
|
const body = FeedService.buildGetPostBody(this.activePostList, this.offset);
|
|
|
|
|
this.http.post(environment.graphQLUrl, body, {headers: this.headers})
|
|
|
|
|
this.http.post(environment.graphQLUrl, body, { headers: this.headers })
|
|
|
|
|
.pipe(this.retryRated())
|
|
|
|
|
.subscribe(response => {
|
|
|
|
|
const posts = this.constructAllPosts(response.data.getPosts);
|
|
|
|
|