Add an asciiarrows option (for clients that do not support Unicode ones)

This commit is contained in:
Bohdan Horbeshko 2022-02-13 19:05:59 -05:00
parent 6cbfed8245
commit 915c40f1ee
4 changed files with 29 additions and 9 deletions

View file

@ -38,12 +38,14 @@ type Session struct {
Timezone string `yaml:":timezone"` Timezone string `yaml:":timezone"`
KeepOnline bool `yaml:":keeponline"` KeepOnline bool `yaml:":keeponline"`
RawMessages bool `yaml:":rawmessages"` RawMessages bool `yaml:":rawmessages"`
AsciiArrows bool `yaml:":asciiarrows"`
} }
var configKeys = []string{ var configKeys = []string{
"timezone", "timezone",
"keeponline", "keeponline",
"rawmessages", "rawmessages",
"asciiarrows",
} }
var sessionDB *SessionsYamlDB var sessionDB *SessionsYamlDB
@ -114,6 +116,8 @@ func (s *Session) Get(key string) (string, error) {
return fromBool(s.KeepOnline), nil return fromBool(s.KeepOnline), nil
case "rawmessages": case "rawmessages":
return fromBool(s.RawMessages), nil return fromBool(s.RawMessages), nil
case "asciiarrows":
return fromBool(s.AsciiArrows), nil
} }
return "", errors.New("Unknown session property") return "", errors.New("Unknown session property")
@ -150,6 +154,13 @@ func (s *Session) Set(key string, value string) (string, error) {
} }
s.RawMessages = b s.RawMessages = b
return value, nil 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") return "", errors.New("Unknown session property")

View file

@ -53,6 +53,7 @@ func TestSessionToMap(t *testing.T) {
"timezone": "klsf", "timezone": "klsf",
"keeponline": "false", "keeponline": "false",
"rawmessages": "true", "rawmessages": "true",
"asciiarrows": "false",
} }
if !reflect.DeepEqual(m, sample) { if !reflect.DeepEqual(m, sample) {
t.Errorf("Map does not match the sample: %v", m) t.Errorf("Map does not match the sample: %v", m)

View file

@ -617,11 +617,19 @@ func (c *Client) messageToPrefix(message *client.Message, fileString string) str
prefix := []string{} prefix := []string{}
// message direction // message direction
var directionChar string var directionChar string
if c.Session.AsciiArrows {
if message.IsOutgoing {
directionChar = "> "
} else {
directionChar = "< "
}
} else {
if message.IsOutgoing { if message.IsOutgoing {
directionChar = "➡ " directionChar = "➡ "
} else { } else {
directionChar = "⬅ " directionChar = "⬅ "
} }
}
prefix = append(prefix, directionChar+strconv.FormatInt(message.Id, 10)) prefix = append(prefix, directionChar+strconv.FormatInt(message.Id, 10))
// show sender in group chats // show sender in group chats
if message.ChatId < 0 && message.SenderId != nil { if message.ChatId < 0 && message.SenderId != nil {

View file

@ -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" { if prefix != "➡ 42 | fwd: ziz" {
t.Errorf("Wrong prefix: %v", prefix) 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)" { if prefix != "⬅ 56 | fwd: (zaz)" {
t.Errorf("Wrong prefix: %v", prefix) t.Errorf("Wrong prefix: %v", prefix)
} }
@ -525,8 +525,8 @@ func TestMessageToPrefix3(t *testing.T) {
Origin: &client.MessageForwardOriginChannel{}, Origin: &client.MessageForwardOriginChannel{},
}, },
} }
prefix := (&Client{}).messageToPrefix(&message, "a.jpg") prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "a.jpg")
if prefix != " 56 | fwd: | file: a.jpg" { if prefix != "< 56 | fwd: | file: a.jpg" {
t.Errorf("Wrong prefix: %v", prefix) t.Errorf("Wrong prefix: %v", prefix)
} }
} }
@ -536,8 +536,8 @@ func TestMessageToPrefix4(t *testing.T) {
Id: 23, Id: 23,
IsOutgoing: true, IsOutgoing: true,
} }
prefix := (&Client{}).messageToPrefix(&message, "") prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "")
if prefix != " 23" { if prefix != "> 23" {
t.Errorf("Wrong prefix: %v", prefix) t.Errorf("Wrong prefix: %v", prefix)
} }
} }