From 08383bdcbcc153fcacfebbb208e191bd4e45f591 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 5 Jan 2023 15:16:14 +0800 Subject: [PATCH] chore: simplify truncateContent --- services/actions/notifier_helper.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 396f739297..c2a6d402c8 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -221,13 +221,9 @@ func notifyPackage(ctx context.Context, sender *user_model.User, pd *packages_mo } func truncateContent(content string, n int) string { - truncatedContent, truncatedRight := util.SplitStringAtByteN(content, n) - if truncatedRight != "" { - // in case the content is in a Latin family language, we remove the last broken word. - lastSpaceIdx := strings.LastIndex(truncatedContent, " ") - if lastSpaceIdx != -1 && (len(truncatedContent)-lastSpaceIdx < 15) { - truncatedContent = truncatedContent[:lastSpaceIdx] + "…" - } + truncated, omitted := util.SplitStringAtByteN(content, n) + if omitted != "" { + truncated += "…" } - return truncatedContent + return truncated }