aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-02-14 03:05:59 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-02-14 03:05:59 +0300
commit915c40f1eed6ba139323c0fa15eed4ed3792f34b (patch)
treeb7e67604ea0451e2cc19f532a2c0954614eabd52
parent6cbfed824520e742532db502147d9c6bc524cc84 (diff)
Add an asciiarrows option (for clients that do not support Unicode ones)v1.1.2
-rw-r--r--persistence/sessions.go11
-rw-r--r--persistence/sessions_test.go1
-rw-r--r--telegram/utils.go14
-rw-r--r--telegram/utils_test.go12
4 files changed, 29 insertions, 9 deletions
diff --git a/persistence/sessions.go b/persistence/sessions.go
index cfea675..bc71fd6 100644
--- a/persistence/sessions.go
+++ b/persistence/sessions.go
@@ -38,12 +38,14 @@ type Session struct {
Timezone string `yaml:":timezone"`
KeepOnline bool `yaml:":keeponline"`
RawMessages bool `yaml:":rawmessages"`
+ AsciiArrows bool `yaml:":asciiarrows"`
}
var configKeys = []string{
"timezone",
"keeponline",
"rawmessages",
+ "asciiarrows",
}
var sessionDB *SessionsYamlDB
@@ -114,6 +116,8 @@ func (s *Session) Get(key string) (string, error) {
return fromBool(s.KeepOnline), nil
case "rawmessages":
return fromBool(s.RawMessages), nil
+ case "asciiarrows":
+ return fromBool(s.AsciiArrows), nil
}
return "", errors.New("Unknown session property")
@@ -150,6 +154,13 @@ func (s *Session) Set(key string, value string) (string, error) {
}
s.RawMessages = b
return value, nil
+ case "asciiarrows":
+ b, err := toBool(value)
+ if err != nil {
+ return "", err
+ }
+ s.AsciiArrows = b
+ return value, nil
}
return "", errors.New("Unknown session property")
diff --git a/persistence/sessions_test.go b/persistence/sessions_test.go
index aa1f4b8..76f71f9 100644
--- a/persistence/sessions_test.go
+++ b/persistence/sessions_test.go
@@ -53,6 +53,7 @@ func TestSessionToMap(t *testing.T) {
"timezone": "klsf",
"keeponline": "false",
"rawmessages": "true",
+ "asciiarrows": "false",
}
if !reflect.DeepEqual(m, sample) {
t.Errorf("Map does not match the sample: %v", m)
diff --git a/telegram/utils.go b/telegram/utils.go
index 086b7ae..7e93e57 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -617,10 +617,18 @@ func (c *Client) messageToPrefix(message *client.Message, fileString string) str
prefix := []string{}
// message direction
var directionChar string
- if message.IsOutgoing {
- directionChar = "➡ "
+ if c.Session.AsciiArrows {
+ if message.IsOutgoing {
+ directionChar = "> "
+ } else {
+ directionChar = "< "
+ }
} else {
- directionChar = "⬅ "
+ if message.IsOutgoing {
+ directionChar = "➡ "
+ } else {
+ directionChar = "⬅ "
+ }
}
prefix = append(prefix, directionChar+strconv.FormatInt(message.Id, 10))
// show sender in group chats
diff --git a/telegram/utils_test.go b/telegram/utils_test.go
index c168757..a435ea9 100644
--- a/telegram/utils_test.go
+++ b/telegram/utils_test.go
@@ -497,7 +497,7 @@ func TestMessageToPrefix1(t *testing.T) {
},
},
}
- prefix := (&Client{}).messageToPrefix(&message, "")
+ prefix := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "")
if prefix != "➡ 42 | fwd: ziz" {
t.Errorf("Wrong prefix: %v", prefix)
}
@@ -512,7 +512,7 @@ func TestMessageToPrefix2(t *testing.T) {
},
},
}
- prefix := (&Client{}).messageToPrefix(&message, "")
+ prefix := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "")
if prefix != "⬅ 56 | fwd: (zaz)" {
t.Errorf("Wrong prefix: %v", prefix)
}
@@ -525,8 +525,8 @@ func TestMessageToPrefix3(t *testing.T) {
Origin: &client.MessageForwardOriginChannel{},
},
}
- prefix := (&Client{}).messageToPrefix(&message, "a.jpg")
- if prefix != "⬅ 56 | fwd: | file: a.jpg" {
+ prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "a.jpg")
+ if prefix != "< 56 | fwd: | file: a.jpg" {
t.Errorf("Wrong prefix: %v", prefix)
}
}
@@ -536,8 +536,8 @@ func TestMessageToPrefix4(t *testing.T) {
Id: 23,
IsOutgoing: true,
}
- prefix := (&Client{}).messageToPrefix(&message, "")
- if prefix != "➡ 23" {
+ prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "")
+ if prefix != "> 23" {
t.Errorf("Wrong prefix: %v", prefix)
}
}