<commit_before>package util.syntax

import scala.language.{higherKinds, implicitConversions}

import play.api.i18n.Lang
import play.twirl.api.Html

import db.impl.access.UserBase
import ore.OreConfig
import ore.db.access.ModelView
import ore.db.{DbRef, Model, ModelService}
import ore.db.impl.OrePostgresDriver.api._
import ore.markdown.MarkdownRenderer
import ore.models.organization.Organization
import ore.models.project.{Page, Project}
import ore.models.user.{Session, User}
import ore.util.OreMDC
import security.spauth.SpongeAuthApi

import cats.Monad
import cats.syntax.all._
import cats.data.OptionT
import cats.effect.IO

trait ModelSyntax {

  implicit def userSyntax(u: User): ModelSyntax.UserSyntax                         = new ModelSyntax.UserSyntax(u)
  implicit def userModelRawSyntax(u: Model[User]): ModelSyntax.UserSyntax          = new ModelSyntax.UserSyntax(u)
  implicit def userObjSyntax(u: User.type): ModelSyntax.UserObjSyntax              = new ModelSyntax.UserObjSyntax(u)
  implicit def sessionSyntax(s: Session): ModelSyntax.SessionSyntax                = new ModelSyntax.SessionSyntax(s)
  implicit def sessionModelRawSyntax(s: Model[Session]): ModelSyntax.SessionSyntax = new ModelSyntax.SessionSyntax(s)
  implicit def pageSyntax(p: Page): ModelSyntax.PageSyntax                         = new ModelSyntax.PageSyntax(p)
  implicit def pageModelRawSyntax(p: Model[Page]): ModelSyntax.PageSyntax          = new ModelSyntax.PageSyntax(p)
  implicit def pageObjSyntax(p: Page.type): ModelSyntax.PageObjSyntax              = new ModelSyntax.PageObjSyntax(p)
  implicit def projectModelSyntax(p: Model[Project]): ModelSyntax.ProjectModelSyntax =
    new ModelSyntax.ProjectModelSyntax(p)
  implicit def orgSyntax(o: Organization): ModelSyntax.OrganizationSyntax = new ModelSyntax.OrganizationSyntax(o)
  implicit def orgModelRawSyntax(o: Model[Organization]): ModelSyntax.OrganizationSyntax =
    new ModelSyntax.OrganizationSyntax(o)
}
object ModelSyntax extends ModelSyntax {

  class UserSyntax(private val u: User) extends AnyVal {

    def avatarUrl(implicit config: OreConfig): String = User.avatarUrl(u.name)

    /**
      * Returns this user's current language, or the default language if none
      * was configured.
      */
    implicit def langOrDefault: Lang = u.lang.fold(Lang.defaultLang)(Lang.apply)
  }

  class UserObjSyntax(private val u: User.type) extends AnyVal {

    def avatarUrl(name: String)(implicit config: OreConfig): String =
      config.security.api.avatarUrl.format(name)
  }

  class SessionSyntax(private val s: Session) extends AnyVal {

    /**
      * Returns the [[User]] that this Session belongs to.
      *
      * @param users UserBase instance<commit_msg>Give Spongie an avatar (#819)<commit_after>package util.syntax

import scala.language.{higherKinds, implicitConversions}

import play.api.i18n.Lang
import play.twirl.api.Html

import db.impl.access.UserBase
import ore.OreConfig
import ore.db.access.ModelView
import ore.db.{DbRef, Model, ModelService}
import ore.db.impl.OrePostgresDriver.api._
import ore.markdown.MarkdownRenderer
import ore.models.organization.Organization
import ore.models.project.{Page, Project}
import ore.models.user.{Session, User}
import ore.util.OreMDC
import security.spauth.SpongeAuthApi

import cats.Monad
import cats.syntax.all._
import cats.data.OptionT
import cats.effect.IO

trait ModelSyntax {

  implicit def userSyntax(u: User): ModelSyntax.UserSyntax                         = new ModelSyntax.UserSyntax(u)
  implicit def userModelRawSyntax(u: Model[User]): ModelSyntax.UserSyntax          = new ModelSyntax.UserSyntax(u)
  implicit def userObjSyntax(u: User.type): ModelSyntax.UserObjSyntax              = new ModelSyntax.UserObjSyntax(u)
  implicit def sessionSyntax(s: Session): ModelSyntax.SessionSyntax                = new ModelSyntax.SessionSyntax(s)
  implicit def sessionModelRawSyntax(s: Model[Session]): ModelSyntax.SessionSyntax = new ModelSyntax.SessionSyntax(s)
  implicit def pageSyntax(p: Page): ModelSyntax.PageSyntax                         = new ModelSyntax.PageSyntax(p)
  implicit def pageModelRawSyntax(p: Model[Page]): ModelSyntax.PageSyntax          = new ModelSyntax.PageSyntax(p)
  implicit def pageObjSyntax(p: Page.type): ModelSyntax.PageObjSyntax              = new ModelSyntax.PageObjSyntax(p)
  implicit def projectModelSyntax(p: Model[Project]): ModelSyntax.ProjectModelSyntax =
    new ModelSyntax.ProjectModelSyntax(p)
  implicit def orgSyntax(o: Organization): ModelSyntax.OrganizationSyntax = new ModelSyntax.OrganizationSyntax(o)
  implicit def orgModelRawSyntax(o: Model[Organization]): ModelSyntax.OrganizationSyntax =
    new ModelSyntax.OrganizationSyntax(o)
}
object ModelSyntax extends ModelSyntax {

  class UserSyntax(private val u: User) extends AnyVal {

    def avatarUrl(implicit config: OreConfig): String = User.avatarUrl(u.name)

    /**
      * Returns this user's current language, or the default language if none
      * was configured.
      */
    implicit def langOrDefault: Lang = u.lang.fold(Lang.defaultLang)(Lang.apply)
  }

  class UserObjSyntax(private val u: User.type) extends AnyVal {

    def avatarUrl(name: String)(implicit config: OreConfig): String =
      if (name == "Spongie") config.sponge.logo
      else config.security.api.avatarUrl.format(name)
  }

  class SessionSyntax(private val s: Session) extends AnyVal {

    /**
      * Returns the [[User]] that this Session belongs to.
      *
      * @param users UserBase instance
{'fraction_non_alphanumeric': 0.0911066835718167, 'fraction_numerical': 0.001267886252490491, 'mean_word_length': 4.146318732525629, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5443328', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1564, 'n_words': 388}