Class: Collavre::Api::V1::Mobile::DevicesController

Inherits:
BaseController show all
Defined in:
app/controllers/collavre/api/v1/mobile/devices_controller.rb

Overview

FCM registration for the Android companion. Push is a follow-up (MVP uses foreground polling), but registering the device now keeps the token current so push can light up without a client change.

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/collavre/api/v1/mobile/devices_controller.rb', line 11

def create
  device = Collavre::Device.find_by(fcm_token: device_params[:fcm_token]) ||
           current_user.devices.find_or_initialize_by(client_id: device_params[:client_id])

  device.assign_attributes(device_params)
  device.user = current_user
  device.device_type = :android if device.device_type.blank?
  device.save!
  head :no_content
end