you can specify 2 names and JOIN chat_users with itself and see if the 2 names matches and insert like below
insert into chat_friends(user,friend)
select cu1.uid,cu2.uid
from chat_users cu1 JOIN chat_users cu2
where cu1.name = 'foo'
and cu2.name = 'bar';
alternately you can just individually select the uid of each name as below too if you prefer.
insert into chat_friends(user,friend)
select (select uid from chat_users where name = 'foo'),
(select uid from chat_users where name = 'bar');