dica icon indicating copy to clipboard operation
dica copied to clipboard

follow / unfollow

Open jasoncheng opened this issue 6 years ago • 2 comments

it's look like already have well design in src/Model/Contact; i can just use it on API. goal setting: can follow by url (mastodon / diaspora* / friendica) or existing contact id or email

function api_friendships_destroy($type)
{
        $cid = $_REQUEST['cid'];
        $result = Contact::remove($cid);
        return api_format_data('results', $type, ['results' => $result]);
}

function api_friendships_create($type)
{
        $url = $_REQUEST['url'];

        // here will do the magic, create remote user to local network (testing on diaspora* / mastodon is works)
        $uid = Contact::getIdForURL($url);

        // when user is Friendica user, will cause error, still need to find the correct way
        $result = Contact::createFromProbe(api_user(), $url, true);

        return api_format_data("results", $type, ['results' => $result]);
}

function api_friendships_exists($type)
{
   // need more research on where the code i can reuse
}

api_register_func('api/friendships/destroy', 'api_friendships_destroy', true, API_METHOD_DELETE); api_register_func('api/friendships/create', 'api_friendships_create', true, API_METHOD_POST); api_register_func('api/friendships/exists', 'api_friendships_exists', true, API_METHOD_GET);

testing URL: https://jason.holi.chat/api/friendships/[email protected] https://jason.holi.chat/api/friendships/destroy?cid=547

jasoncheng avatar Dec 24 '18 14:12 jasoncheng