async function notifications(user, { first = 10, after, filter }, _, info) {
  const fields = graphqlFields(info)

  const sellerListings = await ec().allEvents('ListingCreated', user.id)

  const sellerListingIds = sellerListings.map(e =>
    Number(e.returnValues.listingID)
  )

  const sellerEvents = await ec().offers(
    sellerListingIds,
    null,
    [
      'OfferCreated',
      'OfferFinalized',
      'OfferWithdrawn',
      'OfferFundsAdded',
      'OfferDisputed',
      'OfferRuling'
    ],
    user.id
  )

  const buyerListings = await ec().allEvents('OfferCreated', user.id)

  const buyerListingIds = buyerListings.map(e =>
    Number(e.returnValues.listingID)
  )

  const buyerEvents = await ec().offers(
    buyerListingIds,
    null,
    ['OfferAccepted', 'OfferRuling'],
    user.id
  )

  let allEvents = sortBy([...sellerEvents, ...buyerEvents], e => -e.blockNumber)

  if (filter === 'pending') {
    const allListingIds = allEvents.map(e => Number(e.returnValues.listingID))
    const allListings = await Promise.all(
      allListingIds.map(id => ec().offers(id))
    )

    allEvents = allEvents.filter(e => {
      const idx = allListingIds.indexOf(Number(e.returnValues.listingID))
      const events = allListings[idx]
      if (e.event === 'OfferFinalized') {
        return false
      } else if (
        e.event === 'OfferCreated' &&
        events.some(t => t.event.match(/Offer(Withdrawn|Finalized)/))
      ) {
        return false
      } else if (
        e.event === 'OfferAccepted' &&
        events.some(t => t.event === 'OfferFinalized')
      ) {
        return false
      } else {
        return true
      }
    })
  }

  const totalCount = allEvents.length,
    allIds = allEvents.map(e => e.id)

  const { ids, start } = getIdsForPage({ after, ids: allIds, first })
  const filteredEvents = allEvents.filter(e => ids.indexOf(e.id) >= 0)

  let offers = [],
    nodes = []

  if (fields.nodes) {
    offers = await Promise.all(
      filteredEvents.map(event =>
        contracts.eventSource.getOffer(
          event.returnValues.listingID,
          event.returnValues.offerID,
          event.blockNumber
        )
      )
    )
    nodes = filteredEvents.map((event, idx) => {
      const party = event.returnValues.party
      return {
        id: event.id,
        offer: offers[idx],
        party: { id: party, account: { id: party } },
        event,
        read: false
      }
    })
  }

  return getConnection({ start, first, nodes, ids, totalCount })
}
// Sourced from offer events where user is alternate party
Sourced from offer events where user is alternate party
Sourced from offer events where user is alternate party
async function notifications(user, { first = 10, after, filter }, _, info) {
  const fields = graphqlFields(info)
  const sellerListings = await ec().allEvents('ListingCreated', user.id)
  const sellerListingIds = sellerListings.map(e =>
    Number(e.returnValues.listingID)
  )
  const sellerEvents = await ec().offers(
    sellerListingIds,
    null,
    [
      'OfferCreated',
      'OfferFinalized',
      'OfferWithdrawn',
      'OfferFundsAdded',
      'OfferDisputed',
      'OfferRuling'
    ],
    user.id
  )
  const buyerListings = await ec().allEvents('OfferCreated', user.id)
  const buyerListingIds = buyerListings.map(e =>
    Number(e.returnValues.listingID)
  )
  const buyerEvents = await ec().offers(
    buyerListingIds,
    null,
    ['OfferAccepted', 'OfferRuling'],
    user.id
  )
  let allEvents = sortBy([...sellerEvents, ...buyerEvents], e => -e.blockNumber)
  if (filter === 'pending') {
    const allListingIds = allEvents.map(e => Number(e.returnValues.listingID))
    const allListings = await Promise.all(
      allListingIds.map(id => ec().offers(id))
    )
    allEvents = allEvents.filter(e => {
      const idx = allListingIds.indexOf(Number(e.returnValues.listingID))
      const events = allListings[idx]
      if (e.event === 'OfferFinalized') {
        return false
      } else if (
        e.event === 'OfferCreated' &&
        events.some(t => t.event.match(/Offer(Withdrawn|Finalized)/))
      ) {
        return false
      } else if (
        e.event === 'OfferAccepted' &&
        events.some(t => t.event === 'OfferFinalized')
      ) {
        return false
      } else {
        return true
      }
    })
  }
  const totalCount = allEvents.length,
    allIds = allEvents.map(e => e.id)
  const { ids, start } = getIdsForPage({ after, ids: allIds, first })
  const filteredEvents = allEvents.filter(e => ids.indexOf(e.id) >= 0)
  let offers = [],
    nodes = []
  if (fields.nodes) {
    offers = await Promise.all(
      filteredEvents.map(event =>
        contracts.eventSource.getOffer(
          event.returnValues.listingID,
          event.returnValues.offerID,
          event.blockNumber
        )
      )
    )
    nodes = filteredEvents.map((event, idx) => {
      const party = event.returnValues.party
      return {
        id: event.id,
        offer: offers[idx],
        party: { id: party, account: { id: party } },
        event,
        read: false
      }
    })
  }
  return getConnection({ start, first, nodes, ids, totalCount })
}
async function notifications ( user , { first = 10 , after , filter } , _ , info ) { const fields = graphqlFields ( info ) const sellerListings = await ec ( ) . allEvents ( 'ListingCreated' , user . id ) const sellerListingIds = sellerListings . map ( e => Number ( e . returnValues . listingID ) ) const sellerEvents = await ec ( ) . offers ( sellerListingIds , null , [ 'OfferCreated' , 'OfferFinalized' , 'OfferWithdrawn' , 'OfferFundsAdded' , 'OfferDisputed' , 'OfferRuling' ] , user . id ) const buyerListings = await ec ( ) . allEvents ( 'OfferCreated' , user . id ) const buyerListingIds = buyerListings . map ( e => Number ( e . returnValues . listingID ) ) const buyerEvents = await ec ( ) . offers ( buyerListingIds , null , [ 'OfferAccepted' , 'OfferRuling' ] , user . id ) let allEvents = sortBy ( [ ... sellerEvents , ... buyerEvents ] , e => - e . blockNumber ) if ( filter === 'pending' ) { const allListingIds = allEvents . map ( e => Number ( e . returnValues . listingID ) ) const allListings = await Promise . all ( allListingIds . map ( id => ec ( ) . offers ( id ) ) ) allEvents = allEvents . filter ( e => { const idx = allListingIds . indexOf ( Number ( e . returnValues . listingID ) ) const events = allListings [ idx ] if ( e . event === 'OfferFinalized' ) { return false } else if ( e . event === 'OfferCreated' && events . some ( t => t . event . match ( / Offer(Withdrawn|Finalized) / ) ) ) { return false } else if ( e . event === 'OfferAccepted' && events . some ( t => t . event === 'OfferFinalized' ) ) { return false } else { return true } } ) } const totalCount = allEvents . length , allIds = allEvents . map ( e => e . id ) const { ids , start } = getIdsForPage ( { after , ids : allIds , first } ) const filteredEvents = allEvents . filter ( e => ids . indexOf ( e . id ) >= 0 ) let offers = [ ] , nodes = [ ] if ( fields . nodes ) { offers = await Promise . all ( filteredEvents . map ( event => contracts . eventSource . getOffer ( event . returnValues . listingID , event . returnValues . offerID , event . blockNumber ) ) ) nodes = filteredEvents . map ( ( event , idx ) => { const party = event . returnValues . party return { id : event . id , offer : offers [ idx ] , party : { id : party , account : { id : party } } , event , read : false } } ) } return getConnection ( { start , first , nodes , ids , totalCount } ) }
Sourced from offer events where user is alternate party
Sourced from offer events where user is alternate party