Skip to content

Commit

Permalink
PR revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
piazzatron committed May 24, 2022
1 parent e39815f commit cac623a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ module.exports = {
).then(() => queryInterface.addColumn('SolanaNotifications', 'metadata', {
type: Sequelize.JSONB,
allowNull: true
})).then(() =>
queryInterface.sequelize.query(
`CREATE INDEX IF NOT EXISTS "solana_notifications_metadata_tip_tx_signature_idx" ON "SolanaNotifications"(("metadata"->>'tipTxSignature'))`
)
)
}))
},

down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query('DROP INDEX IF EXISTS "solana_notifications_metadata_tip_tx_signature_idx";', { transaction })

// Recreate the old enum:

// Create a new enum
Expand Down
8 changes: 1 addition & 7 deletions identity-service/src/models/solanaNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.JSONB,
allowNull: true
}
}, {
indexes: [{
fields: ["((metadata->'tipTxSignature'))"],
unique: false,
name: 'solana_notifications_metadata_tip_tx_signature_idx'
}]
})
}, {})

SolanaNotification.associate = function (models) {
SolanaNotification.hasMany(models.SolanaNotificationAction, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,20 @@ async function processReactionNotifications (notifications, tx) {
for (const notification of notifications) {
const { slot, initiator: reactorId, metadata: { reaction_value: reactionValue, reacted_to: reactedTo, reaction_type: reactionType } } = notification

// First find the originating tip receive notif
const receiveTipNotification = await models.SolanaNotification.findOne({
await models.SolanaNotification.findOrCreate({
where: {
type: notificationTypes.TipReceive,
slot,
type: notificationTypes.Reaction,
userId: receiveTipNotification.entityId, // The user receiving the reaction is the user who sent the tip, here the entityId
entityId: reactorId, // The user who sent the reaction
metadata: {
[models.Sequelize.Op.contains]: {
'tipTxSignature': reactedTo
}
reactionType,
reactedTo,
reactionValue
}
}
},
transaction: tx
})

if (!receiveTipNotification) {
console.error(`Received reaction to ${reactedTo} from ${reactorId}, but not corresponding tip notification`)
return notifications
}

// Set it's reaction value
receiveTipNotification.metadata = { ...receiveTipNotification.metadata, reactionValue }

// Save out reaction value on receive tip, and create new reaction notif
await Promise.all([
receiveTipNotification.save({ transaction: tx }),
models.SolanaNotification.findOrCreate({
where: {
slot,
type: notificationTypes.Reaction,
userId: receiveTipNotification.entityId, // The user receiving the reaction is the user who sent the tip, here the entityId
entityId: reactorId, // The user who sent the reaction
metadata: {
reactionType,
reactedTo,
reactionValue
}
},
transaction: tx
})
])
}
return notifications
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ async function processTipNotifications (notifications, tx) {
metadata: {
tipTxSignature,
amount,
reactionValue: 0 // Initially, no reaction
}
},
transaction: tx
Expand Down
6 changes: 4 additions & 2 deletions identity-service/src/routes/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ const formatTipReceive = (notification) => ({
type: notification.type,
amount: notification.metadata.amount,
reactionValue: notification.metadata.reactionValue,
senderId: notification.entityId
senderId: notification.entityId,
tipTxSignature: notification.metadata.tipTxSignature
})

const formatSupportingRankUp = (notification) => ({
Expand All @@ -241,7 +242,8 @@ const formatReaction = (notification) => ({
type: notification.type,
reactingUser: notification.entityId,
reactionType: notification.metadata.reactionType,
reactionValue: notification.metadata.reactionValue
reactionValue: notification.metadata.reactionValue,
reactedTo: notification.metadata.reactedTo
})

const getCommonNotificationsFields = (notification) => ({
Expand Down

0 comments on commit cac623a

Please sign in to comment.