From c34a97ec3e59b96201e061ddda0d834e198a16b1 Mon Sep 17 00:00:00 2001 From: Sarah Scott Date: Tue, 30 Jan 2018 16:31:31 +0100 Subject: [PATCH] [msg] filter msgs without attachments or bodies if ignoreBlankMessages is true --- .../conversation/conversation.test.js | 17 +++++- src/schema/me/conversation/index.js | 10 +++- yarn.lock | 57 ++++--------------- 3 files changed, 34 insertions(+), 50 deletions(-) diff --git a/src/schema/me/__tests__/conversation/conversation.test.js b/src/schema/me/__tests__/conversation/conversation.test.js index 09a55e7ff1..143a1570bd 100644 --- a/src/schema/me/__tests__/conversation/conversation.test.js +++ b/src/schema/me/__tests__/conversation/conversation.test.js @@ -255,12 +255,14 @@ describe("Me", () => { }) describe("messages", () => { - const getQuery = (sort = "ASC") => { + const getQuery = (sort = "ASC", ignoreBlankMessages = null) => { return ` { me { conversation(id: "420") { - messages(first: 10, sort: ${sort}) { + messages(first: 10, sort: ${sort}, ignoreBlankMessages: ${ + ignoreBlankMessages + }) { edges { node { id @@ -294,6 +296,17 @@ describe("Me", () => { } ) }) + + it("filters empty messages if ignoreBlankMessages is true", () => { + const query = getQuery("ASC", true) + + return runAuthenticatedQuery(query, rootValue).then( + ({ me: { conversation: { messages } } }) => { + expect(messages.edges.length).toEqual(1) + expect(messages.edges[0].node.id).toEqual("240") + } + ) + }) }) }) }) diff --git a/src/schema/me/conversation/index.js b/src/schema/me/conversation/index.js index 6ca704a3c1..0a19c7ce6e 100644 --- a/src/schema/me/conversation/index.js +++ b/src/schema/me/conversation/index.js @@ -370,8 +370,16 @@ export const ConversationFields = { conversation_id: id, }) }) + + const filtered_messages = options.ignoreBlankMessages + ? message_details.filter( + message => + (message.body && message.body.length) || + (message.attachments && message.attachments.length) + ) + : message_details /* eslint-disable no-param-reassign */ - return connectionFromArraySlice(message_details, options, { + return connectionFromArraySlice(filtered_messages, options, { arrayLength: total_count, sliceStart: offset, }) diff --git a/yarn.lock b/yarn.lock index 00a04b845b..d34fe0b736 100644 --- a/yarn.lock +++ b/yarn.lock @@ -96,11 +96,7 @@ dependencies: "@types/graphql" "*" -"@types/graphql@*": - version "0.11.7" - resolved "https://registry.yarnpkg.com/@types/graphql/-/graphql-0.11.7.tgz#da39a2f7c74e793e32e2bb7b3b68da1691532dd5" - -"@types/graphql@^0.8.2": +"@types/graphql@*", "@types/graphql@^0.8.2": version "0.8.6" resolved "https://registry.yarnpkg.com/@types/graphql/-/graphql-0.8.6.tgz#b34fb880493ba835b0c067024ee70130d6f9bb68" @@ -405,14 +401,10 @@ async-each@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d" -async@0.2.9: +async@0.2.9, async@0.2.x, async@~0.2.9: version "0.2.9" resolved "https://registry.yarnpkg.com/async/-/async-0.2.9.tgz#df63060fbf3d33286a76aaf6d55a2986d9ff8619" -async@0.2.x, async@~0.2.9: - version "0.2.10" - resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1" - async@^1.4.0: version "1.5.2" resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" @@ -3099,14 +3091,14 @@ js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" -js-yaml@3.4.5: +js-yaml@3.4.5, js-yaml@^3.4.3: version "3.4.5" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.4.5.tgz#c3403797df12b91866574f2de23646fe8cafb44d" dependencies: argparse "^1.0.2" esprima "^2.6.0" -js-yaml@^3.4.3, js-yaml@^3.7.0: +js-yaml@^3.7.0: version "3.10.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc" dependencies: @@ -3745,14 +3737,10 @@ mu2@~0.5.20: version "0.5.21" resolved "https://registry.yarnpkg.com/mu2/-/mu2-0.5.21.tgz#888a8f0fd90eb1cfda9db81476f6e199cc9e58d3" -mute-stream@0.0.5: +mute-stream@0.0.5, mute-stream@~0.0.4: version "0.0.5" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0" -mute-stream@~0.0.4: - version "0.0.7" - resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" - nan@^2.3.0, nan@^2.4.0: version "2.8.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.8.0.tgz#ed715f3fe9de02b57a5e6252d90a96675e1f085a" @@ -4162,14 +4150,10 @@ pinkie@^2.0.0: version "2.0.4" resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" -pkginfo@0.3.x: +pkginfo@0.3.x, pkginfo@0.x.x: version "0.3.1" resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.3.1.tgz#5b29f6a81f70717142e09e765bbeab97b4f81e21" -pkginfo@0.x.x: - version "0.4.1" - resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.4.1.tgz#b5418ef0439de5425fc4995042dced14fb2a84ff" - postinstall-prepare@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/postinstall-prepare/-/postinstall-prepare-1.0.1.tgz#dac9b5d91b054389141b13c0192eb68a0aa002b5" @@ -4315,16 +4299,7 @@ raw-body@2.3.2, raw-body@^2.1.0: iconv-lite "0.4.19" unpipe "1.0.0" -rc@^1.0.1, rc@^1.1.6: - version "1.2.4" - resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.4.tgz#a0f606caae2a3b862bbd0ef85482c0125b315fa3" - dependencies: - deep-extend "~0.4.0" - ini "~1.3.0" - minimist "^1.2.0" - strip-json-comments "~2.0.1" - -rc@^1.1.7: +rc@^1.0.1, rc@^1.1.6, rc@^1.1.7: version "1.2.2" resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.2.tgz#d8ce9cb57e8d64d9c7badd9876c7c34cbe3c7077" dependencies: @@ -4640,14 +4615,10 @@ safe-buffer@5.1.1, safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@~5.1.0, s version "5.1.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" -samsam@1.1.2: +samsam@1.1.2, samsam@~1.1: version "1.1.2" resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.2.tgz#bec11fdc83a9fda063401210e40176c3024d1567" -samsam@~1.1: - version "1.1.3" - resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.3.tgz#9f5087419b4d091f232571e7fa52e90b0f552621" - sane@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/sane/-/sane-2.2.0.tgz#d6d2e2fcab00e3d283c93b912b7c3a20846f1d56" @@ -4672,14 +4643,10 @@ semver-diff@^2.0.0: dependencies: semver "^5.0.3" -"semver@2 || 3 || 4 || 5", semver@^5.3.0: +"semver@2 || 3 || 4 || 5", semver@^5.0.3, semver@^5.1.0, semver@^5.3.0: version "5.4.1" resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e" -semver@^5.0.3, semver@^5.1.0: - version "5.5.0" - resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab" - send@0.16.1: version "0.16.1" resolved "https://registry.yarnpkg.com/send/-/send-0.16.1.tgz#a70e1ca21d1382c11d0d9f6231deb281080d7ab3" @@ -4850,11 +4817,7 @@ staged-git-files@0.0.4: version "0.0.4" resolved "https://registry.yarnpkg.com/staged-git-files/-/staged-git-files-0.0.4.tgz#d797e1b551ca7a639dec0237dc6eb4bb9be17d35" -"statuses@>= 1.3.1 < 2": - version "1.4.0" - resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087" - -statuses@~1.3.1: +"statuses@>= 1.3.1 < 2", statuses@~1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"