-
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.
📢 Add support for role mentions (#4789)
* Clarify backend types * Add backend support for role mentions * Add frontend support for role mentions * Improve role mention appearance * Pass roles to `fromThreadCreatedEvent` * Remove the "@wg Workers" notification * Don't fetch posts text as it's not used
- Loading branch information
Showing
23 changed files
with
872 additions
and
498 deletions.
There are no files selected for viewing
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
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
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
Oops, something went wrong.