summaryrefslogtreecommitdiffstats
path: root/bridge/helper/helper.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-05-27 21:45:23 +0200
committerGitHub <noreply@github.com>2021-05-27 21:45:23 +0200
commitc86137449e733fc643337f33eaa33daf9e16d73c (patch)
tree711cbfd7f64edfbf1780285b0f177afc2b3c472b /bridge/helper/helper.go
parentefec01a92f3d7c3aec3ada8bf873d728e349eee6 (diff)
downloadmatterbridge-msglm-c86137449e733fc643337f33eaa33daf9e16d73c.tar.gz
matterbridge-msglm-c86137449e733fc643337f33eaa33daf9e16d73c.tar.bz2
matterbridge-msglm-c86137449e733fc643337f33eaa33daf9e16d73c.zip
Add a MessageClipped option to set your own clipped message. Closes #1359 (#1487)
Diffstat (limited to 'bridge/helper/helper.go')
-rw-r--r--bridge/helper/helper.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go
index 0ad31457..1bdd8a40 100644
--- a/bridge/helper/helper.go
+++ b/bridge/helper/helper.go
@@ -82,8 +82,10 @@ func DownloadFileAuthRocket(url, token, userID string) (*[]byte, error) {
// TODO: The current implementation has the inconvenient that it disregards
// word boundaries when splitting but this is hard to solve without potentially
// breaking formatting and other stylistic effects.
-func GetSubLines(message string, maxLineLength int) []string {
- const clippingMessage = " <clipped message>"
+func GetSubLines(message string, maxLineLength int, clippingMessage string) []string {
+ if clippingMessage == "" {
+ clippingMessage = " <clipped message>"
+ }
var lines []string
for _, line := range strings.Split(strings.TrimSpace(message), "\n") {
@@ -193,8 +195,11 @@ func RemoveEmptyNewLines(msg string) string {
// ClipMessage trims a message to the specified length if it exceeds it and adds a warning
// to the message in case it does so.
-func ClipMessage(text string, length int) string {
- const clippingMessage = " <clipped message>"
+func ClipMessage(text string, length int, clippingMessage string) string {
+ if clippingMessage == "" {
+ clippingMessage = " <clipped message>"
+ }
+
if len(text) > length {
text = text[:length-len(clippingMessage)]
if r, size := utf8.DecodeLastRuneInString(text); r == utf8.RuneError {