utils: Fix maybe_splice_recipient when "object" isn’t a map
This commit is contained in:
		
							parent
							
								
									0b88accae6
								
							
						
					
					
						commit
						53193b84b1
					
				
					 3 changed files with 9 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -12,4 +12,10 @@ def put_if_present(map, key, value, value_function \\ &{:ok, &1}) when is_map(ma
 | 
			
		|||
      _ -> map
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def safe_put_in(data, keys, value) when is_map(data) and is_list(keys) do
 | 
			
		||||
    Kernel.put_in(data, keys, value)
 | 
			
		||||
  rescue
 | 
			
		||||
    _ -> data
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -96,11 +96,11 @@ def maybe_splice_recipient(ap_id, params) do
 | 
			
		|||
        !label_in_collection?(ap_id, params["cc"])
 | 
			
		||||
 | 
			
		||||
    if need_splice? do
 | 
			
		||||
      cc_list = extract_list(params["cc"])
 | 
			
		||||
      cc = [ap_id | extract_list(params["cc"])]
 | 
			
		||||
 | 
			
		||||
      params
 | 
			
		||||
      |> Map.put("cc", [ap_id | cc_list])
 | 
			
		||||
      |> Kernel.put_in(["object", "cc"], [ap_id | cc_list])
 | 
			
		||||
      |> Map.put("cc", cc)
 | 
			
		||||
      |> Maps.safe_put_in(["object", "cc"], cc)
 | 
			
		||||
    else
 | 
			
		||||
      params
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1003,7 +1003,6 @@ test "forwarded report from mastodon", %{conn: conn} do
 | 
			
		|||
        "actor" => remote_actor,
 | 
			
		||||
        "content" => "test report",
 | 
			
		||||
        "id" => "https://#{remote_domain}/e3b12fd1-948c-446e-b93b-a5e67edbe1d8",
 | 
			
		||||
        "nickname" => reported_user.nickname,
 | 
			
		||||
        "object" => [
 | 
			
		||||
          reported_user.ap_id,
 | 
			
		||||
          note.data["object"]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue