replies from people you're not subscribed to over Jabber

darcs-hash:20080715195513-84dde-454419c971015be385d9c4c35f7acbee419031f9.gz
This commit is contained in:
Evan Prodromou 2008-07-15 15:55:13 -04:00
parent 3f59000e73
commit 499afd8c22
19 changed files with 79 additions and 46 deletions

View File

@ -73,6 +73,9 @@ class ImsettingsAction extends SettingsAction {
common_checkbox('updatefrompresence', common_checkbox('updatefrompresence',
_('Post a notice when my Jabber/GTalk status changes.'), _('Post a notice when my Jabber/GTalk status changes.'),
$user->updatefrompresence); $user->updatefrompresence);
common_checkbox('jabberreplies',
_('Send me replies through Jabber/GTalk from people I\'m not subscribed to.'),
$user->jabberreplies);
common_submit('save', _('Save')); common_submit('save', _('Save'));
common_element_end('form'); common_element_end('form');
@ -110,6 +113,7 @@ class ImsettingsAction extends SettingsAction {
$jabbernotify = $this->boolean('jabbernotify'); $jabbernotify = $this->boolean('jabbernotify');
$updatefrompresence = $this->boolean('updatefrompresence'); $updatefrompresence = $this->boolean('updatefrompresence');
$jabberreplies = $this->boolean('jabberreplies');
$user = common_current_user(); $user = common_current_user();
@ -121,6 +125,7 @@ class ImsettingsAction extends SettingsAction {
$user->jabbernotify = $jabbernotify; $user->jabbernotify = $jabbernotify;
$user->updatefrompresence = $updatefrompresence; $user->updatefrompresence = $updatefrompresence;
$user->jabberreplies = $jabberreplies;
$result = $user->update($original); $result = $user->update($original);

View File

@ -12,8 +12,8 @@ class Reply extends DB_DataObject
public $__table = 'reply'; // table name public $__table = 'reply'; // table name
public $notice_id; // int(4) primary_key not_null public $notice_id; // int(4) primary_key not_null
public $profile_id; // int(4) primary_key not_null public $profile_id; // int(4) primary_key not_null
public $replied_id; // int(4)
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
public $replied_id; // int(4)
/* Static get */ /* Static get */
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Reply',$k,$v); } function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Reply',$k,$v); }

View File

@ -36,6 +36,7 @@ class User extends DB_DataObject
public $email; // varchar(255) unique_key public $email; // varchar(255) unique_key
public $jabber; // varchar(255) unique_key public $jabber; // varchar(255) unique_key
public $jabbernotify; // tinyint(1) public $jabbernotify; // tinyint(1)
public $jabberreplies; // tinyint(1)
public $updatefrompresence; // tinyint(1) public $updatefrompresence; // tinyint(1)
public $sms; // varchar(64) unique_key public $sms; // varchar(64) unique_key
public $carrier; // int(4) public $carrier; // int(4)

View File

@ -159,6 +159,7 @@ password = 2
email = 2 email = 2
jabber = 2 jabber = 2
jabbernotify = 17 jabbernotify = 17
jabberreplies = 17
updatefrompresence = 17 updatefrompresence = 17
sms = 2 sms = 2
carrier = 1 carrier = 1

View File

@ -47,6 +47,7 @@ create table user (
email varchar(255) unique key comment 'email address for password recovery etc.', email varchar(255) unique key comment 'email address for password recovery etc.',
jabber varchar(255) unique key comment 'jabber ID for notices', jabber varchar(255) unique key comment 'jabber ID for notices',
jabbernotify tinyint default 0 comment 'whether to send notices to jabber', jabbernotify tinyint default 0 comment 'whether to send notices to jabber',
jabberreplies tinyint default 0 comment 'whether to send notices to jabber on replies',
updatefrompresence tinyint default 0 comment 'whether to record updates from Jabber presence notices', updatefrompresence tinyint default 0 comment 'whether to record updates from Jabber presence notices',
sms varchar(64) unique key comment 'sms phone number', sms varchar(64) unique key comment 'sms phone number',
carrier integer comment 'foreign key to sms_carrier' references sms_carrier (id), carrier integer comment 'foreign key to sms_carrier' references sms_carrier (id),

View File

@ -194,8 +194,6 @@ function jabber_special_presence($type, $to=NULL, $show=NULL, $status=NULL) {
} }
function jabber_broadcast_notice($notice) { function jabber_broadcast_notice($notice) {
# First, get users subscribed to this profile
# XXX: use a join here rather than looping through results
$profile = Profile::staticGet($notice->profile_id); $profile = Profile::staticGet($notice->profile_id);
if (!$profile) { if (!$profile) {
common_log(LOG_WARNING, 'Refusing to broadcast notice with ' . common_log(LOG_WARNING, 'Refusing to broadcast notice with ' .
@ -203,23 +201,50 @@ function jabber_broadcast_notice($notice) {
__FILE__); __FILE__);
return false; return false;
} }
$sub = new Subscription(); $sent_to = array();
$sub->subscribed = $notice->profile_id; # First, get users who this is a direct reply to
if ($sub->find()) { $reply = new Reply();
while ($sub->fetch()) { $reply->notice_id = $notice->id;
$user = User::staticGet($sub->subscriber); if ($reply->find()) {
if ($user && $user->jabber && $user->jabbernotify) { while ($reply->fetch()) {
$user = User::staticGet($reply->profile_id);
if ($user && $user->jabber && $user->jabbernotify && $user->jabberreplies) {
common_log(LOG_INFO, common_log(LOG_INFO,
'Sending notice ' . $notice->id . ' to ' . $user->jabber, 'Sending reply notice ' . $notice->id . ' to ' . $user->jabber,
__FILE__); __FILE__);
$success = jabber_send_notice($user->jabber, $notice); $success = jabber_send_notice($user->jabber, $notice);
if (!$success) { if ($success) {
# Remember so we don't send twice
$sent_to[$user->id] = true;
} else {
# XXX: Not sure, but I think that's the right thing to do # XXX: Not sure, but I think that's the right thing to do
return false; return false;
} }
} }
} }
} }
# Now, get users subscribed to this profile
# XXX: use a join here rather than looping through results
$sub = new Subscription();
$sub->subscribed = $notice->profile_id;
if ($sub->find()) {
while ($sub->fetch()) {
$user = User::staticGet($sub->subscriber);
if ($user && $user->jabber && $user->jabbernotify && !$sent_to[$user->id]) {
common_log(LOG_INFO,
'Sending notice ' . $notice->id . ' to ' . $user->jabber,
__FILE__);
$success = jabber_send_notice($user->jabber, $notice);
if ($success) {
$sent_to[$user->id] = true;
# XXX: Not sure, but I think that's the right thing to do
return false;
}
}
}
}
return true; return true;
} }