Skip to content
Snippets Groups Projects
Verified Commit b680a11d authored by Mikolai Gütschow's avatar Mikolai Gütschow
Browse files

truncate texts to maximum allowed length

parent 5dded26b
No related branches found
No related tags found
1 merge request!295Truncate texts to maximum allowed length
Pipeline #13385 passed
......@@ -53,6 +53,7 @@ import org.briarproject.briar.api.conversation.event.ConversationMessageReceived
import org.briarproject.briar.api.forum.ForumSharingManager
import org.briarproject.briar.api.identity.AuthorManager
import org.briarproject.briar.api.introduction.IntroductionManager
import org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH
import org.briarproject.briar.api.messaging.MessagingManager
import org.briarproject.briar.api.messaging.PrivateMessage
import org.briarproject.briar.api.messaging.PrivateMessageFactory
......@@ -68,6 +69,7 @@ import org.briarproject.briar.desktop.utils.KLoggerUtils.e
import org.briarproject.briar.desktop.utils.KLoggerUtils.i
import org.briarproject.briar.desktop.utils.KLoggerUtils.logDuration
import org.briarproject.briar.desktop.utils.KLoggerUtils.w
import org.briarproject.briar.desktop.utils.StringUtils.takeUtf8
import org.briarproject.briar.desktop.utils.addAfterLast
import org.briarproject.briar.desktop.utils.clearAndAddAll
import org.briarproject.briar.desktop.utils.replaceIf
......@@ -145,7 +147,7 @@ constructor(
}
fun setNewMessage(msg: String) {
_newMessage.value = msg
_newMessage.value = msg.takeUtf8(MAX_PRIVATE_MESSAGE_TEXT_LENGTH)
}
fun setNewMessageImage(image: ImageBitmap?) {
......
......@@ -49,6 +49,7 @@ import org.briarproject.briar.desktop.theme.divider
import org.briarproject.briar.desktop.theme.sendButton
import org.briarproject.briar.desktop.ui.HorizontalDivider
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
import org.briarproject.briar.desktop.utils.StringUtils.takeUtf8
@Composable
@OptIn(ExperimentalComposeUiApi::class)
......@@ -102,7 +103,7 @@ fun GroupInputComposable(
HorizontalDivider()
TextField(
value = postText.value,
onValueChange = { postText.value = it },
onValueChange = { postText.value = it.takeUtf8(MAX_FORUM_POST_TEXT_LENGTH) },
onEnter = onSendAction,
maxLines = 10,
textStyle = MaterialTheme.typography.body1,
......
......@@ -46,6 +46,7 @@ import org.briarproject.briar.desktop.contact.ContactsViewModel
import org.briarproject.briar.desktop.threading.BriarExecutors
import org.briarproject.briar.desktop.threading.UiExecutor
import org.briarproject.briar.desktop.utils.InternationalizationUtils
import org.briarproject.briar.desktop.utils.StringUtils.takeUtf8
import org.briarproject.briar.desktop.viewmodel.asState
import org.briarproject.briar.desktop.viewmodel.update
import javax.inject.Inject
......@@ -95,7 +96,10 @@ class ForumSharingViewModel @Inject constructor(
}.sortedWith(
// first all items that are SHAREABLE (false comes before true)
// second non-case-sensitive, alphabetical order on displayName
compareBy({ it.status != SHAREABLE }, { it.contactItem.displayName.lowercase(InternationalizationUtils.locale) })
compareBy(
{ it.status != SHAREABLE },
{ it.contactItem.displayName.lowercase(InternationalizationUtils.locale) }
)
)
}
......@@ -135,7 +139,7 @@ class ForumSharingViewModel @Inject constructor(
@UiExecutor
fun setSharingMessage(message: String) {
_sharingMessage.value = message.take(MAX_INVITATION_TEXT_LENGTH)
_sharingMessage.value = message.takeUtf8(MAX_INVITATION_TEXT_LENGTH)
}
@UiExecutor
......
......@@ -33,6 +33,7 @@ import org.briarproject.briar.api.introduction.IntroductionManager
import org.briarproject.briar.desktop.contact.ContactItem
import org.briarproject.briar.desktop.contact.ContactsViewModel
import org.briarproject.briar.desktop.threading.BriarExecutors
import org.briarproject.briar.desktop.utils.StringUtils.takeUtf8
import org.briarproject.briar.desktop.viewmodel.asState
import javax.inject.Inject
......@@ -93,7 +94,7 @@ constructor(
}
fun setIntroductionMessage(msg: String) {
_introductionMessage.value = msg.take(MAX_INTRODUCTION_TEXT_LENGTH)
_introductionMessage.value = msg.takeUtf8(MAX_INTRODUCTION_TEXT_LENGTH)
}
fun makeIntroduction() {
......
/*
* Briar Desktop
* Copyright (C) 2021-2022 The Briar Project
  • Maintainer

    I think we need to update our template for 2023

  • Author Maintainer

    What was our take on this? Update all source files or only the new/changed ones?

  • Maintainer

    I was hoping IntelliJ automtically updates the header on changes files once we update the template

  • Author Maintainer

    Just tested, it uses the template for new files, but doesn't update it when changing existing files.

  • Maintainer

    well, maybe just update the template and the current new file here and we take care about the rest later. new files will be good then already and with the other ones, we can think about it again.

  • Author Maintainer
  • Maintainer

    I think it doesn't work with our files because we use an uppercase C instead of the lowercase c in the parantheses.

  • Author Maintainer

    we can adapt that, I'm on it

  • Author Maintainer
  • Maintainer

    oh, nice, IntelliJ finally has save actions. now I no longer need a plugin.

  • Author Maintainer

    I've changed the copyright template now accordingly in a new commit. I didn't find a way of storing the save actions in git, let's perhaps discuss this after the release.

  • Maintainer

    OK, cool. I enabled them manually and can confirm that the year updates on save.

  • Maintainer

    This is stored in .idea/workspace.xml which we ignore. I've got something like this there:

     85   <component name="PropertiesComponent"><![CDATA[{
     86   "keyToString": {
     87     "SHARE_PROJECT_CONFIGURATION_FILES": "true",
     88     "last_opened_file_path": …,
     89     "run.code.analysis.last.selected.profile": "pi18n",
     90     "settings.editor.selected.configurable": "actions.on.save",
     91     "update.copyright.on.save": "true"
     92   }
  • Author Maintainer

    I've got something similar for PropertiesComponent, but there's a lot of other info in that file which we probably really don't want to have in our git. So perhaps write somewhere down that this should be activated manually, perhaps in HACKING.md? Btw @grote this is what we were talking about during the last meeting, it can be enabled in File > Settings > Tools > Actions on Save > Update Copyright notice. Also "Optimize Code" and "Reformat imports" are useful options here. Perhaps you could check if those are available in Android Studio as well and report here.

  • They are available in Electric Eel and luckily they seem to be per project settings which is good.

  • Please register or sign in to reply
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.briarproject.briar.desktop.utils
import org.briarproject.bramble.util.StringUtils
object StringUtils {
fun String.takeUtf8(maxUtf8Length: Int): String =
StringUtils.truncateUtf8(this, maxUtf8Length)
}
  • Maintainer

    Tested the input cap and I think it works flawless now with all the reported problems.

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment