jasoncheng / dica

This is a very simple Friendica android client, wrote by Android Kotlin
GNU General Public License v3.0
14 stars 2 forks source link

follow / unfollow #117

Open jasoncheng opened 5 years ago

jasoncheng commented 5 years ago

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/create?url=jasoncheng@diasp.org https://jason.holi.chat/api/friendships/destroy?cid=547

jasoncheng commented 5 years ago

not that simple, too complicate for me, temporary pause

Rik44444 commented 5 years ago

great, yeah this would be a useful addition Jason, to be able to follow/be-friends with people via the app