Support nativeedits for rawmessages=false
This commit is contained in:
parent
2459b14948
commit
a3f6d5f774
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
COMMIT := $(shell git rev-parse --short HEAD)
|
COMMIT := $(shell git rev-parse --short HEAD)
|
||||||
TD_COMMIT := "5bbfc1cf5dab94f82e02f3430ded7241d4653551"
|
TD_COMMIT := "5bbfc1cf5dab94f82e02f3430ded7241d4653551"
|
||||||
VERSION := "v1.9.2"
|
VERSION := "v1.9.3"
|
||||||
MAKEOPTS := "-j4"
|
MAKEOPTS := "-j4"
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
goxmpp "gosrc.io/xmpp"
|
goxmpp "gosrc.io/xmpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string = "1.9.2"
|
var version string = "1.9.3"
|
||||||
var commit string
|
var commit string
|
||||||
|
|
||||||
var sm *goxmpp.StreamManager
|
var sm *goxmpp.StreamManager
|
||||||
|
|
|
@ -384,16 +384,6 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string
|
||||||
if gateway.MessageOutgoingPermissionVersion == 0 && args[0] == "carbons" && args[1] == "true" {
|
if gateway.MessageOutgoingPermissionVersion == 0 && args[0] == "carbons" && args[1] == "true" {
|
||||||
return "The server did not allow to enable carbons"
|
return "The server did not allow to enable carbons"
|
||||||
}
|
}
|
||||||
if !c.Session.RawMessages && args[0] == "nativeedits" && args[1] == "true" {
|
|
||||||
return "nativeedits only works with rawmessages as of yet, enable it first"
|
|
||||||
}
|
|
||||||
if c.Session.NativeEdits && args[0] == "rawmessages" && args[1] == "false" {
|
|
||||||
_, err := c.Session.Set("nativeedits", "false")
|
|
||||||
if err != nil {
|
|
||||||
return err.Error()
|
|
||||||
}
|
|
||||||
msg = "Automatically disabling nativeedits too...\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
value, err := c.Session.Set(args[0], args[1])
|
value, err := c.Session.Set(args[0], args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -309,34 +309,43 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message, err := c.client.GetMessage(&client.GetMessageRequest{
|
message, messageErr := c.client.GetMessage(&client.GetMessageRequest{
|
||||||
ChatId: update.ChatId,
|
ChatId: update.ChatId,
|
||||||
MessageId: update.MessageId,
|
MessageId: update.MessageId,
|
||||||
})
|
})
|
||||||
if err == nil {
|
var prefix string
|
||||||
|
if messageErr == nil {
|
||||||
isCarbon = c.isCarbonsEnabled() && message.IsOutgoing
|
isCarbon = c.isCarbonsEnabled() && message.IsOutgoing
|
||||||
|
// reply correction support in clients is suboptimal yet, so cut them out for now
|
||||||
|
prefix, _ = c.messageToPrefix(message, "", "", true)
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("No message %v/%v found, cannot reliably determine if it's a carbon", update.ChatId, update.MessageId)
|
log.Errorf("No message %v/%v found, cannot reliably determine if it's a carbon", update.ChatId, update.MessageId)
|
||||||
}
|
}
|
||||||
|
|
||||||
text := formatter.Format(
|
var text strings.Builder
|
||||||
textContent.Text.Text,
|
|
||||||
textContent.Text.Entities,
|
|
||||||
markupFunction,
|
|
||||||
)
|
|
||||||
|
|
||||||
if replaceId == "" {
|
if replaceId == "" {
|
||||||
var editChar string
|
var editChar string
|
||||||
if c.Session.AsciiArrows {
|
if c.Session.AsciiArrows {
|
||||||
editChar = "e "
|
editChar = "e"
|
||||||
} else {
|
} else {
|
||||||
editChar = "✎ "
|
editChar = "✎"
|
||||||
}
|
}
|
||||||
text = editChar + fmt.Sprintf("%v | %s", update.MessageId, text)
|
text.WriteString(fmt.Sprintf("%s %v | ", editChar, update.MessageId))
|
||||||
|
} else if prefix != "" {
|
||||||
|
text.WriteString(prefix)
|
||||||
|
text.WriteString(c.getPrefixSeparator(update.ChatId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
text.WriteString(formatter.Format(
|
||||||
|
textContent.Text.Text,
|
||||||
|
textContent.Text.Entities,
|
||||||
|
markupFunction,
|
||||||
|
))
|
||||||
|
|
||||||
|
sChatId := strconv.FormatInt(update.ChatId, 10)
|
||||||
for _, jid := range jids {
|
for _, jid := range jids {
|
||||||
gateway.SendMessage(jid, strconv.FormatInt(update.ChatId, 10), text, "e"+sId, c.xmpp, nil, replaceId, isCarbon, false)
|
gateway.SendMessage(jid, sChatId, text.String(), "e"+sId, c.xmpp, nil, replaceId, isCarbon, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -915,7 +915,7 @@ func (c *Client) isCarbonsEnabled() bool {
|
||||||
return gateway.MessageOutgoingPermissionVersion > 0 && c.Session.Carbons
|
return gateway.MessageOutgoingPermissionVersion > 0 && c.Session.Carbons
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) messageToPrefix(message *client.Message, previewString string, fileString string) (string, *gateway.Reply) {
|
func (c *Client) messageToPrefix(message *client.Message, previewString string, fileString string, suppressReply bool) (string, *gateway.Reply) {
|
||||||
isPM, err := c.IsPM(message.ChatId)
|
isPM, err := c.IsPM(message.ChatId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Could not determine if chat is PM: %v", err)
|
log.Errorf("Could not determine if chat is PM: %v", err)
|
||||||
|
@ -953,10 +953,14 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// reply to
|
// reply to
|
||||||
|
var reply *gateway.Reply
|
||||||
|
if !suppressReply {
|
||||||
preview := true
|
preview := true
|
||||||
reply, tgReply := c.getMessageReply(message, preview, false)
|
gwReply, tgReply := c.getMessageReply(message, preview, false)
|
||||||
|
|
||||||
if tgReply != nil {
|
if tgReply != nil {
|
||||||
|
reply = gwReply
|
||||||
|
|
||||||
var replyStart, replyEnd int
|
var replyStart, replyEnd int
|
||||||
|
|
||||||
if len(prefix) > 0 {
|
if len(prefix) > 0 {
|
||||||
|
@ -976,6 +980,7 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string,
|
||||||
reply.End = uint64(replyEnd)
|
reply.End = uint64(replyEnd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if message.ForwardInfo != nil {
|
if message.ForwardInfo != nil {
|
||||||
prefix = append(prefix, "fwd: "+c.formatOrigin(message.ForwardInfo.Origin))
|
prefix = append(prefix, "fwd: "+c.formatOrigin(message.ForwardInfo.Origin))
|
||||||
|
@ -1008,6 +1013,17 @@ func (c *Client) ensureDownloadFile(file *client.File) *client.File {
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// \n if it is groupchat and message is not empty
|
||||||
|
func (c *Client) getPrefixSeparator(chatId int64) string {
|
||||||
|
var separator string
|
||||||
|
if chatId < 0 {
|
||||||
|
separator = "\n"
|
||||||
|
} else if chatId > 0 {
|
||||||
|
separator = " | "
|
||||||
|
}
|
||||||
|
return separator
|
||||||
|
}
|
||||||
|
|
||||||
// ProcessIncomingMessage transfers a message to XMPP side and marks it as read on Telegram side
|
// ProcessIncomingMessage transfers a message to XMPP side and marks it as read on Telegram side
|
||||||
func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
|
func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
|
||||||
isCarbon := c.isCarbonsEnabled() && message.IsOutgoing
|
isCarbon := c.isCarbonsEnabled() && message.IsOutgoing
|
||||||
|
@ -1051,21 +1067,15 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
|
||||||
} else if !c.Session.RawMessages {
|
} else if !c.Session.RawMessages {
|
||||||
var newText strings.Builder
|
var newText strings.Builder
|
||||||
|
|
||||||
prefix, prefixReply := c.messageToPrefix(message, previewName, fileName)
|
prefix, prefixReply := c.messageToPrefix(message, previewName, fileName, false)
|
||||||
reply = prefixReply
|
reply = prefixReply
|
||||||
replyObtained = true
|
replyObtained = true
|
||||||
newText.WriteString(prefix)
|
newText.WriteString(prefix)
|
||||||
|
|
||||||
if text != "" {
|
if text != "" {
|
||||||
// \n if it is groupchat and message is not empty
|
|
||||||
if prefix != "" {
|
if prefix != "" {
|
||||||
if chatId < 0 {
|
newText.WriteString(c.getPrefixSeparator(chatId))
|
||||||
newText.WriteString("\n")
|
|
||||||
} else if chatId > 0 {
|
|
||||||
newText.WriteString(" | ")
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
newText.WriteString(text)
|
newText.WriteString(text)
|
||||||
}
|
}
|
||||||
text = newText.String()
|
text = newText.String()
|
||||||
|
|
|
@ -436,7 +436,7 @@ func TestMessageToPrefix1(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
prefix, gatewayReply := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "", "")
|
prefix, gatewayReply := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "", "", false)
|
||||||
if prefix != "➡ 42 | fwd: ziz" {
|
if prefix != "➡ 42 | fwd: ziz" {
|
||||||
t.Errorf("Wrong prefix: %v", prefix)
|
t.Errorf("Wrong prefix: %v", prefix)
|
||||||
}
|
}
|
||||||
|
@ -454,7 +454,7 @@ func TestMessageToPrefix2(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
prefix, gatewayReply := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "y.jpg", "")
|
prefix, gatewayReply := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "y.jpg", "", false)
|
||||||
if prefix != "⬅ 56 | fwd: (zaz) | preview: y.jpg" {
|
if prefix != "⬅ 56 | fwd: (zaz) | preview: y.jpg" {
|
||||||
t.Errorf("Wrong prefix: %v", prefix)
|
t.Errorf("Wrong prefix: %v", prefix)
|
||||||
}
|
}
|
||||||
|
@ -472,7 +472,7 @@ func TestMessageToPrefix3(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "a.jpg")
|
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "a.jpg", false)
|
||||||
if prefix != "< 56 | fwd: (zuz) | file: a.jpg" {
|
if prefix != "< 56 | fwd: (zuz) | file: a.jpg" {
|
||||||
t.Errorf("Wrong prefix: %v", prefix)
|
t.Errorf("Wrong prefix: %v", prefix)
|
||||||
}
|
}
|
||||||
|
@ -486,7 +486,7 @@ func TestMessageToPrefix4(t *testing.T) {
|
||||||
Id: 23,
|
Id: 23,
|
||||||
IsOutgoing: true,
|
IsOutgoing: true,
|
||||||
}
|
}
|
||||||
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "")
|
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "", false)
|
||||||
if prefix != "> 23" {
|
if prefix != "> 23" {
|
||||||
t.Errorf("Wrong prefix: %v", prefix)
|
t.Errorf("Wrong prefix: %v", prefix)
|
||||||
}
|
}
|
||||||
|
@ -504,7 +504,7 @@ func TestMessageToPrefix5(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "h.jpg", "a.jpg")
|
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "h.jpg", "a.jpg", false)
|
||||||
if prefix != "< 560 | fwd: (zyz) | preview: h.jpg | file: a.jpg" {
|
if prefix != "< 560 | fwd: (zyz) | preview: h.jpg | file: a.jpg" {
|
||||||
t.Errorf("Wrong prefix: %v", prefix)
|
t.Errorf("Wrong prefix: %v", prefix)
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ func TestMessageToPrefix6(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "")
|
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "", false)
|
||||||
if prefix != "> 23 | reply: ziz @ unknown contact: TDlib instance is offline | tist uz iz" {
|
if prefix != "> 23 | reply: ziz @ unknown contact: TDlib instance is offline | tist uz iz" {
|
||||||
t.Errorf("Wrong prefix: %v", prefix)
|
t.Errorf("Wrong prefix: %v", prefix)
|
||||||
}
|
}
|
||||||
|
@ -556,7 +556,7 @@ func TestMessageToPrefix7(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "")
|
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "", false)
|
||||||
if prefix != "> 23 | reply: (zaz) @ unknown contact: TDlib instance is offline | tist" {
|
if prefix != "> 23 | reply: (zaz) @ unknown contact: TDlib instance is offline | tist" {
|
||||||
t.Errorf("Wrong prefix: %v", prefix)
|
t.Errorf("Wrong prefix: %v", prefix)
|
||||||
}
|
}
|
||||||
|
@ -565,6 +565,32 @@ func TestMessageToPrefix7(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMessageToPrefix8(t *testing.T) {
|
||||||
|
message := client.Message{
|
||||||
|
Id: 23,
|
||||||
|
ChatId: 42,
|
||||||
|
IsOutgoing: true,
|
||||||
|
ReplyTo: &client.MessageReplyToMessage{
|
||||||
|
ChatId: 41,
|
||||||
|
Content: &client.MessageText{
|
||||||
|
Text: &client.FormattedText{
|
||||||
|
Text: "tist",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Origin: &client.MessageOriginChannel{
|
||||||
|
AuthorSignature: "zuz",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
prefix, gatewayReply := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "", true)
|
||||||
|
if prefix != "> 23" {
|
||||||
|
t.Errorf("Wrong prefix: %v", prefix)
|
||||||
|
}
|
||||||
|
if gatewayReply != nil {
|
||||||
|
t.Errorf("Reply is not nil: %v", gatewayReply)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetSenderIdEmpty(t *testing.T) {
|
func GetSenderIdEmpty(t *testing.T) {
|
||||||
message := client.Message{}
|
message := client.Message{}
|
||||||
senderId := (&Client{}).getSenderId(&message)
|
senderId := (&Client{}).getSenderId(&message)
|
||||||
|
|
Loading…
Reference in a new issue