Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 92 additions & 3 deletions src/components/Imip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ function findAttendee(vEvent, email) {
return undefined
}

function findAttendeeByEmails(vEvent, emails) {
if (!vEvent || !Array.isArray(emails) || emails.length === 0) {
return undefined
}

const emailSet = new Set(emails.map(e => removeMailtoPrefix(e).toLowerCase()))
for (const attendee of [...vEvent.getPropertyIterator('ORGANIZER'), ...vEvent.getAttendeeIterator()]) {
const normalized = removeMailtoPrefix(attendee.email).toLowerCase()
if (emailSet.has(normalized)) {
return attendee
}
}

return undefined
}

export default {
name: 'Imip',
components: {
Expand All @@ -173,6 +189,10 @@ export default {
type: Object,
required: true,
},
message: {
type: Object,
required: true,
},
},
data() {
return {
Expand All @@ -197,6 +217,7 @@ export default {
currentUserPrincipalEmail: 'getCurrentUserPrincipalEmail',
clonedWriteableCalendars: 'getClonedWriteableCalendars',
currentUserPrincipal: 'getCurrentUserPrincipal',
accounts: 'getAccounts',
}),

/**
Expand All @@ -208,6 +229,14 @@ export default {
return this.scheduling.method
},

isFromDigikala() {
if (!this.message.from || !this.message.from[0]) {
return false
}
const fromEmail = this.message.from[0].email?.toLowerCase() || ''
return fromEmail.endsWith('@digikala.com')
},
Comment on lines +232 to +238
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be generalized


/**
* @return {boolean}
*/
Expand Down Expand Up @@ -305,7 +334,7 @@ export default {
* @return {boolean}
*/
userIsAttendee() {
return !!findAttendee(this.attachedVEvent, this.currentUserPrincipalEmail)
return !!findAttendeeByEmails(this.attachedVEvent, this.allUserEmails)
},

/**
Expand All @@ -314,10 +343,38 @@ export default {
* @return {string|undefined}
*/
existingParticipationStatus() {
const attendee = findAttendee(this.existingVEvent, this.currentUserPrincipalEmail)
const attendee = findAttendeeByEmails(this.existingVEvent, this.allUserEmails)
return attendee?.participationStatus ?? undefined
},

/**
* All user's email addresses (principal + all mail account addresses and aliases)
*
* @return {string[]}
*/
allUserEmails() {
const emails = new Set()
if (this.currentUserPrincipalEmail) {
emails.add(this.currentUserPrincipalEmail.toLowerCase())
}
if (Array.isArray(this.accounts)) {
for (const account of this.accounts) {
if (account?.emailAddress) {
emails.add(String(account.emailAddress).toLowerCase())
}
if (Array.isArray(account?.aliases)) {
for (const alias of account.aliases) {
const address = alias?.alias || alias?.emailAddress
if (address) {
emails.add(String(address).toLowerCase())
}
}
}
}
}
return Array.from(emails)
},

/**
* The status message to show in case of REPLY messages.
*
Expand Down Expand Up @@ -352,6 +409,14 @@ export default {
})
},

existingEventFetched: {
immediate: false,
async handler(fetched) {
if (!fetched) return
await this.autoCreateTentativeIfNeeded()
},
},

/**
* List of calendar options for the target calendar picker.
*
Expand Down Expand Up @@ -410,6 +475,14 @@ export default {
},
},
},

async mounted() {
// If data already fetched on mount, attempt auto-create once
if (this.existingEventFetched) {
await this.autoCreateTentativeIfNeeded()
}
},

methods: {
async accept() {
await this.saveEventWithParticipationStatus(ACCEPTED)
Expand All @@ -420,6 +493,22 @@ export default {
async decline() {
await this.saveEventWithParticipationStatus(DECLINED)
},
async autoCreateTentativeIfNeeded() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say that approach isn’t ideal from a conceptual standpoint. Creating the tentative event during the mounting of the frontend component requires the user to open the email. It should be done in the imip background job and only for contacts listed as internal addresses or trusted sender.

try {
if (
this.isRequest
&& !this.wasProcessed
&& this.userIsAttendee
&& this.eventIsInFuture
&& this.existingEventFetched
&& !this.isExistingEvent
) {
await this.saveEventWithParticipationStatus(TENTATIVE)
}
} catch (e) {
console.log("error", e)
}
},
async saveEventWithParticipationStatus(status) {
let vCalendar
if (this.isExistingEvent) {
Expand All @@ -428,7 +517,7 @@ export default {
vCalendar = this.attachedVCalendar
}
const vEvent = vCalendar.getFirstComponent('VEVENT')
const attendee = findAttendee(vEvent, this.currentUserPrincipalEmail)
const attendee = findAttendeeByEmails(vEvent, this.allUserEmails)
if (!attendee) {
return
}
Expand Down
7 changes: 7 additions & 0 deletions y
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ drop this and revoke the key ASAP

b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACCtkOBeKymyWdv3qjRB7V66WCTnQw+X3evlBOiTo3VvWwAAAKD0Hy8b9B8v
GwAAAAtzc2gtZWQyNTUxOQAAACCtkOBeKymyWdv3qjRB7V66WCTnQw+X3evlBOiTo3VvWw
AAAECII2T26l6rmjxjcJfCMsA2GpbQ1LTqNbqnLxAErFCasq2Q4F4rKbJZ2/eqNEHtXrpY
JOdDD5fd6+UE6JOjdW9bAAAAFnlvdXJfZW1haWxAZXhhbXBsZS5jb20BAgMEBQYH
-----END OPENSSH PRIVATE KEY-----
1 change: 1 addition & 0 deletions y.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK2Q4F4rKbJZ2/eqNEHtXrpYJOdDD5fd6+UE6JOjdW9b [email protected]