Spoke icon indicating copy to clipboard operation
Spoke copied to clipboard

Bug: Ghost Replies / Contacts

Open stefanhayden opened this issue 3 years ago • 4 comments

Describe the bug When 1 contact is in 2 campaigns and is marked as opt out in 1 of the campaigns the other campaign does not properly exclude that contact from the total count of contacts. This means the "Initials" box can never be 100% which is very confusing.

Also if a reply link is set to give out 10 replies but 5 people are opted out it will only give 5 replies to a person.

To Reproduce Steps to reproduce the behavior:

  1. Set up 2 campaigns with the same contact in both and a few other random contacts.
  2. In the first campaign start the convo and opt them out.
  3. Then get initials from the next campaign and send them all
  4. Observe how the campaign never hit 100%

Expected behavior Total Contacts should always represent the number of people who are textable. An op-out from the first campaign should drop the total count from other campaigns.

if a reply link is supposed to give out 10 replies it should find 10 people who can be texted.

stefanhayden avatar May 27 '21 23:05 stefanhayden

After some pairing with @Arique1104 we found the possible source.

The issue is that optouts are not being excluded from the counts on the TexterTodos page.

The TexterTodo interface is in this file with counts called from the GraphQl assignment root query here: https://github.com/MoveOnOrg/Spoke/blob/main/src/containers/TexterTodo.jsx#L146-L162 That calls this query: https://github.com/MoveOnOrg/Spoke/blob/main/src/server/api/schema.js#L1389-L1426 which after loading the assignment calls contactsCount (w/ diff parameters) here: https://github.com/MoveOnOrg/Spoke/blob/main/src/server/api/assignment.js#L244

contactsCount has some additional complexity because it is ALSO called from the TexterTodoList.jsx file through user/todos clientside: https://github.com/MoveOnOrg/Spoke/blob/main/src/containers/TexterTodoList.jsx#L149-L184 serverside: https://github.com/MoveOnOrg/Spoke/blob/main/src/server/api/user.js#L253

The todos call has a bunch of extra complexity which loads contacts counts and does a group by and creates counts to 'service' the assignment.contactsCount calls. The todos complexity is here:

https://github.com/MoveOnOrg/Spoke/blob/main/src/server/api/user.js#L298-L365

Significantly, in the path for the TexterTodosList user/todos query we DO filter for is_opted_out: https://github.com/MoveOnOrg/Spoke/blob/main/src/server/api/user.js#L304-L305

but we don't in the TexterTodo.jsx page for the counts.

One approach would be to make sure the count queries in contactsCount are running/doing the right things when the query is being run. -- maybe the MAIN bug is just in contactsCount: https://github.com/MoveOnOrg/Spoke/blob/main/src/server/api/assignment.js#L244 either here: https://github.com/MoveOnOrg/Spoke/blob/main/src/server/api/assignment.js#L258-L268 or somewhere else in the contactsCount method and then to make sure that the TexterTodos query filters out isOptedOut: false

schuyler1d avatar Sep 29 '21 17:09 schuyler1d

amazing research!

stefanhayden avatar Oct 01 '21 11:10 stefanhayden

@n0land0 @schuyler1d

We completed this:

https://github.com/MoveOnOrg/Spoke/blob/main/src/server/api/assignment.js#L258-L268 or somewhere else in the contactsCount method and then to make sure that the TexterTodos query filters out isOptedOut: false

We are hoping to create a new experiment to see if there is an additional bug in the server api call for contactCounts

  • Creating Campaign
  • With same contacts
  • Opt out a few
  • Check the database with the following sql queries and ensure these numbers are reflected in the TexterTodo countdown

Texter todo

Arique1104 avatar Jan 14 '22 00:01 Arique1104

@schuyler1d @Arique1104

Work done & PR'd this morning:

  • src/containers/TexterTodo.jsx: Add isOptedOut field to allContactsCount and set value to false
  • Test to ensure opt-out status persists across campaigns when creating a new campaign
  • Test to ensure that, if same contacts are loaded to two new campaigns simultaneously, the second campaign's total contacts update when a shared contact opts out of the first campaign

n0land0 avatar Jan 15 '22 19:01 n0land0