avatar_updates.rb 745 B

123456789101112131415161718192021
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Subscriptions
  3. class User::Current::AvatarUpdates < BaseSubscription
  4. argument :user_id, GraphQL::Types::ID, 'ID of the user to receive avatar updates for', loads: Gql::Types::UserType
  5. description 'Updates to account avatar records'
  6. field :avatars, [Gql::Types::AvatarType], null: true, description: 'List of avatars for the user'
  7. # Instance method: allow subscriptions only for the current user
  8. def authorized?(user:)
  9. context.current_user.permissions?('user_preferences.avatar') && user.id == context.current_user.id
  10. end
  11. def update(user:)
  12. { avatars: Avatar.list('User', user.id, raw: true) }
  13. end
  14. end
  15. end