Skip to content

Commit

Permalink
Merge pull request #307 from k2maan/generate-topic-name-update
Browse files Browse the repository at this point in the history
Improved: used ofbizInstanceName for generating topic name for notifications
  • Loading branch information
ravilodhi authored Oct 4, 2023
2 parents 2469768 + 5c2ed9f commit 5009d2d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/components/NotificationPreferenceModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default defineComponent({
},
computed: {
...mapGetters({
userProfile: 'user/getUserProfile',
currentFacility: 'user/getCurrentFacility',
instanceUrl: 'user/getInstanceUrl',
notificationPrefs: 'user/getNotificationPrefs'
Expand Down Expand Up @@ -144,17 +145,17 @@ export default defineComponent({
}
},
async handleTopicSubscription() {
const oms = this.instanceUrl
const ofbizInstanceName = this.userProfile.ofbizInstanceName
const facilityId = (this.currentFacility as any).facilityId
const subscribeRequests = [] as any
this.notificationPrefToUpate.subscribe.map(async (enumId: string) => {
const topicName = generateTopicName(oms, facilityId, enumId)
const topicName = generateTopicName(ofbizInstanceName, facilityId, enumId)
await subscribeRequests.push(subscribeTopic(topicName, process.env.VUE_APP_NOTIF_APP_ID))
})
const unsubscribeRequests = [] as any
this.notificationPrefToUpate.unsubscribe.map(async (enumId: string) => {
const topicName = generateTopicName(oms, facilityId, enumId)
const topicName = generateTopicName(ofbizInstanceName, facilityId, enumId)
await unsubscribeRequests.push(unsubscribeTopic(topicName, process.env.VUE_APP_NOTIF_APP_ID))
})
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const actions: ActionTree<UserState, RootState> = {

async fetchNotificationPreferences({ commit, state }) {
let resp = {} as any
const oms = state.instanceUrl
const ofbizInstanceName = state.current.ofbizInstanceName
const facilityId = (state.currentFacility as any).facilityId
let notificationPreferences = [], enumerationResp = [], userPrefIds = [] as any
try {
Expand All @@ -194,7 +194,7 @@ const actions: ActionTree<UserState, RootState> = {
// data and getNotificationUserPrefTypeIds fails or returns empty response (all disbaled)
if (enumerationResp.length) {
notificationPreferences = enumerationResp.reduce((notifactionPref: any, pref: any) => {
const userPrefTypeIdToSearch = generateTopicName(oms, facilityId, pref.enumId)
const userPrefTypeIdToSearch = generateTopicName(ofbizInstanceName, facilityId, pref.enumId)
notifactionPref.push({ ...pref, isEnabled: userPrefIds.includes(userPrefTypeIdToSearch) })
return notifactionPref
}, [])
Expand Down
2 changes: 1 addition & 1 deletion src/utils/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const addNotification = async (notification: any) => store.dispatch('user/addNot
const generateDeviceId = () => (DateTime.now().toFormat('ddMMyy') + String(DateTime.now().toMillis()).slice(-6))

// topic name: oms-facilityId-enumId(enumCode)
const generateTopicName = (oms: string, facilityId: string, enumId: string) => `${oms}-${facilityId}-${enumId}`
const generateTopicName = (ofbizInstanceName: string, facilityId: string, enumId: string) => `${ofbizInstanceName}-${facilityId}-${enumId}`

export {
addNotification,
Expand Down

0 comments on commit 5009d2d

Please sign in to comment.