From b3b41ad7773550e700675d42c76d9a54e8c6a285 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 25 Oct 2019 17:43:37 +0200 Subject: [PATCH] Refactor Core things, including Ecto handling, ActivityPub & Transmogrifier modules * Data doesn't need anymore to be converted to ActivityStream format to be saved (this was taken from Pleroma and not at all a good idea here) * Everything saved when creating an event is inserted into PostgreSQL in a single transaction --- js/src/components/Event/EventListCard.vue | 14 +- js/src/graphql/actor.ts | 9 +- js/src/graphql/event.ts | 24 +- js/src/mixins/event.ts | 6 +- js/src/types/event.model.ts | 11 +- js/src/views/Event/Event.vue | 32 +- js/src/views/Event/Participants.vue | 18 +- .../tasks/mobilizon/move_participant_stats.ex | 67 +++ lib/mix/tasks/mobilizon/setup_search.ex | 49 +++ lib/mix/tasks/mobilizon/toot.ex | 14 +- lib/mobilizon/actors/actor.ex | 3 + lib/mobilizon/actors/actors.ex | 5 +- lib/mobilizon/addresses/address.ex | 3 +- lib/mobilizon/events/comment.ex | 40 +- lib/mobilizon/events/event.ex | 152 +++++-- .../events/event_participant_stats.ex | 44 ++ lib/mobilizon/events/events.ex | 283 +++++++----- lib/mobilizon/mentions/mention.ex | 53 +++ lib/mobilizon_web/api/comments.ex | 45 +- lib/mobilizon_web/api/events.ex | 110 ++--- lib/mobilizon_web/api/follows.ex | 16 +- lib/mobilizon_web/api/groups.ex | 37 +- lib/mobilizon_web/api/participations.ex | 11 +- lib/mobilizon_web/api/utils.ex | 95 ---- lib/mobilizon_web/resolvers/comment.ex | 12 +- lib/mobilizon_web/resolvers/event.ex | 60 +-- lib/mobilizon_web/resolvers/group.ex | 28 +- lib/mobilizon_web/resolvers/person.ex | 2 +- lib/mobilizon_web/resolvers/picture.ex | 2 +- lib/mobilizon_web/schema/comment.ex | 2 +- lib/mobilizon_web/schema/event.ex | 16 +- lib/mobilizon_web/upload.ex | 24 +- lib/service/activity_pub/activity_pub.ex | 410 ++++++++++++++---- lib/service/activity_pub/audience.ex | 98 +++++ lib/service/activity_pub/converter/actor.ex | 23 +- lib/service/activity_pub/converter/comment.ex | 103 +++-- lib/service/activity_pub/converter/event.ex | 77 ++-- .../activity_pub/converter/follower.ex | 36 ++ lib/service/activity_pub/converter/utils.ex | 100 +++++ lib/service/activity_pub/relay.ex | 8 +- lib/service/activity_pub/transmogrifier.ex | 219 +++++----- lib/service/activity_pub/utils.ex | 57 ++- lib/service/federator.ex | 2 +- lib/service/http_signatures/signature.ex | 2 +- ...materialized_view_for_searching_events.exs | 36 -- ...43659_move_participants_stats_to_event.exs | 15 + .../20191024204726_add_tags_to_comments.exs | 14 + .../20191025083642_add_mention_tables.exs | 16 + ...191025115537_add_unique_index_on_ur_ls.exs | 8 + schema.graphql | 23 +- .../mastodon-post-activity-hashtag.json | 8 +- test/fixtures/mastodon-post-activity.json | 8 +- test/fixtures/mobilizon-post-activity.json | 10 +- .../fetch_framasoft_framapiaf_reply.json | 182 +++----- .../fetch_reply_to_framatube.json | 252 +++-------- .../mastodon-post-activity_actor_call.json | 78 ++-- test/mobilizon/actors/actors_test.exs | 10 +- test/mobilizon/events/events_test.exs | 7 +- .../activity_pub/activity_pub_test.exs | 54 +-- .../activity_pub/converter/actor_test.exs | 2 +- .../activity_pub/transmogrifier_test.exs | 49 +-- .../service/activity_pub/utils_test.exs | 13 +- .../plugs/uploaded_media_plug_test.exs | 3 +- .../resolvers/comment_resolver_test.exs | 2 +- .../resolvers/event_resolver_test.exs | 17 +- .../resolvers/group_resolver_test.exs | 3 +- .../resolvers/participant_resolver_test.exs | 22 +- test/mobilizon_web/upload_test.exs | 36 +- test/support/factory.ex | 15 +- 69 files changed, 1881 insertions(+), 1424 deletions(-) create mode 100644 lib/mix/tasks/mobilizon/move_participant_stats.ex create mode 100644 lib/mix/tasks/mobilizon/setup_search.ex create mode 100644 lib/mobilizon/events/event_participant_stats.ex create mode 100644 lib/mobilizon/mentions/mention.ex create mode 100644 lib/service/activity_pub/audience.ex create mode 100644 lib/service/activity_pub/converter/follower.ex create mode 100644 lib/service/activity_pub/converter/utils.ex create mode 100644 priv/repo/migrations/20191023143659_move_participants_stats_to_event.exs create mode 100644 priv/repo/migrations/20191024204726_add_tags_to_comments.exs create mode 100644 priv/repo/migrations/20191025083642_add_mention_tables.exs create mode 100644 priv/repo/migrations/20191025115537_add_unique_index_on_ur_ls.exs diff --git a/js/src/components/Event/EventListCard.vue b/js/src/components/Event/EventListCard.vue index c14945a71..46115a553 100644 --- a/js/src/components/Event/EventListCard.vue +++ b/js/src/components/Event/EventListCard.vue @@ -14,7 +14,7 @@ export default { data() { return { participation: { - event: { + event: { title: 'Vue Styleguidist first meetup: learn the basics!', id: 5, uuid: 'some uuid', @@ -31,7 +31,7 @@ export default { }, participantStats: { approved: 1, - unapproved: 2 + notApproved: 2 } }, actor: { @@ -75,20 +75,20 @@ export default { - {{ $t('{approved} / {total} seats', {approved: participation.event.participantStats.participants, total: participation.event.options.maximumAttendeeCapacity }) }} + {{ $t('{approved} / {total} seats', {approved: participation.event.participantStats.participant, total: participation.event.options.maximumAttendeeCapacity }) }} - + - {{ $tc('{count} participants', participation.event.participantStats.participants, { count: participation.event.participantStats.participants })}} + {{ $tc('{count} participants', participation.event.participantStats.participant, { count: participation.event.participantStats.participant })}} + v-if="participation.event.participantStats.notApproved > 0"> - {{ $tc('{count} requests waiting', participation.event.participantStats.unapproved, { count: participation.event.participantStats.unapproved })}} + {{ $tc('{count} requests waiting', participation.event.participantStats.notApproved, { count: participation.event.participantStats.notApproved })}} diff --git a/js/src/graphql/actor.ts b/js/src/graphql/actor.ts index 6bb8d88eb..68e8c29b4 100644 --- a/js/src/graphql/actor.ts +++ b/js/src/graphql/actor.ts @@ -113,9 +113,8 @@ query LoggedUserParticipations($afterDateTime: DateTime, $beforeDateTime: DateTi } }, participantStats { - approved, - unapproved, - participants + notApproved + participant }, options { maximumAttendeeCapacity @@ -161,8 +160,8 @@ export const LOGGED_USER_DRAFTS = gql` } }, participantStats { - approved, - unapproved + going, + notApproved }, options { maximumAttendeeCapacity diff --git a/js/src/graphql/event.ts b/js/src/graphql/event.ts index 3dc947bea..d4620d5ed 100644 --- a/js/src/graphql/event.ts +++ b/js/src/graphql/event.ts @@ -102,9 +102,9 @@ export const FETCH_EVENT = gql` # name, # }, participantStats { - approved, - unapproved, - participants + going, + notApproved, + participant }, tags { ${tagsQuery} @@ -259,9 +259,9 @@ export const CREATE_EVENT = gql` id, }, participantStats { - approved, - unapproved, - participants + going, + notApproved, + participant }, tags { ${tagsQuery} @@ -344,9 +344,9 @@ export const EDIT_EVENT = gql` id, }, participantStats { - approved, - unapproved, - participants + going, + notApproved, + participant }, tags { ${tagsQuery} @@ -410,10 +410,10 @@ export const PARTICIPANTS = gql` ${participantQuery} }, participantStats { - approved, - unapproved, + going, + notApproved, rejected, - participants + participant } } } diff --git a/js/src/mixins/event.ts b/js/src/mixins/event.ts index 5aefb7a6c..f35c3aeac 100644 --- a/js/src/mixins/event.ts +++ b/js/src/mixins/event.ts @@ -8,10 +8,10 @@ import { IPerson } from '@/types/actor'; @Component export default class EventMixin extends mixins(Vue) { async openDeleteEventModal (event: IEvent, currentActor: IPerson) { - const participantsLength = event.participantStats.approved; + const participantsLength = event.participantStats.participant; const prefix = participantsLength - ? this.$tc('There are {participants} participants.', event.participantStats.approved, { - participants: event.participantStats.approved, + ? this.$tc('There are {participants} participants.', event.participantStats.participant, { + participants: event.participantStats.participant, }) : ''; diff --git a/js/src/types/event.model.ts b/js/src/types/event.model.ts index 05bb1577f..494dbb45d 100644 --- a/js/src/types/event.model.ts +++ b/js/src/types/event.model.ts @@ -94,10 +94,13 @@ export enum CommentModeration { } export interface IEventParticipantStats { - approved: number; - unapproved: number; + notApproved: number; rejected: number; - participants: number; + participant: number; + creator: number; + moderator: number; + administrator: number; + going: number; } export interface IEvent { @@ -192,7 +195,7 @@ export class EventModel implements IEvent { publishAt = new Date(); - participantStats = { approved: 0, unapproved: 0, rejected: 0, participants: 0 }; + participantStats = { notApproved: 0, rejected: 0, participant: 0, moderator: 0, administrator: 0, creator: 0, going: 0 }; participants: IParticipant[] = []; relatedEvents: IEvent[] = []; diff --git a/js/src/views/Event/Event.vue b/js/src/views/Event/Event.vue index be089a1df..7819e9d48 100644 --- a/js/src/views/Event/Event.vue +++ b/js/src/views/Event/Event.vue @@ -16,18 +16,18 @@ import {ParticipantRole} from "@/types/event.model";

{{ event.title }}

- - {{ $tc('One person is going', event.participantStats.approved, {approved: event.participantStats.approved}) }} + + {{ $tc('One person is going', event.participantStats.going, {approved: event.participantStats.going}) }} - - {{ $tc('You and one other person are going to this event', event.participantStats.participants, { approved: event.participantStats.participants }) }} + + {{ $tc('You and one other person are going to this event', event.participantStats.participant, { approved: event.participantStats.participant }) }} - - {{ $tc('One person is going', event.participantStats.approved, {approved: event.participantStats.approved}) }} + + {{ $tc('One person is going', event.participantStats.going, {approved: event.participantStats.going}) }} - - {{ $tc('You and one other person are going to this event', event.participantStats.participants, { approved: event.participantStats.participants }) }} + + {{ $tc('You and one other person are going to this event', event.participantStats.participant, { approved: event.participantStats.participant }) }} {{ $tc('All the places have already been taken', numberOfPlacesStillAvailable, { places: numberOfPlacesStillAvailable}) }} @@ -443,10 +443,10 @@ export default class Event extends EventMixin { } if (data.joinEvent.role === ParticipantRole.NOT_APPROVED) { - event.participantStats.unapproved = event.participantStats.unapproved + 1; + event.participantStats.notApproved = event.participantStats.notApproved + 1; } else { - event.participantStats.approved = event.participantStats.approved + 1; - event.participantStats.participants = event.participantStats.participants + 1; + event.participantStats.going = event.participantStats.going + 1; + event.participantStats.participant = event.participantStats.participant + 1; } store.writeQuery({ query: FETCH_EVENT, variables: { uuid: this.uuid }, data: { event } }); @@ -514,10 +514,10 @@ export default class Event extends EventMixin { return; } if (participation.role === ParticipantRole.NOT_APPROVED) { - event.participantStats.unapproved = event.participantStats.unapproved - 1; + event.participantStats.notApproved = event.participantStats.notApproved - 1; } else { - event.participantStats.approved = event.participantStats.approved - 1; - event.participantStats.participants = event.participantStats.participants - 1; + event.participantStats.going = event.participantStats.going - 1; + event.participantStats.participant = event.participantStats.participant - 1; } store.writeQuery({ query: FETCH_EVENT, variables: { uuid: this.uuid }, data: { event } }); }, @@ -591,11 +591,11 @@ export default class Event extends EventMixin { get eventCapacityOK(): boolean { if (!this.event.options.maximumAttendeeCapacity) return true; - return this.event.options.maximumAttendeeCapacity > this.event.participantStats.participants; + return this.event.options.maximumAttendeeCapacity > this.event.participantStats.participant; } get numberOfPlacesStillAvailable(): number { - return this.event.options.maximumAttendeeCapacity - this.event.participantStats.participants; + return this.event.options.maximumAttendeeCapacity - this.event.participantStats.participant; } urlToHostname(url: string): string|null { diff --git a/js/src/views/Event/Participants.vue b/js/src/views/Event/Participants.vue index 3d5998add..9d66fe66f 100644 --- a/js/src/views/Event/Participants.vue +++ b/js/src/views/Event/Participants.vue @@ -4,7 +4,7 @@ - +