ios: group welcome message byte limit (#3751)
* ios: group welcome message character limit * confirmation dialogue key * use chatJsonLength * text * change footer --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
This commit is contained in:
parent
f102f39147
commit
78a38cb080
@ -18,6 +18,8 @@ struct GroupWelcomeView: View {
|
||||
@FocusState private var keyboardVisible: Bool
|
||||
@State private var showSaveDialog = false
|
||||
|
||||
let maxByteCount = 1200
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if groupInfo.canEdit {
|
||||
@ -29,9 +31,12 @@ struct GroupWelcomeView: View {
|
||||
showSaveDialog = true
|
||||
}
|
||||
})
|
||||
.confirmationDialog("Save welcome message?", isPresented: $showSaveDialog) {
|
||||
Button("Save and update group profile") {
|
||||
save()
|
||||
.confirmationDialog(
|
||||
welcomeTextFitsLimit() ? "Save welcome message?" : "Welcome message is too long",
|
||||
isPresented: $showSaveDialog
|
||||
) {
|
||||
if welcomeTextFitsLimit() {
|
||||
Button("Save and update group profile") { save() }
|
||||
}
|
||||
Button("Exit without saving") { dismiss() }
|
||||
}
|
||||
@ -53,7 +58,7 @@ struct GroupWelcomeView: View {
|
||||
|
||||
private func textPreview() -> some View {
|
||||
messageText(welcomeText, parseSimpleXMarkdown(welcomeText), nil, showSecrets: false)
|
||||
.frame(minHeight: 140, alignment: .topLeading)
|
||||
.frame(minHeight: 130, alignment: .topLeading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
@ -73,7 +78,7 @@ struct GroupWelcomeView: View {
|
||||
}
|
||||
.padding(.horizontal, -5)
|
||||
.padding(.top, -8)
|
||||
.frame(height: 140, alignment: .topLeading)
|
||||
.frame(height: 130, alignment: .topLeading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
} else {
|
||||
@ -92,6 +97,9 @@ struct GroupWelcomeView: View {
|
||||
}
|
||||
.disabled(welcomeText.isEmpty)
|
||||
copyButton()
|
||||
} footer: {
|
||||
Text(!welcomeTextFitsLimit() ? "Message too large" : "")
|
||||
.foregroundColor(.red)
|
||||
}
|
||||
|
||||
Section {
|
||||
@ -112,13 +120,17 @@ struct GroupWelcomeView: View {
|
||||
Button("Save and update group profile") {
|
||||
save()
|
||||
}
|
||||
.disabled(welcomeTextUnchanged())
|
||||
.disabled(welcomeTextUnchanged() || !welcomeTextFitsLimit())
|
||||
}
|
||||
|
||||
private func welcomeTextUnchanged() -> Bool {
|
||||
welcomeText == groupInfo.groupProfile.description || (welcomeText == "" && groupInfo.groupProfile.description == nil)
|
||||
}
|
||||
|
||||
private func welcomeTextFitsLimit() -> Bool {
|
||||
chatJsonLength(welcomeText) <= maxByteCount
|
||||
}
|
||||
|
||||
private func save() {
|
||||
Task {
|
||||
do {
|
||||
|
@ -105,6 +105,11 @@ public func parseSimpleXMarkdown(_ s: String) -> [FormattedText]? {
|
||||
return nil
|
||||
}
|
||||
|
||||
public func chatJsonLength(_ s: String) -> Int {
|
||||
var c = s.cString(using: .utf8)!
|
||||
return Int(chat_json_length(&c))
|
||||
}
|
||||
|
||||
struct ParsedMarkdown: Decodable {
|
||||
var formattedText: [FormattedText]?
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ extern char *chat_parse_markdown(char *str);
|
||||
extern char *chat_parse_server(char *str);
|
||||
extern char *chat_password_hash(char *pwd, char *salt);
|
||||
extern char *chat_valid_name(char *name);
|
||||
extern int chat_json_length(char *str);
|
||||
extern char *chat_encrypt_media(chat_ctrl ctl, char *key, char *frame, int len);
|
||||
extern char *chat_decrypt_media(char *key, char *frame, int len);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user