From 7f23fe6d05b78f4ed55e8a9573d1851c7d48da03 Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Wed, 27 Jul 2022 20:55:47 +0200 Subject: [PATCH] Friendship Accepted and Refused (notification updated) --- src/common/shared_vuejs.ts | 15 ++++++++--- .../toolbar/notifPopover/notifPopover.ts | 10 ++++++- .../toolbar/notifPopover/notifPopover.vue | 26 ++++++++++++++++++- src/mixins/mixin-users.ts | 16 ++++++++++-- src/model/MessageStore.ts | 3 ++- src/statics/lang/enUs.js | 1 + src/statics/lang/it.js | 6 ++++- src/store/Modules/tools.ts | 5 ++++ src/store/NotifStore.ts | 3 ++- src/views/user/myprofile/myprofile.vue | 18 ++++++++----- 10 files changed, 87 insertions(+), 16 deletions(-) diff --git a/src/common/shared_vuejs.ts b/src/common/shared_vuejs.ts index 64978c0d..118a2e93 100755 --- a/src/common/shared_vuejs.ts +++ b/src/common/shared_vuejs.ts @@ -859,6 +859,11 @@ export const shared_consts = { NEW_ADV_SECTOR: 32, }, + StatusNotifs: { + STATUS_FRIENDS_ACCEPTED: 1, + STATUS_FRIENDS_REFUSED: 2, + }, + TypeNotifs: { TYPEDIR_BACHECA: 1, ID_BACHECA_NEW_GOOD: 1, @@ -872,11 +877,15 @@ export const shared_consts = { ID_FRIENDS_NEW_REC: 1, ID_FRIENDS_ACCEPTED: 2, - TYPEDIR_CIRCUITS: 4, + TYPEDIR_GROUPS: 4, + ID_GROUP_NEW_REC: 1, + ID_GROUP_ACCEPTED: 2, - TYPEDIR_BOOKING: 5, + TYPEDIR_CIRCUITS: 5, - TYPEDIR_MSGS: 6, + TYPEDIR_BOOKING: 6, + + TYPEDIR_MSGS: 7, ID_MSGS_NEW_REC: 1, }, diff --git a/src/layouts/toolbar/notifPopover/notifPopover.ts b/src/layouts/toolbar/notifPopover/notifPopover.ts index eff689b4..0fb08d16 100755 --- a/src/layouts/toolbar/notifPopover/notifPopover.ts +++ b/src/layouts/toolbar/notifPopover/notifPopover.ts @@ -80,6 +80,12 @@ export default defineComponent({ } }) + watch(() => notifStore.updateNotification, async (to: any, from: any) => { + if (notifStore.updateNotification) { + await refreshdata(userStore.my.username) + } + }) + function clickNotif(notif: INotif) { if (notif.openUrl) { let mylink = tools.updateQueryStringParameter(notif.openUrl, 'idnotif', notif._id) @@ -101,7 +107,7 @@ export default defineComponent({ // Get msg for this let myrec = getlastnotif(username) - const lastdata: any = (myrec) ? myrec.lastdataread : tools.getLastDateReadReset() + const lastdata: any = (myrec && myrec.lastdataread) ? myrec.lastdataread : tools.getLastDateReadReset() let mydate = '' if (!tools.isIsoDate(lastdata)) @@ -127,6 +133,7 @@ export default defineComponent({ lastdataread: getlastdataread(username) }).then((ris) => { + notifStore.updateNotification = false notifsel.value.dest = username loading.value = false @@ -170,6 +177,7 @@ export default defineComponent({ show_all, t, username, + userStore, } }, }) diff --git a/src/layouts/toolbar/notifPopover/notifPopover.vue b/src/layouts/toolbar/notifPopover/notifPopover.vue index 0c8727d1..9bdfd83f 100755 --- a/src/layouts/toolbar/notifPopover/notifPopover.vue +++ b/src/layouts/toolbar/notifPopover/notifPopover.vue @@ -86,7 +86,31 @@ -
+ +
+
+ + +
+ + +
+
+ {{ tools.timeAgo(notif.datenotif) }} diff --git a/src/mixins/mixin-users.ts b/src/mixins/mixin-users.ts index af90d3bf..67e79788 100755 --- a/src/mixins/mixin-users.ts +++ b/src/mixins/mixin-users.ts @@ -5,6 +5,7 @@ import { useGlobalStore } from '@store/globalStore' import { useProducts } from '@store/Products' import { serv_constants } from '@store/Modules/serv_constants' import { tools } from '@store/Modules/tools' +import { shared_consts } from '@src/common/shared_vuejs' // You can declare a mixin as the same style as components. export default function () { @@ -156,9 +157,20 @@ export default function () { return ris } - function getNotifText(notif: INotif) { + function getNotifText($t: any, notif: INotif) { + + let descr = notif.descr + + if (notif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) { + if (notif.status === shared_consts.StatusNotifs.STATUS_FRIENDS_ACCEPTED) { + descr += '\n' + $t('friends.accepted') + } else if (notif.status === shared_consts.StatusNotifs.STATUS_FRIENDS_REFUSED) { + descr += '\n' + $t('friends.refused') + } + } + + return descr - return notif.descr } function getNumNotif() { diff --git a/src/model/MessageStore.ts b/src/model/MessageStore.ts index ee3493da..e0a0ebc5 100755 --- a/src/model/MessageStore.ts +++ b/src/model/MessageStore.ts @@ -1,5 +1,5 @@ -import { shared_consts } from '@src/common/shared_vuejs' import { EState } from './Calendar' +import { shared_consts } from '@src/common/shared_vuejs' export interface IMessagePage { show: boolean @@ -117,4 +117,5 @@ export interface IMessageState { export interface INotifState { last_notifs: INotif[] show_all: boolean + updateNotification: boolean } diff --git a/src/statics/lang/enUs.js b/src/statics/lang/enUs.js index 6a08ab93..1410e762 100755 --- a/src/statics/lang/enUs.js +++ b/src/statics/lang/enUs.js @@ -885,6 +885,7 @@ const msg_enUs = { rejected: 'Rifiutati', }, friends: { + accepted: 'Amicizia Accettata', accept_trust: 'Accetta Fiducia', accept_friend: 'Accetta Amicizia', refuse_trust: 'Rifiuta Fiducia', diff --git a/src/statics/lang/it.js b/src/statics/lang/it.js index e5941a24..4e1d9974 100755 --- a/src/statics/lang/it.js +++ b/src/statics/lang/it.js @@ -977,6 +977,10 @@ const msg_it = { }, friends: { accept_trust: 'Accetta Fiducia', + accepted: 'Amicizia Accettata', + refused: 'Amicizia Rifiutata', + accept: 'Accetta', + refuse: 'Rifiuta', accept_friend: 'Accetta Amicizia', refuse_trust: 'Rifiuta Fiducia', reject_trust: 'Revoca Fiducia', @@ -985,7 +989,7 @@ const msg_it = { ask_friend: 'Chiedi l\'Amicizia', cancel_ask_friend: 'Annulla la richiesta di Amicizia', cancel_ask_friend_short: 'Annulla richiesta', - reject_ask_friend: 'Rifiuta la richiesta di Amicizia', + reject_ask_friend: 'Rifiuta l\'Amicizia', }, groups: { member: 'membro', diff --git a/src/store/Modules/tools.ts b/src/store/Modules/tools.ts index 6f8be7f2..cc76f8c6 100644 --- a/src/store/Modules/tools.ts +++ b/src/store/Modules/tools.ts @@ -40,6 +40,7 @@ import { useCalendarStore } from '@store/CalendarStore' import { Router } from 'vue-router' import { AxiosResponse, default as Axios } from 'axios' import { PayloadMessageTypes } from '@/common' +import { useNotifStore } from '@store/NotifStore' export interface INotify { color?: string | 'primary' @@ -4614,6 +4615,7 @@ export const tools = { addToMyFriends($q: any, username: string, usernameDest: string) { const userStore = useUserStore() + const notifStore = useNotifStore() $q.dialog({ message: t('db.domanda_addtofriend', { username: usernameDest }), ok: { label: t('dialog.yes'), push: true }, @@ -4624,6 +4626,7 @@ export const tools = { userStore.setFriendsCmd($q, t, username, usernameDest, shared_consts.FRIENDSCMD.SETFRIEND, null) .then((res: any) => { if (res) { + notifStore.updateNotification = true userStore.my.profile.friends = [...userStore.my.profile.friends, res] userStore.my.profile.req_friends = userStore.my.profile.req_friends.filter((rec: IFriends) => rec.username !== usernameDest) tools.showPositiveNotif($q, t('db.addedfriend')) @@ -4671,6 +4674,7 @@ export const tools = { refuseReqFriends($q: any, username: string, usernameDest: string) { const userStore = useUserStore() + const notifStore = useNotifStore() $q.dialog({ message: t('db.domanda_revoke_friend', { username: usernameDest }), ok: { label: t('dialog.yes'), push: true }, @@ -4680,6 +4684,7 @@ export const tools = { userStore.setFriendsCmd($q, t, username, usernameDest, shared_consts.FRIENDSCMD.REMOVE_FROM_MYFRIENDS, null).then((res) => { if (res) { + notifStore.updateNotification = true userStore.my.profile.req_friends = userStore.my.profile.req_friends.filter((user: IFriends) => user.username !== usernameDest) tools.showPositiveNotif($q, t('db.removedfriend')) } diff --git a/src/store/NotifStore.ts b/src/store/NotifStore.ts index 34cbe365..ebdf0f8d 100755 --- a/src/store/NotifStore.ts +++ b/src/store/NotifStore.ts @@ -12,7 +12,8 @@ import { useUserStore } from '@store/UserStore' export const useNotifStore = defineStore('NotifStore', { state: (): INotifState => ({ last_notifs: [], - show_all: true + show_all: true, + updateNotification: false, }), getters: { diff --git a/src/views/user/myprofile/myprofile.vue b/src/views/user/myprofile/myprofile.vue index b736d5a9..94c0f969 100755 --- a/src/views/user/myprofile/myprofile.vue +++ b/src/views/user/myprofile/myprofile.vue @@ -71,12 +71,18 @@
- +
+ + +