diff --git a/actions/imsettings.php b/actions/imsettings.php new file mode 100644 index 0000000000..b34f8ca12d --- /dev/null +++ b/actions/imsettings.php @@ -0,0 +1,120 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +require_once(INSTALLDIR.'/lib/settingsaction.php'); + +class ImsettingsAction extends SettingsAction { + + function show_top($arr) { + $msg = $arr[0]; + $success = $arr[1]; + if ($msg) { + $this->message($msg, $success); + } else { + common_element('div', 'instructions', + _t('You can send and receive notices through '. + 'Jabber/GTalk instant messages. Configure '. + 'your address and settings below.')); + } + $this->settings_menu(); + } + + function show_form($msg=NULL, $success=false) { + $user = common_current_user(); + common_show_header(_t('IM settings'), NULL, array($msg, $success), + array($this, 'show_top')); + + common_element_start('form', array('method' => 'POST', + 'id' => 'imsettings', + 'action' => + common_local_url('imsettings'))); + # too much common patterns here... abstractable? + common_input('jabber', _t('IM Address'), + ($this->arg('jabber')) ? $this->arg('jabber') : $user->jabber, + _t('Jabber or GTalk address, like "UserName@example.org"')); + common_checkbox('jabbernotify', + _t('Send me notices through Jabber/GTalk.')); + common_checkbox('updatefrompresence', + _t('Post a notice when my Jabber/GTalk status changes.')); + common_submit('submit', _t('Save')); + common_element_end('form'); + common_show_footer(); + } + + function handle_post() { + + $jabber = $this->trimmed('jabber'); + $jabbernotify = $this->boolean('jabbernotify'); + $updatefrompresence = $this->boolean('updatefrompresence'); + + if (!jabber_validate_jid($jabber)) { + $this->show_form(_('Not a valid Jabber ID')); + return; + } else if ($this->jabber_exists($jabber)) { + $this->show_form(_('Not a valid Jabber ID')); + return; + } + + # Some validation + + $user = common_current_user(); + + assert(!is_null($user)); # should already be checked + + $user->query('BEGIN'); + + $original = clone($user); + + $user->jabber = $jabber; + $user->jabbernotify = $jabbernotify; + $user->updatefrompresence = $updatefrompresence; + + $result = $user->updateKeys($original); # For key columns + + if ($result === FALSE) { + common_log_db_error($user, 'UPDATE', __FILE__); + common_server_error(_t('Couldnt update user.')); + return; + } + + $result = $user->update($original); # For non-key columns + + if ($result === FALSE) { + common_log_db_error($user, 'UPDATE', __FILE__); + common_server_error(_t('Couldnt update user.')); + return; + } + + $user->query('COMMIT'); + + $this->show_form(_t('Settings saved.'), TRUE); + } + + function jabber_exists($jabber) { + $user = common_current_user(); + $other = User::staticGet('jabber', $jabber); + if (!$other) { + return false; + } else { + return $other->id != $user->id; + } + } +} diff --git a/classes/User.php b/classes/User.php index e735457f9d..370dad82f7 100644 --- a/classes/User.php +++ b/classes/User.php @@ -35,8 +35,11 @@ class User extends DB_DataObject public $password; // varchar(255) public $email; // varchar(255) unique_key public $jabber; // varchar(255) unique_key + public $jabbernotify; // tinyint(1) + public $updatefrompresence; // tinyint(1) public $sms; // varchar(64) unique_key public $carrier; // int(4) + public $smsnotify; // tinyint(1) public $uri; // varchar(255) unique_key public $created; // datetime() not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP diff --git a/classes/stoica.ini b/classes/stoica.ini index 96f3d06bc8..4fe395f59c 100644 --- a/classes/stoica.ini +++ b/classes/stoica.ini @@ -128,8 +128,11 @@ nickname = 2 password = 2 email = 2 jabber = 2 +jabbernotify = 17 +updatefrompresence = 17 sms = 2 carrier = 1 +smsnotify = 17 uri = 2 created = 142 modified = 384 diff --git a/lib/settingsaction.php b/lib/settingsaction.php index dafa0e4bc9..fad6abaf12 100644 --- a/lib/settingsaction.php +++ b/lib/settingsaction.php @@ -21,67 +21,60 @@ if (!defined('LACONICA')) { exit(1); } class SettingsAction extends Action { - function handle($args) { - parent::handle($args); - if (!common_logged_in()) { - common_user_error(_t('Not logged in.')); - return; - } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $this->handle_post(); - } else { - $this->show_form(); - } - } + function handle($args) { + parent::handle($args); + if (!common_logged_in()) { + common_user_error(_t('Not logged in.')); + return; + } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->handle_post(); + } else { + $this->show_form(); + } + } - # override! - function handle_post() { - return false; - } + # override! + function handle_post() { + return false; + } - function show_form($msg=NULL, $success=false) { - return false; - } + function show_form($msg=NULL, $success=false) { + return false; + } - function message($msg, $success) { - if ($msg) { - common_element('div', ($success) ? 'success' : 'error', - $msg); - } - } + function message($msg, $success) { + if ($msg) { + common_element('div', ($success) ? 'success' : 'error', + $msg); + } + } - function settings_menu() { - $action = $this->trimmed('action'); - common_element_start('ul', array('id' => 'nav_views')); - common_menu_item(common_local_url('profilesettings'), - _t('Profile'), - _t('Change your profile settings'), - $action == 'profilesettings'); - common_menu_item(common_local_url('avatar'), - _t('Avatar'), - _t('Upload a new profile image'), - $action == 'avatar'); - common_menu_item(common_local_url('password'), - _t('Password'), - _t('Change your password'), - $action == 'password'); - common_menu_item(common_local_url('openidsettings'), - _t('OpenID'), - _t('Add or remove OpenIDs'), - $action == 'openidsettings'); - if (false) { - common_menu_item(common_local_url('emailsettings'), - _t('Email'), - _t('Address and preferences'), - $action == 'emailsettings'); - common_menu_item(common_local_url('imsettings'), - _t('IM'), - _t('Notifications by instant messenger'), - $action == 'imsettings'); - common_menu_item(common_local_url('phonesettings'), - _t('Phone'), - _t('Notifications by phone'), - $action == 'phonesettings'); - } - common_element_end('ul'); - } + function settings_menu() { + # action => array('prompt', 'title') + static $menu = + array('profilesettings' => + array('Profile', + 'Change your profile settings'), + 'avatar' => + array('Avatar', + 'Upload a new profile image'), + 'password' => + array('Password', + 'Change your password'), + 'openidsettings' => + array('OpenID', + 'Add or remove OpenIDs'), + 'imsettings' => + array('IM', + 'Updates by instant messenger (IM)')); + + $action = $this->trimmed('action'); + common_element_start('ul', array('id' => 'nav_views')); + foreach ($menu as $menuaction => $menudesc) { + common_menu_item(common_local_url($menuaction), + _t($menudesc[0]), + _t($menudesc[1])); + } + common_element_end('ul'); + } } diff --git a/xmppdaemon.php b/xmppdaemon.php index e055182c92..aa402b1e2c 100644 --- a/xmppdaemon.php +++ b/xmppdaemon.php @@ -58,7 +58,7 @@ class XMPPDaemon { $resource = $matches[3]; return strtolower($node.'@'.$server); } - + function handle() { while(!$this->conn->disconnected) { $payloads = $this->conn->processUntil(array('message', 'presence', @@ -81,6 +81,12 @@ class XMPPDaemon { } function handle_message(&$pl) { + if ($pl['type'] != 'chat') { + return; + } + if (strlen($pl['body']) == 0) { + return; + } $from = $this->normalize_jid($pl['from']); $user = User::staticGet('jabber', $from); if (!$user) {