20 public function __construct(
25 parent::__construct( $mainModule, $moduleName );
28 public function execute():
void {
29 if ( !$this->groupSubscription->isEnabled() ) {
30 $this->dieWithError(
'apierror-translate-messagegroupsubscription-disabled' );
33 $params = $this->extractRequestParams();
35 $groupId = $params[
'groupId'];
36 $operation = $params[
'operation'];
39 if ( $group ===
null ) {
40 $this->dieWithError(
'apierror-translate-invalidgroup',
'invalidgroup' );
43 $user = $this->getUser();
44 if ( $operation ===
'subscribe' ) {
45 $status = $this->groupSubscription->subscribeToGroup( $group, $user );
46 if ( !$status->isOK() ) {
47 $this->handleSubscriptionFailure( $status );
49 } elseif ( $operation ===
'unsubscribe' ) {
50 $this->groupSubscription->unsubscribeFromGroup( $group, $user );
53 $this->getResult()->addValue(
55 $this->getModuleName(),
60 'label' => $group->getLabel( $this->getContext() )
66 protected function getAllowedParams(): array {
69 ParamValidator::PARAM_TYPE =>
'string',
70 ParamValidator::PARAM_REQUIRED =>
true,
73 ParamValidator::PARAM_TYPE => [
'subscribe',
'unsubscribe' ],
74 ParamValidator::PARAM_ISMULTI =>
false,
75 ParamValidator::PARAM_REQUIRED =>
true,
80 public function isInternal():
bool {
84 public function needsToken():
string {
88 private function handleSubscriptionFailure( StatusValue $status ): never {
89 if ( $status->hasMessage( MessageGroupSubscription::NOT_ENABLED ) ) {
90 $this->dieWithError(
'apierror-translate-messagegroupsubscription-disabled' );
91 } elseif ( $status->hasMessage( MessageGroupSubscription::UNNAMED_USER_UNSUPPORTED ) ) {
93 [
'apierror-mustbeloggedin', $this->msg(
'action-translate-watch-message-group' ) ]
96 $this->dieWithError(
'apierror-translate-messagegroupsubscription-dynamic-group-unsupported' );