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

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

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

@ -1,15 +1,16 @@
<template> <template>
<WallPost <WallPost
v-for="message in messageList" v-for="socialPost in postList"
:key="message.id" :key="socialPost.id"
:message="message" :post="socialPost"
/> />
<Loading :visible="isLoading" /> <Loading :visible="isLoading" />
</template> </template>
<script> <script>
import {MESSAGE_TYPE_WALL} from "../message/constants"; import {SOCIAL_TYPE_WALL_POST} from "./constants";
import WallPost from "./WallPost"; import WallPost from "./WallPost";
import {useStore} from "vuex"; import {useStore} from "vuex";
import {inject, onMounted, ref, watch} from "vue"; import {inject, onMounted, ref, watch} from "vue";
@ -22,38 +23,38 @@ export default {
const user = inject('social-user'); const user = inject('social-user');
const store = useStore(); const store = useStore();
const messageList = ref([]); const postList = ref([]);
const isLoading = ref(false); const isLoading = ref(false);
async function listMessage() { async function listPosts() {
if (!user.value['@id']) { if (!user.value['@id']) {
return; return;
} }
isLoading.value = true; isLoading.value = true;
store.state.message.resetList = true; store.state.socialpost.resetList = true;
try { try {
await store.dispatch('message/fetchAll', { postList.value = await store.dispatch('socialpost/findAll', {
msgType: MESSAGE_TYPE_WALL, type: SOCIAL_TYPE_WALL_POST,
'receivers.receiver': user.value['@id'], sender: user.value['@id'],
'order[sendDate]': 'desc', 'order[sendDate]': 'desc',
groupReceiver: null
}); });
messageList.value = store.getters['message/list'];
} catch (e) { } catch (e) {
messageList.value = []; postList.value = [];
} }
isLoading.value = false; isLoading.value = false;
} }
watch(() => user.value, listMessage) watch(() => user.value, listPosts)
onMounted(listMessage) onMounted(listPosts)
return { return {
messageList, postList,
isLoading 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 pageService from './services/page';
import pageCategoryService from './services/pagecategory'; import pageCategoryService from './services/pagecategory';
import sessionService from './services/session'; import sessionService from './services/session';
import socialPostService from './services/socialpost';
import makeCrudModule from './store/modules/crud'; import makeCrudModule from './store/modules/crud';
//import vuetify from './plugins/vuetify' // path to vuetify export //import vuetify from './plugins/vuetify' // path to vuetify export
@ -163,6 +164,13 @@ store.registerModule(
}) })
); );
store.registerModule(
'socialpost',
makeCrudModule({
service: socialPostService
})
);
// Vuetify. // Vuetify.
import '@mdi/font/css/materialdesignicons.css'; import '@mdi/font/css/materialdesignicons.css';
//import 'vuetify/lib/styles/main.sass'; //import 'vuetify/lib/styles/main.sass';

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

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

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

Loading…
Cancel
Save