Social: Use SocialPost API

pull/4161/head
Angel Fernando Quiroz Campos 4 years ago
parent c744d5a824
commit a2bd34a0b8
  1. 20
      assets/vue/components/social/PostForm.vue
  2. 18
      assets/vue/components/social/WallComment.vue
  3. 39
      assets/vue/components/social/WallPost.vue
  4. 31
      assets/vue/components/social/WallPostList.vue
  5. 6
      assets/vue/components/social/constants.js
  6. 8
      assets/vue/main.js
  7. 3
      assets/vue/services/socialpost.js
  8. 14
      src/CoreBundle/Entity/SocialPost.php
  9. 4
      src/CoreBundle/Entity/User.php

@ -39,7 +39,7 @@
<script>
import {inject, onMounted, reactive, toRefs, watch} from "vue";
import {useStore} from "vuex";
import {MESSAGE_REL_USER_TYPE_TO, MESSAGE_TYPE_WALL} from "../message/constants";
import {SOCIAL_TYPE_WALL_POST} from "./constants";
import useVuelidate from "@vuelidate/core";
import {required} from "@vuelidate/validators";
import {useI18n} from "vue-i18n";
@ -77,25 +77,19 @@ export default {
return;
}
const messagePayload = {
title: 'Post',
const createPostPayload = {
content: postState.content,
msgType: MESSAGE_TYPE_WALL,
type: SOCIAL_TYPE_WALL_POST,
sender: currentUser['@id'],
receivers: [
{
receiver: user.value['@id'],
receiverType: MESSAGE_REL_USER_TYPE_TO
}
]
userReceiver: user.value['@id']
};
await store.dispatch('message/create', messagePayload);
await store.dispatch('socialpost/create', createPostPayload);
if (postState.attachment) {
const message = store.state.message.created;
const post = store.state.socialpost.created;
const attachmentPayload = {
messageId: message.id,
postId: post.id,
file: postState.attachment
};

@ -14,16 +14,16 @@
<q-item-section side top>
<q-btn
v-if="enableMessagesFeedbackConfig"
:label="comment.countLikes"
v-if="enableFeedback"
:label="comment.countFeedbackLikes"
:title="$t('Like')"
dense
flat
icon="mdi-heart-plus"
/>
<q-btn
v-if="enableMessagesFeedbackConfig && !disableDislikeOption"
:label="comment.countDislikes"
v-if="enableFeedback && !disableDislike"
:label="comment.countFeedbackDislikes"
:title="$t('Dislike')"
dense
flat
@ -61,18 +61,18 @@ export default {
function deleteComment() {
store
.dispatch('message/del', props.comment)
.dispatch('socialpost/del', props.comment)
.then(() => context.emit('deleted'));
}
const enableMessagesFeedbackConfig = ref(window.config['social.social_enable_messages_feedback'] === 'true');
const disableDislikeOption = ref(window.config['social.disable_dislike_option'] === 'true');
const enableFeedback = ref(window.config['social.social_enable_messages_feedback'] === 'true');
const disableDislike = ref(window.config['social.disable_dislike_option'] === 'true');
return {
deleteComment,
isOwner: currentUser['@id'] === props.comment.sender['@id'],
enableMessagesFeedbackConfig,
disableDislikeOption,
enableFeedback,
disableDislike,
};
}
}

@ -7,31 +7,31 @@
<q-item>
<q-item-section side>
<q-avatar>
<q-img :alt="message.sender.username" :src="message.sender.illustrationUrl" />
<q-img :alt="post.sender.username" :src="post.sender.illustrationUrl" />
</q-avatar>
</q-item-section>
<q-item-section>
<q-item-label
v-if="!message.firstReceiver || (message.firstReceiver && message.sender['@id'] === message.firstReceiver.receiver['@id'])"
v-if="null === post.userReceiver || post.sender['@id'] === post.userReceiver['@id']"
>
<router-link :to="{ name: 'SocialkWall', query: { id: message.sender['@id']} }">
{{ message.sender.username }}
<router-link :to="{ name: 'SocialWall', query: { id: post.sender['@id']} }">
{{ post.sender.username }}
</router-link>
</q-item-label>
<q-item-label v-else>
<router-link :to="{ name: 'SocialWall', query: { id: message.sender['@id']} }">
{{ message.sender.username }}
<router-link :to="{ name: 'SocialWall', query: { id: post.sender['@id']} }">
{{ post.sender.username }}
</router-link>
&raquo;
<router-link :to="{ name: 'SocialkWall', query: { id: message.firstReceiver.receiver['@id']} }">
{{ message.firstReceiver.receiver.username }}
<router-link :to="{ name: 'SocialWall', query: { id: post.userReceiver['@id']} }">
{{ post.userReceiver.username }}
</router-link>
</q-item-label>
<q-item-label caption>
{{ $filters.abbreviatedDatetime(message.sendDate) }}
{{ $filters.abbreviatedDatetime(post.sendDate) }}
</q-item-label>
</q-item-section>
</q-item>
@ -47,7 +47,7 @@
:alt="attachment.comment"
:src="attachment.contentUrl"
/>
<q-card-section v-html="message.content" />
<q-card-section v-html="post.content" />
<q-separator />
@ -64,7 +64,7 @@
/>
</q-list>
<WallCommentForm :post="message" />
<WallCommentForm :post="post" />
</q-card>
</template>
@ -72,35 +72,36 @@
import WallCommentForm from "./CommentForm";
import {onMounted, reactive} from "vue";
import WallComment from "./WallComment";
import {MESSAGE_TYPE_WALL} from "../message/constants";
import {SOCIAL_TYPE_WALL_COMMENT} from "./constants";
import {useStore} from "vuex";
export default {
name: "WallPost",
components: {WallComment, WallCommentForm},
props: {
message: {
post: {
type: Object,
required: true
}
},
setup(props) {
const attachment = props.message.attachments.length ? props.message.attachments[0] : null;
const attachment = null;//props.post.attachments.length ? props.post.attachments[0] : null;
let comments = reactive([]);
const containsImage = attachment && attachment.resourceNode.resourceFile.mimeType.includes('image/');
const containsVideo = attachment && attachment.resourceNode.resourceFile.mimeType.includes('video/');
const containsImage = false; //attachment && attachment.resourceNode.resourceFile.mimeType.includes('image/');
const containsVideo = false; //attachment && attachment.resourceNode.resourceFile.mimeType.includes('video/');
function loadComments() {
const store = useStore();
store
.dispatch(
'message/findAll',
'socialpost/findAll',
{
parent: props.message['@id'],
msgType: MESSAGE_TYPE_WALL,
parent: props.post['@id'],
type: SOCIAL_TYPE_WALL_COMMENT,
'order[sendDate]': 'desc',
itemsPerPage: 3
}
)
.then(response => comments.push(...response));

@ -1,15 +1,16 @@
<template>
<WallPost
v-for="message in messageList"
:key="message.id"
:message="message"
v-for="socialPost in postList"
:key="socialPost.id"
:post="socialPost"
/>
<Loading :visible="isLoading" />
</template>
<script>
import {MESSAGE_TYPE_WALL} from "../message/constants";
import {SOCIAL_TYPE_WALL_POST} from "./constants";
import WallPost from "./WallPost";
import {useStore} from "vuex";
import {inject, onMounted, ref, watch} from "vue";
@ -22,38 +23,38 @@ export default {
const user = inject('social-user');
const store = useStore();
const messageList = ref([]);
const postList = ref([]);
const isLoading = ref(false);
async function listMessage() {
async function listPosts() {
if (!user.value['@id']) {
return;
}
isLoading.value = true;
store.state.message.resetList = true;
store.state.socialpost.resetList = true;
try {
await store.dispatch('message/fetchAll', {
msgType: MESSAGE_TYPE_WALL,
'receivers.receiver': user.value['@id'],
postList.value = await store.dispatch('socialpost/findAll', {
type: SOCIAL_TYPE_WALL_POST,
sender: user.value['@id'],
'order[sendDate]': 'desc',
groupReceiver: null
});
messageList.value = store.getters['message/list'];
} catch (e) {
messageList.value = [];
postList.value = [];
}
isLoading.value = false;
}
watch(() => user.value, listMessage)
watch(() => user.value, listPosts)
onMounted(listMessage)
onMounted(listPosts)
return {
messageList,
postList,
isLoading
}
}

@ -0,0 +1,6 @@
export const SOCIAL_TYPE_WALL_POST = 1;
export const SOCIAL_TYPE_WALL_COMMENT = 2;
export const SOCIAL_TYPE_GROUP_MESSAGE = 3;
export const SOCIAL_TYPE_PROMOTED_MESSAGE = 4;
export const SOCIAL_STATUS_DELETED = 2;
export const SOCIAL_STATUS_SENT = 1;

@ -24,6 +24,7 @@ import toolIntroService from './services/ctoolintro';
import pageService from './services/page';
import pageCategoryService from './services/pagecategory';
import sessionService from './services/session';
import socialPostService from './services/socialpost';
import makeCrudModule from './store/modules/crud';
//import vuetify from './plugins/vuetify' // path to vuetify export
@ -163,6 +164,13 @@ store.registerModule(
})
);
store.registerModule(
'socialpost',
makeCrudModule({
service: socialPostService
})
);
// Vuetify.
import '@mdi/font/css/materialdesignicons.css';
//import 'vuetify/lib/styles/main.sass';

@ -0,0 +1,3 @@
import makeService from './api';
export default makeService('social_posts');

@ -1,4 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity;
@ -54,19 +57,20 @@ class SocialPost
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="sentSocialPosts")
* @ORM\JoinColumn(nullable=false)
*/
#[Groups(['social_post:read'])]
#[Groups(['social_post:read', 'social_post:write'])]
protected User $sender;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="receivedSocialPosts")
* @ORM\JoinColumn(nullable=true)
*/
#[Groups(['social_post:read'])]
#[Groups(['social_post:read', 'social_post:write'])]
protected User $userReceiver;
/**
* @ORM\Column(type="text")
*/
#[Groups(['social_post:read'])]
#[Groups(['social_post:read', 'social_post:write'])]
protected string $content;
/**
@ -80,6 +84,7 @@ class SocialPost
* )
* @ORM\Column(type="smallint")
*/
#[Groups(['social_post:write', 'social_post:read'])]
protected int $type;
/**
@ -102,7 +107,6 @@ class SocialPost
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
#[Groups(['social_post:read'])]
protected DateTime $updatedAt;
/**
@ -125,6 +129,7 @@ class SocialPost
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\SocialPost", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
#[Groups(['social_post:write'])]
protected ?SocialPost $parent = null;
#[Groups(['social_post:read'])]
@ -139,6 +144,7 @@ class SocialPost
$this->updatedAt = $this->sendDate;
$this->status = self::STATUS_SENT;
$this->feedbacks = new ArrayCollection();
$this->type = self::TYPE_WALL_POST;
}
public function getId(): int

@ -127,6 +127,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
'user_json:read',
'message:read',
'user_rel_user:read',
'social_post:read',
])]
public ?string $illustrationUrl = null;
@ -158,6 +159,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
'message:read',
'page:read',
'user_rel_user:read',
'social_post:read',
])]
protected string $username;
@ -793,7 +795,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
// Property used only during installation.
protected bool $skipResourceNode = false;
#[Groups(['user:read', 'user_json:read'])]
#[Groups(['user:read', 'user_json:read', 'social_post:read'])]
protected string $fullName;
/**

Loading…
Cancel
Save