-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
901 additions
and
511 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,65 @@ | ||
import { uniq } from 'lodash' | ||
|
||
import { EntitiyPotentialNotif, GeneralPotentialNotif, PotentialNotif } from './types' | ||
|
||
import { GetCurrentRolesQuery } from '@/common/queries' | ||
import { EntityPotentialNotif, GeneralPotentialNotif, PotentialNotif } from '@/notifier/types' | ||
export { getParentCategories } from './getParentCategories' | ||
export { NotifEventFromQNEvent, NotificationEvent, PotentialNotif } from './types' | ||
export { NotifEventFromQNEvent } from './types' | ||
|
||
export const isGeneralPotentialNotif = (p: PotentialNotif): p is GeneralPotentialNotif => 'relatedMembers' in p | ||
export const isEntityPotentialNotif = (p: PotentialNotif): p is EntitiyPotentialNotif => 'relatedEntityId' in p | ||
export const isEntityPotentialNotif = (p: PotentialNotif): p is EntityPotentialNotif => 'relatedEntityId' in p | ||
|
||
type Created = { createdAt: any } | ||
export const isOlderThan = | ||
<A extends Created>(a: A) => | ||
<B extends Created>(b: B): boolean => | ||
Date.parse(String(a)) > Date.parse(String(b)) | ||
|
||
export const getMentionedMemberIds = (text: string): number[] => | ||
export const getMentionedMemberIds = (text: string, roles: GetCurrentRolesQuery): number[] => | ||
uniq( | ||
Array.from(text.matchAll(/\[@[-.0-9A-Z\\_a-z]+\]\(#mention\?member-id=(\d+)\)/g)).flatMap((match) => { | ||
const id = match[1] && Number(match[1]) | ||
return !id || isNaN(id) ? [] : Number(id) | ||
Array.from(text.matchAll(/\[@[^\]\n]*\]\(#mention\?(member-id|role)=([^)\n]+?)\)/g)).flatMap((match) => { | ||
const type = match[1] | ||
const id = match[2] | ||
if (!type || !id) return [] | ||
|
||
if (type === 'member-id') { | ||
const memberId = Number(id) | ||
return isNaN(memberId) ? [] : memberId | ||
} | ||
|
||
if (type !== 'role') return [] | ||
|
||
const councilIds = roles.electedCouncils.at(0)?.councilMembers.map((member) => Number(member.memberId)) ?? [] | ||
const workers = roles.workers | ||
const leads = workers.filter((worker) => worker.isLead) | ||
const [role, groupId] = id.split('_') | ||
|
||
switch (role) { | ||
case 'dao': | ||
return [...councilIds, ...roles.workers.map((worker) => Number(worker.membershipId))] | ||
|
||
case 'council': | ||
return councilIds | ||
|
||
case 'workers': { | ||
if (!groupId) { | ||
return [] | ||
} | ||
return workers.filter((worker) => worker.groupId === groupId).map((worker) => Number(worker.membershipId)) | ||
} | ||
|
||
case 'leads': | ||
return leads.map((lead) => Number(lead.membershipId)) | ||
|
||
case 'lead': { | ||
if (!groupId) { | ||
return [] | ||
} | ||
const leadId = leads.find((lead) => lead.groupId === groupId)?.membershipId ?? [] | ||
return leadId ? [Number(leadId)] : [] | ||
} | ||
|
||
default: | ||
return [] | ||
} | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.