{"size": 1031, "ext": "js", "max_stars_repo_path": "src/redux/actions/send-topic-packet/index.js", "max_stars_repo_name": "hideoutchat/web-client", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/redux/actions/send-topic-packet/index.js", "max_issues_repo_name": "hideoutchat/web-client", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/redux/actions/send-topic-packet/index.js", "max_forks_repo_name": "hideoutchat/web-client", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.976744186, "max_line_length": 94, "alphanum_fraction": 0.555771096}
const isRelated = (a, relationshipName, b) => {
  if (a.relationships[relationshipName].id === b.id) {
    if (a.relationships[relationshipName].type === b.type) {
      return true;
    }
  }
  return false;
};

const sendTopicPacket = ({ packet, topic }) => (dispatch, getState) => {
  const {
    connection: {
      sendPeerEvent
    },
    indexes: {
      resources: {
        by: {
          id: resourcesById,
          type: {
            self: [{
              relationships: {
                identity: sender
              }
            }],
            topicMembership: memberships
          }
        }
      }
    }
  } = getState();

  for (const member of memberships) {
    if (isRelated(member, 'topic', topic) && !isRelated(member, 'identity', sender)) {
      const [recipient] = resourcesById[member.relationships.identity.id];
      const [{ attributes: publicKey }] = resourcesById[recipient.relationships.publicKey.id];

      sendPeerEvent(publicKey, packet);
    }
  }
};

export default sendTopicPacket;
