Class: NewsmastMastodon::Api::V1::NotificationTokensController

Inherits:
Api::BaseController
  • Object
show all
Includes:
Concerns::ApiResponseHelper
Defined in:
app/controllers/newsmast_mastodon/api/v1/notification_tokens_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
# File 'app/controllers/newsmast_mastodon/api/v1/notification_tokens_controller.rb', line 17

def create
  if @notification_token.present?
    render_result({}, 'api.notification.messages.token_already_exists')
  else
    NewsmastMastodon::NotificationToken.create!(notification_token_params.merge(account_id: .id))
    render_success({}, 'api.notification.messages.token_saved')
  end
end

#get_mute_statusObject



35
36
37
38
39
40
41
# File 'app/controllers/newsmast_mastodon/api/v1/notification_tokens_controller.rb', line 35

def get_mute_status
  if @notification_tokens.present?
    render_response(key: :mute, data: @notification_tokens.first.mute, status: :ok)
  else
    render_result({}, 'api.notification.messages.token_not_found', :not_found)
  end
end

#reset_device_tokensObject



52
53
54
55
56
57
58
59
# File 'app/controllers/newsmast_mastodon/api/v1/notification_tokens_controller.rb', line 52

def reset_device_tokens
  if @notification_tokens.present?
    @notification_tokens.destroy_all
    render_deleted('api.notification.messages.token_deleted')
  else
    render_result({}, 'api.errors.not_found', :not_found)
  end
end

#revoke_notification_tokenObject



26
27
28
29
30
31
32
33
# File 'app/controllers/newsmast_mastodon/api/v1/notification_tokens_controller.rb', line 26

def revoke_notification_token
  if @notification_token.present?
    @notification_token.destroy!
    render_deleted('api.notification.messages.token_deleted')
  else
    render_result({}, 'api.errors.not_found', :not_found)
  end
end

#update_muteObject



43
44
45
46
47
48
49
50
# File 'app/controllers/newsmast_mastodon/api/v1/notification_tokens_controller.rb', line 43

def update_mute
  if @notification_tokens.present?
    @notification_tokens.update_all(mute: notification_token_params[:mute])
    render_updated({}, 'api.notification.messages.mute_updated')
  else
    render_result({}, 'api.notification.messages.token_not_found', :not_found)
  end
end