From 4a53e7518a1b439d4268311fa4ebebbab0314bc2 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 7 May 2021 17:18:58 +0200 Subject: [PATCH] Tried using front end to translate push notifications, not a good idea Signed-off-by: Thomas Citharel --- .../Activity/DiscussionActivityItem.vue | 33 +---- .../components/Activity/EventActivityItem.vue | 34 +---- .../components/Activity/GroupActivityItem.vue | 18 +-- .../Activity/MemberActivityItem.vue | 128 +--------------- .../components/Activity/PostActivityItem.vue | 23 +-- .../Activity/ResourceActivityItem.vue | 73 +-------- js/src/service-worker.ts | 80 +++++++++- js/src/services/activity-converter.ts | 52 +++++++ js/src/services/activity/discussion.ts | 39 +++++ js/src/services/activity/event.ts | 43 ++++++ js/src/services/activity/group.ts | 24 +++ js/src/services/activity/member.ts | 139 ++++++++++++++++++ js/src/services/activity/post.ts | 29 ++++ js/src/services/activity/resource.ts | 70 +++++++++ js/src/services/activity/utils.ts | 19 +++ js/src/types/activity.model.ts | 9 +- 16 files changed, 523 insertions(+), 290 deletions(-) create mode 100644 js/src/services/activity-converter.ts create mode 100644 js/src/services/activity/discussion.ts create mode 100644 js/src/services/activity/event.ts create mode 100644 js/src/services/activity/group.ts create mode 100644 js/src/services/activity/member.ts create mode 100644 js/src/services/activity/post.ts create mode 100644 js/src/services/activity/resource.ts create mode 100644 js/src/services/activity/utils.ts diff --git a/js/src/components/Activity/DiscussionActivityItem.vue b/js/src/components/Activity/DiscussionActivityItem.vue index c05c145fd..33cc9ab4b 100644 --- a/js/src/components/Activity/DiscussionActivityItem.vue +++ b/js/src/components/Activity/DiscussionActivityItem.vue @@ -55,6 +55,7 @@ import RouteName from "../../router/name"; import PopoverActorCard from "../Account/PopoverActorCard.vue"; import ActivityMixin from "../../mixins/activity"; import { mixins } from "vue-class-component"; +import { convertActivity } from "@/services/activity-converter"; @Component({ components: { @@ -67,35 +68,9 @@ export default class DiscussionActivityItem extends mixins(ActivityMixin) { ActivityDiscussionSubject = ActivityDiscussionSubject; get translation(): string | undefined { - switch (this.activity.subject) { - case ActivityDiscussionSubject.DISCUSSION_CREATED: - if (this.isAuthorCurrentActor) { - return "You created the discussion {discussion}."; - } - return "{profile} created the discussion {discussion}."; - case ActivityDiscussionSubject.DISCUSSION_REPLIED: - if (this.isAuthorCurrentActor) { - return "You replied to the discussion {discussion}."; - } - return "{profile} replied to the discussion {discussion}."; - case ActivityDiscussionSubject.DISCUSSION_RENAMED: - if (this.isAuthorCurrentActor) { - return "You renamed the discussion from {old_discussion} to {discussion}."; - } - return "{profile} renamed the discussion from {old_discussion} to {discussion}."; - case ActivityDiscussionSubject.DISCUSSION_ARCHIVED: - if (this.isAuthorCurrentActor) { - return "You archived the discussion {discussion}."; - } - return "{profile} archived the discussion {discussion}."; - case ActivityDiscussionSubject.DISCUSSION_DELETED: - if (this.isAuthorCurrentActor) { - return "You deleted the discussion {discussion}."; - } - return "{profile} deleted the discussion {discussion}."; - default: - return undefined; - } + return convertActivity(this.activity, { + isAuthorCurrentActor: this.isAuthorCurrentActor, + }); } get iconColor(): string | undefined { diff --git a/js/src/components/Activity/EventActivityItem.vue b/js/src/components/Activity/EventActivityItem.vue index 573ee11a7..c5cee603d 100644 --- a/js/src/components/Activity/EventActivityItem.vue +++ b/js/src/components/Activity/EventActivityItem.vue @@ -44,6 +44,7 @@ import { Component } from "vue-property-decorator"; import RouteName from "../../router/name"; import PopoverActorCard from "../Account/PopoverActorCard.vue"; import ActivityMixin from "../../mixins/activity"; +import { convertActivity } from "@/services/activity-converter"; @Component({ components: { @@ -56,36 +57,9 @@ export default class EventActivityItem extends mixins(ActivityMixin) { RouteName = RouteName; get translation(): string | undefined { - switch (this.activity.subject) { - case ActivityEventSubject.EVENT_CREATED: - if (this.isAuthorCurrentActor) { - return "You created the event {event}."; - } - return "The event {event} was created by {profile}."; - case ActivityEventSubject.EVENT_UPDATED: - if (this.isAuthorCurrentActor) { - return "You updated the event {event}."; - } - return "The event {event} was updated by {profile}."; - case ActivityEventSubject.EVENT_DELETED: - if (this.isAuthorCurrentActor) { - return "You deleted the event {event}."; - } - return "The event {event} was deleted by {profile}."; - case ActivityEventCommentSubject.COMMENT_POSTED: - if (this.subjectParams.comment_reply_to) { - if (this.isAuthorCurrentActor) { - return "You replied to a comment on the event {event}."; - } - return "{profile} replied to a comment on the event {event}."; - } - if (this.isAuthorCurrentActor) { - return "You posted a comment on the event {event}."; - } - return "{profile} posted a comment on the event {event}."; - default: - return undefined; - } + return convertActivity(this.activity, { + isAuthorCurrentActor: this.isAuthorCurrentActor, + }); } get iconColor(): string | undefined { diff --git a/js/src/components/Activity/GroupActivityItem.vue b/js/src/components/Activity/GroupActivityItem.vue index d54bf896a..09d0cd496 100644 --- a/js/src/components/Activity/GroupActivityItem.vue +++ b/js/src/components/Activity/GroupActivityItem.vue @@ -77,6 +77,7 @@ import RouteName from "../../router/name"; import PopoverActorCard from "../Account/PopoverActorCard.vue"; import ActivityMixin from "../../mixins/activity"; import { mixins } from "vue-class-component"; +import { convertActivity } from "@/services/activity-converter"; @Component({ components: { @@ -89,20 +90,9 @@ export default class GroupActivityItem extends mixins(ActivityMixin) { ActivityGroupSubject = ActivityGroupSubject; get translation(): string | undefined { - switch (this.activity.subject) { - case ActivityGroupSubject.GROUP_CREATED: - if (this.isAuthorCurrentActor) { - return "You created the group {group}."; - } - return "{profile} created the group {group}."; - case ActivityGroupSubject.GROUP_UPDATED: - if (this.isAuthorCurrentActor) { - return "You updated the group {group}."; - } - return "{profile} updated the group {group}."; - default: - return undefined; - } + return convertActivity(this.activity, { + isAuthorCurrentActor: this.isAuthorCurrentActor, + }); } get iconColor(): string | undefined { diff --git a/js/src/components/Activity/MemberActivityItem.vue b/js/src/components/Activity/MemberActivityItem.vue index c03c21b99..da8b24c17 100644 --- a/js/src/components/Activity/MemberActivityItem.vue +++ b/js/src/components/Activity/MemberActivityItem.vue @@ -42,19 +42,13 @@