<commit_before>// Copyright (c) 2012 <NAME> (born 1979)

package com.debiki.v0

import java.{util => ju}
import collection.{immutable => imm, mutable => mut}
import Prelude._
import Debate._
import FlagReason.FlagReason


// COULD rename all these ViAc/NiPo/whatever to SmartAction/Post/Whatever.
// COULD take an Action subclass type param, so it'd be possible to use e.g. a
// SmartPageAction[Rating].
/** A virtual Action, that is, an Action plus some utility methods that
 *  look up other stuff in the relevant Debate.
 */
class ViAc(val debate: Debate, val action: Action) {
  def id: String = action.id
  def ctime = action.ctime
  def login: Option[Login] = debate.login(action.loginId)
  def login_! : Login = login.getOrElse(runErr(
     "DwE6gG32", "No login with id "+ safed(action.loginId) +
     " for action "+ safed(id)))
  def identity: Option[Identity] = login.flatMap(l =>
                                    debate.identity(l.identityId))
  def identity_! : Identity = debate.identity_!(login_!.identityId)
  def user : Option[User] = identity.flatMap(i => debate.user(i.userId))
  def user_! : User = debate.user_!(identity_!.userId)
  def ip: Option[String] = action.newIp.orElse(login.map(_.ip))
  def ip_! : String = action.newIp.getOrElse(login_!.ip)
  def ipSaltHash: Option[String] = ip.map(saltAndHashIp(_))
  def ipSaltHash_! : String = saltAndHashIp(ip_!)
<commit_msg>Add `page` field and object SmartAction.<commit_after>// Copyright (c) 2012 <NAME> (born 1979)

package com.debiki.v0

import java.{util => ju}
import collection.{immutable => imm, mutable => mut}
import Prelude._
import Debate._
import FlagReason.FlagReason


object SmartAction {

  def apply(page: Debate, action: Action): ViAc = action match {
    case p: Post => new ViPo(page, p)
    case a: Action => new ViAc(page, a)
  }

}


// COULD rename all these ViAc/NiPo/whatever to SmartAction/Post/Whatever.
// COULD take an Action subclass type param, so it'd be possible to use e.g. a
// SmartPageAction[Rating].
/** A virtual Action, that is, an Action plus some utility methods that
 *  look up other stuff in the relevant Debate.
 */
class ViAc(val debate: Debate, val action: Action) {
  def page = debate // should rename `debate` to `page`
  def id: String = action.id
  def ctime = action.ctime
  def login: Option[Login] = debate.login(action.loginId)
  def login_! : Login = login.getOrElse(runErr(
     "DwE6gG32", "No login with id "+ safed(action.loginId) +
     " for action "+ safed(id)))
  def identity: Option[Identity] = login.flatMap(l =>
                                    debate.identity(l.identityId))
  def identity_! : Identity = debate.identity_!(login_!.identityId)
  def user : Option[User] = identity.flatMap(i => debate.user(i.userId))
  def user_! : User = debate.user_!(identity_!.userId)
  def ip: Option[String] = action.newIp.orElse(login.map(_.ip))
  def ip_! : String = action.newIp.getOrElse(login_!.ip)
  def ipSaltHash: Option[String] = ip.map(saltAndHashIp(_))
  def ipSaltHash_! : String = saltAndHashIp(ip_!)

{'fraction_non_alphanumeric': 0.12741565673108418, 'fraction_numerical': 0.007861120209629872, 'mean_word_length': 3.6984615384615385, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1558827', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1001, 'n_words': 297}