@@ -939,20 +939,6 @@ package object core {
939939 }
940940
941941
942- /*
943- sealed abstract class AnonLevel(val IntVal: i32) { def toInt: i32 = IntVal }
944- object AnonLevel {
945- case object NotAnon extends AnonLevel(10)
946- case object AnonymPerPage extends AnonLevel(50)
947-
948- def fromInt(value: i32): Opt[AnonLevel] = Some(value match {
949- case NotAnon.IntVal => NotAnon
950- case AnonymPerPage.IntVal => AnonymPerPage
951- case _ => return None
952- })
953- }*/
954-
955-
956942
957943 /** A bitfield. Currently only None, 65535 = IsAnonOnlySelfCanDeanon
958944 * and 2097151 = IsAnonCanAutoDeanon are supported.
@@ -1080,27 +1066,92 @@ package object core {
10801066 }
10811067
10821068
1083- sealed abstract class WhichAnon () {
1084- require(anySameAnonId.isDefined != anyNewAnonStatus.isDefined, " TyE6G0FM2TF3" )
1069+ /** For before an alias has been looked up — we know only its id. Or,
1070+ * if it's a lazy-created anon, we don't know its id (doesn't yet exist),
1071+ * instead, we only know what type of anon it's going to be, that is, its
1072+ * future anon status (currently, either temporarily anonymous,
1073+ * for ideation, or permanently, for sensitive discussions).
1074+ */
1075+ sealed abstract class WhichAliasId () {
1076+ // Remove later. [chk_alias_status]
1077+ require(anySameAliasId.isEmpty || anyAnonStatus.isEmpty, " TyE6G0FM2TF3" )
1078+
1079+ def anyAnonStatus : Opt [AnonStatus ]
1080+ def anySameAliasId : Opt [AnonId ]
1081+ }
1082+
1083+
1084+ object WhichAliasId {
1085+
1086+ /** For doing sth as oneself (even if anonymity is the default) — "Yourself Mode". */
1087+ case object Oneself extends WhichAliasId {
1088+ def anySameAliasId : Opt [AnonId ] = None
1089+ def anyAnonStatus : Opt [AnonStatus ] = None
1090+ }
1091+
1092+ // Later: [pseudonyms_later]
1093+ // case class SamePseudonym(sameAliasId: PatId) extends WhichAliasId with SameAlias {
1094+ // def anySameAliasId: Opt[PatId] = Some(sameAliasId)
1095+ // def anyAnonStatus: Opt[AnonStatus] = None
1096+ // }
1097+
1098+ COULD // add anonStatus, error if mismatch? [chk_alias_status]
1099+ case class SameAnon (sameAnonId : PatId ) extends WhichAliasId {
1100+ require(sameAnonId <= Pat .MaxAnonId , s " Not an anon id: $sameAnonId" )
1101+ def anySameAliasId : Opt [AnonId ] = Some (sameAnonId)
1102+ def anyAnonStatus : Opt [AnonStatus ] = None
1103+ }
1104+
1105+ case class LazyCreatedAnon (anonStatus : AnonStatus ) extends WhichAliasId {
1106+ require(anonStatus != AnonStatus .NotAnon , " WhichAliasId.anonStatus is NotAnon [TyE2M068G]" )
1107+ def anySameAliasId : Opt [AnonId ] = None
1108+ def anyAnonStatus : Opt [AnonStatus ] = Some (anonStatus)
1109+ }
1110+ }
1111+
10851112
1086- // Either ...
1087- def anyNewAnonStatus : Opt [AnonStatus ] = None
1088- // ... or.
1089- def anySameAnonId : Opt [AnonId ] = None
1113+ /** For after the alias has been looked up by any id, when we have an Anonym or Pseudonym,
1114+ * not just an id. (Or still just a to-be-lazy-created anonym, with a future anon status.)
1115+ */
1116+ sealed trait WhichAliasPat {
1117+ def anyPat : Opt [Pat ]
10901118 }
10911119
1092- object WhichAnon {
1093- case class NewAnon (anonStatus : AnonStatus ) extends WhichAnon {
1094- require(anonStatus != AnonStatus .NotAnon , " WhichAnon is NotAnon [TyE2MC06Y8G]" )
1095- override def anyNewAnonStatus : Opt [AnonStatus ] = Some (anonStatus)
1120+
1121+ object WhichAliasPat {
1122+ // Later: [pseudonyms_later]
1123+ // Create a Pseudonym class? Pat / PatBr has unnecessary stuff, e.g. sso id.
1124+ // case class SamePseudonym(pseudonym: Pseudonym) extends WhichAliasPat {
1125+ // def anyPat: Opt[Pat] = Some(pseudonym)
1126+ // }
1127+
1128+ case class SameAnon (anon : Anonym ) extends WhichAliasPat {
1129+ def anyPat : Opt [Pat ] = Some (anon)
10961130 }
10971131
1098- case class SameAsBefore (sameAnonId : PatId ) extends WhichAnon {
1099- override def anySameAnonId : Opt [AnonId ] = Some (sameAnonId)
1132+ /** Reuses any already existing anonym with the same anon status,
1133+ * on the same page.
1134+ *
1135+ * If there're many, on the relevant page, then what? Throw an error?
1136+ * Can't happen, yet, because [one_anon_per_page].
1137+ */
1138+ case class LazyCreatedAnon (anonStatus : AnonStatus ) extends WhichAliasPat {
1139+ def anyPat : Opt [Pat ] = None // might not yet exist
11001140 }
1141+
1142+ // Let's not support creating more than one anonym per user & page, for now.
1143+ // case class NewAnon(anonStatus: AnonStatus) extends WhichAliasPat {
1144+ // def anyPat: Opt[Pat] = None
1145+ // }
11011146 }
11021147
11031148
1149+ sealed abstract class AnyUserAndLevels {
1150+ def anyUser : Opt [Pat ]
1151+ def trustLevel : TrustLevel
1152+ def threatLevel : ThreatLevel
1153+ }
1154+
11041155 /**
11051156 * @param user, (RENAME to patOrPseudonym?) — the id of the requester, can be a pseudonym. But not an anonym.
11061157 * @param trustLevel — if patOrPseudonym is a pseudonym, then this is the pseudonym's
@@ -1111,13 +1162,17 @@ package object core {
11111162 user : Pat ,
11121163 trustLevel : TrustLevel ,
11131164 threatLevel : ThreatLevel ,
1114- ) {
1165+ ) extends AnyUserAndLevels {
1166+ def anyUser = Some (user)
11151167 def id : UserId = user.id
11161168 def isStaff : Boolean = user.isStaff
11171169 def nameHashId : String = user.nameHashId
11181170 }
11191171
1120- case class AnyUserAndThreatLevel (user : Option [Participant ], threatLevel : ThreatLevel )
1172+ case class StrangerAndThreatLevel (threatLevel : ThreatLevel ) extends AnyUserAndLevels {
1173+ def anyUser : Opt [Pat ] = None
1174+ def trustLevel : TrustLevel = TrustLevel .Stranger
1175+ }
11211176
11221177
11231178 sealed trait OrderBy { def isDescending : Boolean = false }
@@ -2057,6 +2112,7 @@ package object core {
20572112
20582113
20592114 implicit class RichBoolean (underlying : Boolean ) {
2115+ // (For find-by-similar-name: "oneIfTrue".)
20602116 def toZeroOne : i32 = if (underlying) 1 else 0
20612117 }
20622118
0 commit comments