Skip to content

Commit

Permalink
Merge pull request #3438 from JoinColony/feat/in-app-notifications
Browse files Browse the repository at this point in the history
Feat: In app notifications
  • Loading branch information
rdig authored Oct 24, 2024
2 parents 19c484f + cf3014a commit 0d41f35
Show file tree
Hide file tree
Showing 124 changed files with 4,948 additions and 832 deletions.
9 changes: 8 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ POSTHOG_HOST=

# Needed for crypto-to-fiat
USDC_LOCAL_ADDRESS=
PERSONA_ENVIRONMENT_ID=
PERSONA_ENVIRONMENT_ID=

# Needed for notifications via magicbell
MAGICBELL_API_KEY=
MAGICBELL_API_SECRET=

# Used to set a local key so that in development you only recieve notifications from your current dev env
MAGICBELL_DEV_KEY=
3 changes: 3 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ METATX_ENABLED=true
METATX_BROADCASTER_ENDPOINT="http://localhost:3004"
AUTH_PROXY_ENDPOINT="http://localhost:3005"
USDC_LOCAL_ADDRESS=
MAGICBELL_API_KEY=
MAGICBELL_API_SECRET=
MAGICBELL_DEV_KEY=
133 changes: 126 additions & 7 deletions amplify/backend/api/colonycdapp/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ input CreateUniqueUserInput {
profile: ProfileInput!
}

"""
Input data for creating notifications data for a user
"""
input CreateUserNotificationsDataInput {
"""
Unique identifier for the user. This is the user's wallet address
"""
id: ID!
}

"""
Input data for a user's profile metadata
"""
Expand Down Expand Up @@ -967,6 +977,53 @@ enum UserStakeType {
STAKED_EXPENDITURE
}

"""
Type of notifications that can be sent
"""
enum NotificationType {
# Expenditures
EXPENDITURE_READY_FOR_REVIEW
EXPENDITURE_READY_FOR_FUNDING
EXPENDITURE_READY_FOR_RELEASE
EXPENDITURE_FINALIZED
EXPENDITURE_PAYOUT_CLAIMED
EXPENDITURE_CANCELLED

# Extensions
EXTENSION_INSTALLED
EXTENSION_UPGRADED
EXTENSION_ENABLED
EXTENSION_DEPRECATED
EXTENSION_UNINSTALLED
EXTENSION_SETTINGS_CHANGED

# Funds
FUNDS_CLAIMED

# Mentions
MENTION

# Motions
MOTION_CREATED
MOTION_SUPPORTED
MOTION_OPPOSED
MOTION_VOTING
MOTION_REVEAL
MOTION_FINALIZED

# Multisig
MULTISIG_ACTION_CREATED
MULTISIG_ACTION_FINALIZED
MULTISIG_ACTION_APPROVED
MULTISIG_ACTION_REJECTED

# Actions made with permissions
PERMISSIONS_ACTION
# versions
NEW_COLONY_VERSION
NEW_EXTENSION_VERSION
}

"""
Root query type
"""
Expand Down Expand Up @@ -1040,15 +1097,20 @@ type Query {
"""
Fetch a domain total balance
"""
getDomainBalance(
input: DomainBalanceArguments!
): DomainBalanceReturn @function(name: "fetchDomainBalance-${env}")
getDomainBalance(input: DomainBalanceArguments!): DomainBalanceReturn
@function(name: "fetchDomainBalance-${env}")

"""
Trigger the balance caching
"""
cacheAllDomainBalance: CacheAllDomainBalanceReturn @function(name: "cacheDomainBalance-${env}")
cacheAllDomainBalance: CacheAllDomainBalanceReturn
@function(name: "cacheDomainBalance-${env}")

"""
Generate key for the user in Magicbell, used for secure fetching of notifications
"""
getUserNotificationsHMAC: String
@function(name: "getUserNotificationsHMAC-${env}")
}

"""
Expand All @@ -1060,6 +1122,14 @@ type Mutation {
"""
createUniqueUser(input: CreateUniqueUserInput): User
@function(name: "createUniqueUser-${env}")

"""
Create notification data for a user
"""
createUserNotificationsData(
input: CreateUserNotificationsDataInput!
): NotificationsData @function(name: "createUserNotificationsData-${env}")

"""
Create temporary metadata entry for an upcoming colony (that will be created by the ingestor)
"""
Expand Down Expand Up @@ -1499,7 +1569,8 @@ type Colony @model {
# Ideally we would merge data from these two into one field, but I couldn't do that
# meaning we'll have to merge this data in-app (or not at all, works either way)
# If you have a better idea, on how to merged them, I'll all ears..
fundsClaimData: [ColonyFundsClaim] @hasMany(indexName: "byColony", fields: ["id"])
fundsClaimData: [ColonyFundsClaim]
@hasMany(indexName: "byColony", fields: ["id"])
"""
Native chain token claim (e.g., Token 0x0000...0000: ETH, xDAI, etc.)
This is not an array since only a single token type can be returned
Expand Down Expand Up @@ -1996,6 +2067,44 @@ type User @model {
"""
liquidationAddresses: [LiquidationAddress!]
@hasMany(indexName: "byUserAddress", fields: ["id"])
"""
Notifications data for the user
"""
notificationsData: NotificationsData @hasOne(fields: "id")
}

"""
Holds the notifications data for the user, such as their unique Magicbell user id, and their notifications preferences.
"""
type NotificationsData @model {
"""
Unique identifier for the user
"""
userAddress: ID! @primaryKey
"""
Unique identifier for the user in Magicbell
"""
magicbellUserId: ID!
"""
Boolean to indicate if the user has disabled notifications app wide
"""
notificationsDisabled: Boolean!
"""
List of addresses of colonies that the user has muted
"""
mutedColonyAddresses: [ID!]!
"""
Boolean to indicate if the user has disabled payment notifications
"""
paymentNotificationsDisabled: Boolean!
"""
Boolean to indicate if the user has disabled mention notifications
"""
mentionNotificationsDisabled: Boolean!
"""
Boolean to indicate if the user has disabled admin notifications
"""
adminNotificationsDisabled: Boolean!
}

"""
Expand Down Expand Up @@ -2047,7 +2156,12 @@ type Domain @model {
"""
Colony ID associated with the Domain
"""
colonyId: ID! @index(name: "byColony", sortKeyFields: ["nativeId"], queryField: "getDomainsByColony")
colonyId: ID!
@index(
name: "byColony"
sortKeyFields: ["nativeId"]
queryField: "getDomainsByColony"
)
"""
Colony associated with the Domain
"""
Expand Down Expand Up @@ -2164,7 +2278,12 @@ type ColonyFundsClaim @model {
"""
The identifier of the Colony the Colony Funds Claim belong to
"""
colonyFundsClaimsId: ID @index(name: "byColony", sortKeyFields: ["createdAt"], queryField: "getFundsClaimsByColony")
colonyFundsClaimsId: ID
@index(
name: "byColony"
sortKeyFields: ["createdAt"]
queryField: "getFundsClaimsByColony"
)
"""
Token associated with the Colony Funds Claim
"""
Expand Down
12 changes: 11 additions & 1 deletion amplify/backend/backend-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"providerPlugin": "awscloudformation",
"service": "Lambda"
},
"createUserNotificationsData": {
"build": true,
"providerPlugin": "awscloudformation",
"service": "Lambda"
},
"fetchColonyBalances": {
"build": true,
"dependsOn": [
Expand Down Expand Up @@ -187,6 +192,11 @@
"providerPlugin": "awscloudformation",
"service": "Lambda"
},
"getUserNotificationsHMAC": {
"build": true,
"providerPlugin": "awscloudformation",
"service": "Lambda"
},
"getUserReputation": {
"build": true,
"dependsOn": [
Expand Down Expand Up @@ -272,4 +282,4 @@
"service": "Lambda"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const ParamNames = {
bridgeXYZApiKey: `%2Famplify%2Fcdapp%2F${ENV}%2FBRIDGEXYZ_API_KEY`,
bridgeXYZApiUrl: `%2Famplify%2Fcdapp%2F${ENV}%2FBRIDGEXYZ_API_URL`,
liquidationAddressOverrides: `%2Famplify%2Fcdapp%2F${ENV}%2FLIQUIDATION_ADDRESS_OVERRIDES`,
magicbellApiKey: `%2Famplify%2Fcdapp%2F${ENV}%2FMAGICBELL_API_KEY`,
magicbellApiSecret: `%2Famplify%2Fcdapp%2F${ENV}%2FMAGICBELL_API_SECRET`,
};

const getParam = async (paramName) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Needed for notifications via magicbell
MAGICBELL_API_KEY=
MAGICBELL_API_SECRET=
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pluginId": "amplify-nodejs-function-runtime-provider",
"functionRuntime": "nodejs",
"useLegacyBuild": true,
"defaultEditorFile": "src/index.js"
}
Loading

0 comments on commit 0d41f35

Please sign in to comment.