|
|
@ -10,8 +10,8 @@ import {BaseService} from '../base.service';
|
|
|
|
import {formatDate} from '@angular/common';
|
|
|
|
import {formatDate} from '@angular/common';
|
|
|
|
import {IFileUploadResult} from '../../models/interfaces/IFileUploadResult';
|
|
|
|
import {IFileUploadResult} from '../../models/interfaces/IFileUploadResult';
|
|
|
|
|
|
|
|
|
|
|
|
const createPostGqlQuery = `mutation($content: String!) {
|
|
|
|
const createPostGqlQuery = `mutation($content: String!, $type: PostType) {
|
|
|
|
createPost(content: $content) {
|
|
|
|
createPost(content: $content, type: $type) {
|
|
|
|
id,
|
|
|
|
id,
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
htmlContent,
|
|
|
|
htmlContent,
|
|
|
@ -34,8 +34,8 @@ const createPostGqlQuery = `mutation($content: String!) {
|
|
|
|
createdAt}
|
|
|
|
createdAt}
|
|
|
|
}`;
|
|
|
|
}`;
|
|
|
|
|
|
|
|
|
|
|
|
const createPostActivityGqlQuery = `mutation($content: String!, $id: ID) {
|
|
|
|
const createPostActivityGqlQuery = `mutation($content: String!, $id: ID, $type: PostType) {
|
|
|
|
createPost(content: $content activityId: $id) {
|
|
|
|
createPost(content: $content activityId: $id, type: $type) {
|
|
|
|
id,
|
|
|
|
id,
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
htmlContent,
|
|
|
|
htmlContent,
|
|
|
@ -70,7 +70,7 @@ const downvotePostGqlQuery = `mutation($postId: ID!) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
}`;
|
|
|
|
|
|
|
|
|
|
|
|
const getPostGqlQuery = `query($first: Int, $offset: Int, $sort: SortType){
|
|
|
|
const getPostsGqlQuery = `query($first: Int, $offset: Int, $sort: SortType){
|
|
|
|
getPosts (first: $first, offset: $offset, sort: $sort) {
|
|
|
|
getPosts (first: $first, offset: $offset, sort: $sort) {
|
|
|
|
id,
|
|
|
|
id,
|
|
|
|
content,
|
|
|
|
content,
|
|
|
@ -122,7 +122,7 @@ export class FeedService extends BaseService {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static buildGetPostBody(sort: string, offset: number, first: number = 10) {
|
|
|
|
private static buildGetPostBody(sort: string, offset: number, first: number = 10) {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
query: getPostGqlQuery, variables: {
|
|
|
|
query: getPostsGqlQuery, variables: {
|
|
|
|
first,
|
|
|
|
first,
|
|
|
|
offset,
|
|
|
|
offset,
|
|
|
|
sort
|
|
|
|
sort
|
|
|
@ -145,10 +145,15 @@ export class FeedService extends BaseService {
|
|
|
|
* @param file
|
|
|
|
* @param file
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public createPost(pContent: String, file?: File) {
|
|
|
|
public createPost(pContent: String, file?: File) {
|
|
|
|
|
|
|
|
let type: string;
|
|
|
|
|
|
|
|
if (file) { type = 'MEDIA'; } else {
|
|
|
|
|
|
|
|
type = 'TEXT';
|
|
|
|
|
|
|
|
}
|
|
|
|
const body = {
|
|
|
|
const body = {
|
|
|
|
query: createPostGqlQuery,
|
|
|
|
query: createPostGqlQuery,
|
|
|
|
variables: {
|
|
|
|
variables: {
|
|
|
|
content: pContent
|
|
|
|
content: pContent,
|
|
|
|
|
|
|
|
type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return this.createPostRequest(body, file);
|
|
|
|
return this.createPostRequest(body, file);
|
|
|
@ -161,10 +166,15 @@ export class FeedService extends BaseService {
|
|
|
|
* @param file
|
|
|
|
* @param file
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public createPostActivity(pContent: String, activityId: String, file?: File) {
|
|
|
|
public createPostActivity(pContent: String, activityId: String, file?: File) {
|
|
|
|
|
|
|
|
let type: string;
|
|
|
|
|
|
|
|
if (file) { type = 'MEDIA'; } else {
|
|
|
|
|
|
|
|
type = 'TEXT';
|
|
|
|
|
|
|
|
}
|
|
|
|
const body = {
|
|
|
|
const body = {
|
|
|
|
query: createPostActivityGqlQuery, variables: {
|
|
|
|
query: createPostActivityGqlQuery, variables: {
|
|
|
|
content: pContent,
|
|
|
|
content: pContent,
|
|
|
|
id: activityId
|
|
|
|
id: activityId,
|
|
|
|
|
|
|
|
type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return this.createPostRequest(body, file);
|
|
|
|
return this.createPostRequest(body, file);
|
|
|
@ -176,26 +186,34 @@ export class FeedService extends BaseService {
|
|
|
|
* @param file - a file that is being uploaded with the post
|
|
|
|
* @param file - a file that is being uploaded with the post
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private createPostRequest(body: { variables: any; query: string }, file?: File) {
|
|
|
|
private createPostRequest(body: { variables: any; query: string }, file?: File) {
|
|
|
|
return this.postGraphql(body, null, 0)
|
|
|
|
if (file) {
|
|
|
|
|
|
|
|
return this.postGraphql(body, null, 0)
|
|
|
|
.pipe(tap(response => {
|
|
|
|
.pipe(tap(response => {
|
|
|
|
|
|
|
|
const updatedPosts = this.posts.getValue();
|
|
|
|
if (this.activePostList === Sort.NEW) {
|
|
|
|
if (this.activePostList === Sort.NEW) {
|
|
|
|
const updatedPosts = this.posts.getValue();
|
|
|
|
|
|
|
|
const post = this.constructPost(response);
|
|
|
|
const post = this.constructPost(response);
|
|
|
|
updatedPosts.unshift(post);
|
|
|
|
this.uploadPostImage(post.id, file).subscribe((result) => {
|
|
|
|
if (file) {
|
|
|
|
post.mediaUrl = result.fileName;
|
|
|
|
this.uploadPostImage(post.id, file).subscribe((result) => {
|
|
|
|
post.mediaType = result.fileName.endsWith('.png') ? 'IMAGE' : 'VIDEO';
|
|
|
|
post.mediaUrl = result.fileName;
|
|
|
|
updatedPosts.unshift(post);
|
|
|
|
post.mediaType = result.fileName.endsWith('.png') ? 'IMAGE' : 'VIDEO';
|
|
|
|
|
|
|
|
this.posts.next(updatedPosts);
|
|
|
|
|
|
|
|
}, error => {
|
|
|
|
|
|
|
|
console.error(error);
|
|
|
|
|
|
|
|
this.deletePost(post.id);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.posts.next(updatedPosts);
|
|
|
|
this.posts.next(updatedPosts);
|
|
|
|
}
|
|
|
|
}, error => {
|
|
|
|
|
|
|
|
console.error(error);
|
|
|
|
|
|
|
|
this.deletePost(post.id);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
} else if (!file) {
|
|
|
|
|
|
|
|
return this.postGraphql(body, null, 0)
|
|
|
|
|
|
|
|
.pipe(tap(response => {
|
|
|
|
|
|
|
|
const updatedPosts = this.posts.getValue();
|
|
|
|
|
|
|
|
if (this.activePostList === Sort.NEW) {
|
|
|
|
|
|
|
|
const post = this.constructPost(response);
|
|
|
|
|
|
|
|
updatedPosts.unshift(post);
|
|
|
|
|
|
|
|
this.posts.next(updatedPosts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|