X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fcommand.php;h=ea7b60372d96542dd134069d7a94b67b4d40756c;hb=b0a75a2ab24673452674a8f296ca4dbb110bed6b;hp=ad2e0bb975d999d806ec41f4a8c492b2a9f95c3b;hpb=5d9a2eb17e3f6e3bc73b5aa80625a365761b6689;p=quix0rs-gnu-social.git diff --git a/lib/command.php b/lib/command.php index ad2e0bb975..ea7b60372d 100644 --- a/lib/command.php +++ b/lib/command.php @@ -222,18 +222,15 @@ class JoinCommand extends Command return; } - $member = new Group_member(); - - $member->group_id = $group->id; - $member->profile_id = $cur->id; - $member->created = common_sql_now(); - - $result = $member->insert(); - if (!$result) { - common_log_db_error($member, 'INSERT', __FILE__); - $channel->error($cur, sprintf(_('Could not join user %s to group %s'), - $cur->nickname, $group->nickname)); - return; + try { + if (Event::handle('StartJoinGroup', array($group, $cur))) { + Group_member::join($group->id, $cur->id); + Event::handle('EndJoinGroup', array($group, $cur)); + } + } catch (Exception $e) { + $channel->error($cur, sprintf(_('Could not join user %s to group %s'), + $cur->nickname, $group->nickname)); + return; } $channel->output($cur, sprintf(_('%s joined group %s'), @@ -269,21 +266,15 @@ class DropCommand extends Command return; } - $member = new Group_member(); - - $member->group_id = $group->id; - $member->profile_id = $cur->id; - - if (!$member->find(true)) { - $channel->error($cur,_('Could not find membership record.')); - return; - } - $result = $member->delete(); - if (!$result) { - common_log_db_error($member, 'INSERT', __FILE__); - $channel->error($cur, sprintf(_('Could not remove user %s to group %s'), - $cur->nickname, $group->nickname)); - return; + try { + if (Event::handle('StartLeaveGroup', array($group, $cur))) { + Group_member::leave($group->id, $cur->id); + Event::handle('EndLeaveGroup', array($group, $cur)); + } + } catch (Exception $e) { + $channel->error($cur, sprintf(_('Could not remove user %s to group %s'), + $cur->nickname, $group->nickname)); + return; } $channel->output($cur, sprintf(_('%s left group %s'), @@ -431,7 +422,7 @@ class RepeatCommand extends Command $repeat = $notice->repeat($this->user->id, $channel->source); if ($repeat) { - common_broadcast_notice($repeat); + $channel->output($this->user, sprintf(_('Notice from %s repeated'), $recipient->nickname)); } else { $channel->error($this->user, _('Error repeating notice.')); @@ -501,7 +492,7 @@ class ReplyCommand extends Command } else { $channel->error($this->user, _('Error saving notice.')); } - common_broadcast_notice($notice); + } } @@ -557,12 +548,19 @@ class SubCommand extends Command return; } - $result = subs_subscribe_user($this->user, $this->other); + $otherUser = User::staticGet('nickname', $this->other); - if ($result == 'true') { + if (empty($otherUser)) { + $channel->error($this->user, _('No such user')); + return; + } + + try { + Subscription::start($this->user->getProfile(), + $otherUser->getProfile()); $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other)); - } else { - $channel->error($this->user, $result); + } catch (Exception $e) { + $channel->error($this->user, $e->getMessage()); } } } @@ -585,12 +583,18 @@ class UnsubCommand extends Command return; } - $result=subs_unsubscribe_user($this->user, $this->other); + $otherUser = User::staticGet('nickname', $this->other); - if ($result) { + if (empty($otherUser)) { + $channel->error($this->user, _('No such user')); + } + + try { + Subscription::cancel($this->user->getProfile(), + $otherUser->getProfile()); $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other)); - } else { - $channel->error($this->user, $result); + } catch (Exception $e) { + $channel->error($this->user, $e->getMessage()); } } } @@ -650,25 +654,17 @@ class LoginCommand extends Command $channel->error($this->user, _('Login command is disabled')); return; } - $login_token = Login_token::staticGet('user_id',$this->user->id); - if($login_token){ - $login_token->delete(); - } - $login_token = new Login_token(); - $login_token->user_id = $this->user->id; - $login_token->token = common_good_rand(16); - $login_token->created = common_sql_now(); - $result = $login_token->insert(); - if (!$result) { - common_log_db_error($login_token, 'INSERT', __FILE__); - $channel->error($this->user, sprintf(_('Could not create login token for %s'), - $this->user->nickname)); - return; + + try { + $login_token = Login_token::makeNew($this->user); + } catch (Exception $e) { + $channel->error($this->user, $e->getMessage()); } + $channel->output($this->user, sprintf(_('This link is useable only once, and is good for only 2 minutes: %s'), - common_local_url('login', - array('user_id'=>$login_token->user_id, 'token'=>$login_token->token)))); + common_local_url('otp', + array('user_id' => $login_token->user_id, 'token' => $login_token->token)))); } } @@ -742,42 +738,42 @@ class HelpCommand extends Command function execute($channel) { $channel->output($this->user, - _("Commands:")."\n". - _("on - turn on notifications")."\n". - _("off - turn off notifications")."\n". - _("help - show this help")."\n". - _("follow - subscribe to user")."\n". - _("groups - lists the groups you have joined")."\n". - _("subscriptions - list the people you follow")."\n". - _("subscribers - list the people that follow you")."\n". - _("leave - unsubscribe from user")."\n". - _("d - direct message to user")."\n". - _("get - get last notice from user")."\n". - _("whois - get profile info on user")."\n". - _("fav - add user's last notice as a 'fave'")."\n". - _("fav # - add notice with the given id as a 'fave'")."\n". - _("repeat # - repeat a notice with a given id")."\n". - _("repeat - repeat the last notice from user")."\n". - _("reply # - reply to notice with a given id")."\n". - _("reply - reply to the last notice from user")."\n". - _("join - join group")."\n". - #_("login - Get a link to login to the web interface")."\n". - _("drop - leave group")."\n". - _("stats - get your stats")."\n". - _("stop - same as 'off'")."\n". - _("quit - same as 'off'")."\n". - _("sub - same as 'follow'")."\n". - _("unsub - same as 'leave'")."\n". - _("last - same as 'get'")."\n". - #_("on - not yet implemented.")."\n". - #_("off - not yet implemented.")."\n". - _("nudge - remind a user to update.")."\n"); - #_("invite - not yet implemented.")."\n". - #_("track - not yet implemented.")."\n". - #_("untrack - not yet implemented.")."\n". - #_("track off - not yet implemented.")."\n". - #_("untrack all - not yet implemented.")."\n". - #_("tracks - not yet implemented.")."\n". - #_("tracking - not yet implemented.")."\n" + _("Commands:\n". + "on - turn on notifications\n". + "off - turn off notifications\n". + "help - show this help\n". + "follow - subscribe to user\n". + "groups - lists the groups you have joined\n". + "subscriptions - list the people you follow\n". + "subscribers - list the people that follow you\n". + "leave - unsubscribe from user\n". + "d - direct message to user\n". + "get - get last notice from user\n". + "whois - get profile info on user\n". + "fav - add user's last notice as a 'fave'\n". + "fav # - add notice with the given id as a 'fave'\n". + "repeat # - repeat a notice with a given id\n". + "repeat - repeat the last notice from user\n". + "reply # - reply to notice with a given id\n". + "reply - reply to the last notice from user\n". + "join - join group\n". + "login - Get a link to login to the web interface\n". + "drop - leave group\n". + "stats - get your stats\n". + "stop - same as 'off'\n". + "quit - same as 'off'\n". + "sub - same as 'follow'\n". + "unsub - same as 'leave'\n". + "last - same as 'get'\n". + "on - not yet implemented.\n". + "off - not yet implemented.\n". + "nudge - remind a user to update.\n". + "invite - not yet implemented.\n". + "track - not yet implemented.\n". + "untrack - not yet implemented.\n". + "track off - not yet implemented.\n". + "untrack all - not yet implemented.\n". + "tracks - not yet implemented.\n". + "tracking - not yet implemented.\n")); } }