Compare commits

...

1 commit

5 changed files with 38 additions and 17 deletions

View file

@ -200,6 +200,7 @@ func (c *Client) sendMessagesReverse(chatID int64, messages []*client.Message) {
c.xmpp, c.xmpp,
reply, reply,
false, false,
"",
) )
} }
} }

View file

@ -242,7 +242,7 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
textContent.Text.Entities, textContent.Text.Entities,
markupFunction, markupFunction,
)) ))
gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatId, 10), text, "e"+strconv.FormatInt(update.MessageId, 10), c.xmpp, nil, false) gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatId, 10), text, "e"+strconv.FormatInt(update.MessageId, 10), c.xmpp, nil, false, "")
} }
} }

View file

@ -891,13 +891,22 @@ func (c *Client) ensureDownloadFile(file *client.File) *client.File {
// 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) {
var text, oob, auxText string var text, oob, auxText, nick, contentType string
var err error var err error
reply, replyMsg := c.getMessageReply(message) reply, replyMsg := c.getMessageReply(message)
content := message.Content content := message.Content
if content != nil && content.MessageContentType() == client.TypeMessageChatChangePhoto { if content != nil {
contentType = content.MessageContentType()
}
if contentType == client.TypeMessageChatChangeTitle {
changeTitle, _ := content.(*client.MessageChatChangeTitle)
nick = changeTitle.Title
}
if contentType == client.TypeMessageChatChangePhoto {
chat, err := c.client.GetChat(&client.GetChatRequest{ chat, err := c.client.GetChat(&client.GetChatRequest{
ChatId: chatId, ChatId: chatId,
}) })
@ -983,9 +992,9 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
} }
for _, jid := range jids { for _, jid := range jids {
gateway.SendMessageWithOOB(jid, sChatId, text, sId, c.xmpp, reply, oob, isOutgoing) gateway.SendMessageWithOOB(jid, sChatId, text, sId, c.xmpp, reply, oob, isOutgoing, nick)
if auxText != "" { if auxText != "" {
gateway.SendMessage(jid, sChatId, auxText, sId, c.xmpp, reply, isOutgoing) gateway.SendMessage(jid, sChatId, auxText, sId, c.xmpp, reply, isOutgoing, nick)
} }
} }
} }

View file

@ -7,8 +7,8 @@ import (
"gosrc.io/xmpp/stanza" "gosrc.io/xmpp/stanza"
) )
// PresenceNickExtension is from XEP-0172 // NickExtension is from XEP-0172
type PresenceNickExtension struct { type NickExtension struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/nick nick"` XMLName xml.Name `xml:"http://jabber.org/protocol/nick nick"`
Text string `xml:",chardata"` Text string `xml:",chardata"`
} }
@ -187,7 +187,7 @@ type Replace struct {
} }
// Namespace is a namespace! // Namespace is a namespace!
func (c PresenceNickExtension) Namespace() string { func (c NickExtension) Namespace() string {
return c.XMLName.Space return c.XMLName.Space
} }
@ -259,7 +259,13 @@ func init() {
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{ stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
"http://jabber.org/protocol/nick", "http://jabber.org/protocol/nick",
"nick", "nick",
}, PresenceNickExtension{}) }, NickExtension{})
// message nick
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"http://jabber.org/protocol/nick",
"nick",
}, NickExtension{})
// presence vcard update // presence vcard update
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{ stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{

View file

@ -42,26 +42,26 @@ var DirtySessions = false
var MessageOutgoingPermission = false var MessageOutgoingPermission = false
// SendMessage creates and sends a message stanza // SendMessage creates and sends a message stanza
func SendMessage(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, isOutgoing bool) { func SendMessage(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, isOutgoing bool, nick string) {
sendMessageWrapper(to, from, body, id, component, reply, "", isOutgoing) sendMessageWrapper(to, from, body, id, component, reply, "", isOutgoing, nick)
} }
// SendServiceMessage creates and sends a simple message stanza from transport // SendServiceMessage creates and sends a simple message stanza from transport
func SendServiceMessage(to string, body string, component *xmpp.Component) { func SendServiceMessage(to string, body string, component *xmpp.Component) {
sendMessageWrapper(to, "", body, "", component, nil, "", false) sendMessageWrapper(to, "", body, "", component, nil, "", false, "")
} }
// SendTextMessage creates and sends a simple message stanza // SendTextMessage creates and sends a simple message stanza
func SendTextMessage(to string, from string, body string, component *xmpp.Component) { func SendTextMessage(to string, from string, body string, component *xmpp.Component) {
sendMessageWrapper(to, from, body, "", component, nil, "", false) sendMessageWrapper(to, from, body, "", component, nil, "", false, "")
} }
// SendMessageWithOOB creates and sends a message stanza with OOB URL // SendMessageWithOOB creates and sends a message stanza with OOB URL
func SendMessageWithOOB(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isOutgoing bool) { func SendMessageWithOOB(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isOutgoing bool, nick string) {
sendMessageWrapper(to, from, body, id, component, reply, oob, isOutgoing) sendMessageWrapper(to, from, body, id, component, reply, oob, isOutgoing, nick)
} }
func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isOutgoing bool) { func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isOutgoing bool, nick string) {
toJid, err := stanza.NewJid(to) toJid, err := stanza.NewJid(to)
if err != nil { if err != nil {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
@ -119,6 +119,11 @@ func sendMessageWrapper(to string, from string, body string, id string, componen
message.Extensions = append(message.Extensions, extensions.NewReplyFallback(reply.Start, reply.End)) message.Extensions = append(message.Extensions, extensions.NewReplyFallback(reply.Start, reply.End))
} }
} }
if nick != "" {
message.Extensions = append(message.Extensions, extensions.NickExtension{
Text: nick,
})
}
if isOutgoing { if isOutgoing {
carbonMessage := extensions.ClientMessage{ carbonMessage := extensions.ClientMessage{
@ -269,7 +274,7 @@ func newPresence(bareJid string, to string, args ...args.V) stanza.Presence {
if SPNickname.IsSet(args) { if SPNickname.IsSet(args) {
nickname := SPNickname.Get(args) nickname := SPNickname.Get(args)
if nickname != "" { if nickname != "" {
presence.Extensions = append(presence.Extensions, extensions.PresenceNickExtension{ presence.Extensions = append(presence.Extensions, extensions.NickExtension{
Text: nickname, Text: nickname,
}) })
} }