* Allow to follow/unfollow markets, backfill as well * remove yarn script edit * add decrement comment * Lint * Decrement follow count on unfollow * Follow/unfollow button logic * Unfollow/follow => heart * Add user to followers in place-bet and sell-shares * Add tracking * Show contract follow modal for first time following * Increment follower count as well * Remove add follow from bet trigger * restore on-create-bet * Add pubsub to dev.sh, show heart on FR, remove from answer trigger
		
			
				
	
	
		
			34 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import * as functions from 'firebase-functions'
 | |
| 
 | |
| import { getUser } from './utils'
 | |
| import { createNotification } from './create-notification'
 | |
| import { Contract } from '../../common/contract'
 | |
| import { parseMentions, richTextToString } from '../../common/util/parse'
 | |
| import { JSONContent } from '@tiptap/core'
 | |
| import { addUserToContractFollowers } from './follow-market'
 | |
| 
 | |
| export const onCreateContract = functions
 | |
|   .runWith({ secrets: ['MAILGUN_KEY'] })
 | |
|   .firestore.document('contracts/{contractId}')
 | |
|   .onCreate(async (snapshot, context) => {
 | |
|     const contract = snapshot.data() as Contract
 | |
|     const { eventId } = context
 | |
| 
 | |
|     const contractCreator = await getUser(contract.creatorId)
 | |
|     if (!contractCreator) throw new Error('Could not find contract creator')
 | |
| 
 | |
|     const desc = contract.description as JSONContent
 | |
|     const mentioned = parseMentions(desc)
 | |
|     await addUserToContractFollowers(contract.id, contractCreator.id)
 | |
| 
 | |
|     await createNotification(
 | |
|       contract.id,
 | |
|       'contract',
 | |
|       'created',
 | |
|       contractCreator,
 | |
|       eventId,
 | |
|       richTextToString(desc),
 | |
|       { contract, recipients: mentioned }
 | |
|     )
 | |
|   })
 |