Skip to content

Commit

Permalink
Don't add metadata if text length exceeds 140 after encoding and don'…
Browse files Browse the repository at this point in the history
…t include metadata to calculate isShouting
  • Loading branch information
Carbrex committed Jul 7, 2024
1 parent accf84c commit 9ff3d6e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
26 changes: 18 additions & 8 deletions modules/common/src/main/String.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,28 @@ object String:
try play.utils.UriEncoding.decodePath(input, "UTF-8").some
catch case _: play.utils.InvalidUriEncodingException => None

def isShouting(text: String) =
def isShouting(text: String): Boolean =
text.lengthIs >= 5 && {
import java.lang.Character.*
// true if >1/2 of the latin letters are uppercase
text.take(80).replace("O-O", "o-o").foldLeft(0) { (i, c) =>
getType(c) match
case UPPERCASE_LETTER => i + 1
case LOWERCASE_LETTER => i - 1
case _ => i
} > 0
if text.contains('\ue666') then
val (before, after) = text.span(_ != '\ue666')
isShouting(before)
else
text.take(80).replace("O-O", "o-o").foldLeft(0) { (i, c) =>
getType(c) match
case UPPERCASE_LETTER => i + 1
case LOWERCASE_LETTER => i - 1
case _ => i
} > 0
}
def noShouting(str: String): String = if isShouting(str) then str.toLowerCase else str
def noShouting(str: String): String = if isShouting(str) then
// '\ue666' is a special character used to encode broadcast chat messages. See file://./../../../../ui/analyse/src/study/relay/chatHandler.ts
if str.contains('\ue666') then
val (before, after) = str.span(_ != '\ue666')
before.toLowerCase + after
else str.toLowerCase
else str

val atUsernameRegex = RawHtml.atUsernameRegex
val forumPostPathRegex = """(?:(?<= )|^)\b([\w-]+/[\w-]+)\b(?:(?= )|$)""".r
Expand Down
2 changes: 1 addition & 1 deletion ui/@types/lichess/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface Site {
clockWidget(el: HTMLElement, opts: { time: number; pause?: boolean }): void;
spinnerHtml: string;
asset: {
// file://./../../site/src/assets.ts
// file://./../../site/src/asset.ts
baseUrl(): string;
url(url: string, opts?: AssetUrlOpts): string;
flairSrc(flair: Flair): string;
Expand Down
5 changes: 4 additions & 1 deletion ui/analyse/src/study/relay/chatHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export function broadcastChatHandler(ctrl: AnalyseCtrl): BroadcastChatHandler {
if (ctrl.study?.relay && !ctrl.study.relay.tourShow()) {
const chapterId = ctrl.study.currentChapter().id;
const ply = ctrl.study.currentNode().ply;
text = text + separator + chapterId + separator + ply;
const newText = text + separator + chapterId + separator + ply;
if (newText.length <= 140) {
text = newText;
}
}
return text;
};
Expand Down

0 comments on commit 9ff3d6e

Please sign in to comment.