aboutsummaryrefslogtreecommitdiff
path: root/classes/BeechatSync.php
blob: e0a2f90b8c23ec2f065cb664ab094444e6ff411e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

class BeechatSync {
        static function onFriendCreate($event, $object_type, $relationship) {
		if ($relationship->relationship == 'friendrequest') {
			elgg_load_library('elgg:beechat');
                        $friend = get_entity($relationship->guid_two);
                        // create friend request
			ejabberd_friend_request(elgg_get_logged_in_user_entity(), $friend);
		}
	}
        static function onFriendDelete($event, $object_type, $relationship) {
		if ($relationship->relationship == 'friendrequest') {
			elgg_load_library('elgg:beechat');
                        $subject = get_entity($relationship->guid_two);
			// here friend is guid_one because is the one initiating
                        $friend = get_entity($relationship->guid_one);
                        $friends = $friend->isFriendsWith($subject->guid);
                        if ($friends) {
                                // accept friend request
                		ejabberd_friend_accept(elgg_get_logged_in_user_entity(), $friend);
                        } else {
                                // decline friend request
				ejabberd_friend_deny(elgg_get_logged_in_user_entity(), $friend);
                        }
                }
                elseif ($relationship->relationship == 'friend') {
			elgg_load_library('elgg:beechat');
                        $subject = get_entity($relationship->guid_one);
                        $friend = get_entity($relationship->guid_two);
                        // delete friendship
			ejabberd_friend_remove(elgg_get_logged_in_user_entity(), $friend);
                }

	}

}