3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once('XMPPHP/XMPP.php');
24 /* Subscribe $user to nickname $other_nickname
25 Returns true or an error message.
27 function subs_subscribe_user($user,$other_nickname) {
29 $other = User::staticGet('nickname', $other_nickname);
32 return _('No such user.');
35 if ($user->isSubscribed($other)) {
36 return _('Already subscribed!.');
39 if (!$user->subscribeTo($other)) {
40 return _('Could not subscribe.');
44 subs_notify($other, $user);
46 if (common_config('memcached', 'enabled')) {
47 $cache = new Memcache();
48 if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
49 $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
53 if ($other->autosubscribe && !$other->isSubscribed($user)) {
54 if (!$other->subscribeTo($user)) {
55 return _('Could not subscribe other to you.');
57 if (common_config('memcached', 'enabled')) {
58 $cache = new Memcache();
59 if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
60 $cache->delete(common_cache_key('user:notices_with_friends:' . $other->id));
64 subs_notify($user, $other);
70 function subs_notify($listenee, $listener) {
71 # XXX: add other notifications (Jabber, SMS) here
72 # XXX: queue this and handle it offline
73 # XXX: Whatever happens, do it in Twitter-like API, too
74 subs_notify_email($listenee, $listener);
77 function subs_notify_email($listenee, $listener) {
78 mail_subscribe_notify($listenee, $listener);
82 /* Unsubscribe $user from nickname $other_nickname
83 Returns true or an error message.
85 function subs_unsubscribe_user($user, $other_nickname) {
87 $other = User::staticGet('nickname', $other_nickname);
89 return _('No such user.');
91 if (!$user->isSubscribed($other))
92 return _('Not subscribed!.');
94 $sub = DB_DataObject::factory('subscription');
96 $sub->subscriber = $user->id;
97 $sub->subscribed = $other->id;
101 // note we checked for existence above
104 return _('Couldn\'t delete subscription.');
106 if (common_config('memcached', 'enabled')) {
107 $cache = new Memcache();
108 if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
109 $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));