def get_peer_user_ids_for_stream_change(stream, altered_users, subscribed_users):
 altered_user_ids = [user.id for user in altered_users]
 if stream.invite_only:
  all_subscribed_ids = [user.id for user in subscribed_users]
  return (set(all_subscribed_ids) - set(altered_user_ids))
 else:
  return (set(active_user_ids(stream.realm)) - set(altered_user_ids))

def get_peer_user_ids_for_stream_change ( stream , altered_users , subscribed_users ) : altered_user_ids = [ user . id for user in altered_users ] if stream . invite_only : all_subscribed_ids = [ user . id for user in subscribed_users ] return ( set ( all_subscribed_ids ) - set ( altered_user_ids ) ) else : return ( set ( active_user_ids ( stream . realm ) ) - set ( altered_user_ids ) )
altered_users is a list of users that we are adding/removing subscribed_users is the list of already subscribed users based on stream policy .