3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, 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('STATUSNET') && !defined('LACONICA')) { exit(1); }
22 class IMChannel extends Channel
29 return $imPlugin->transport;
32 function __construct($imPlugin)
34 $this->imPlugin = $imPlugin;
39 return $this->setNotify($user, 1);
44 return $this->setNotify($user, 0);
47 function output($user, $text)
49 $text = '['.common_config('site', 'name') . '] ' . $text;
50 $this->imPlugin->sendMessage($this->imPlugin->getScreenname($user), $text);
53 function error($user, $text)
55 $text = '['.common_config('site', 'name') . '] ' . $text;
57 $screenname = $this->imPlugin->getScreenname($user);
59 $this->imPlugin->sendMessage($screenname, $text);
63 'Could not send error message to user ' . common_log_objstring($user) .
64 ' on transport ' . $this->imPlugin->transport .' : user preference does not exist');
69 function setNotify($user, $notify)
73 $user_im_prefs = new User_im_prefs();
74 $user_im_prefs->transport = $this->imPlugin->transport;
75 $user_im_prefs->user_id = $user->id;
76 if($user_im_prefs->find() && $user_im_prefs->fetch()){
77 if($user_im_prefs->notify == $notify){
78 //notify is already set the way they want
81 $original = clone($user_im_prefs);
82 $user_im_prefs->notify = $notify;
83 $result = $user_im_prefs->update($original);
86 $last_error = &$_PEAR->getStaticProperty('DB_DataObject','lastError');
88 'Could not set notify flag to ' . $notify .
89 ' for user ' . common_log_objstring($user) .
90 ' on transport ' . $this->imPlugin->transport .' : ' . $last_error->message);
94 'User ' . $user->nickname . ' set notify flag to ' . $notify);
100 'Could not set notify flag to ' . $notify .
101 ' for user ' . common_log_objstring($user) .
102 ' on transport ' . $this->imPlugin->transport .' : user preference does not exist');