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)
71 $user_im_prefs = new User_im_prefs();
72 $user_im_prefs->transport = $this->imPlugin->transport;
73 $user_im_prefs->user_id = $user->id;
74 if($user_im_prefs->find() && $user_im_prefs->fetch()){
75 if($user_im_prefs->notify == $notify){
76 //notify is already set the way they want
79 $original = clone($user_im_prefs);
80 $user_im_prefs->notify = $notify;
81 $result = $user_im_prefs->update($original);
84 $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
86 'Could not set notify flag to ' . $notify .
87 ' for user ' . common_log_objstring($user) .
88 ' on transport ' . $this->imPlugin->transport .' : ' . $last_error->message);
92 'User ' . $user->nickname . ' set notify flag to ' . $notify);
98 'Could not set notify flag to ' . $notify .
99 ' for user ' . common_log_objstring($user) .
100 ' on transport ' . $this->imPlugin->transport .' : user preference does not exist');