|
|
|
@ -890,9 +890,34 @@ func (c *Client) ensureDownloadFile(file *client.File) *client.File {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ProcessIncomingMessage transfers a message to XMPP side and marks it as read on Telegram side
|
|
|
|
|
func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
|
|
|
|
|
var text, oob, auxText string
|
|
|
|
|
func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message, ignoredResource string) {
|
|
|
|
|
var jids []string
|
|
|
|
|
var isPM bool
|
|
|
|
|
var err error
|
|
|
|
|
if gateway.MessageOutgoingPermission && c.Session.Carbons {
|
|
|
|
|
isPM, err = c.IsPM(chatId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorf("Could not determine if chat is PM: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
isOutgoing := message.IsOutgoing
|
|
|
|
|
isCarbon := isPM && isOutgoing
|
|
|
|
|
log.Warnf("isOutgoing: %v", isOutgoing)
|
|
|
|
|
if isOutgoing {
|
|
|
|
|
for resource := range c.resourcesRange() {
|
|
|
|
|
if ignoredResource == "" || resource != ignoredResource {
|
|
|
|
|
jids = append(jids, c.jid+"/"+resource)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(jids) == 0 {
|
|
|
|
|
log.Info("The only resource is ignored, aborting")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
jids = []string{c.jid}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var text, oob, auxText string
|
|
|
|
|
|
|
|
|
|
reply, replyMsg := c.getMessageReply(message)
|
|
|
|
|
|
|
|
|
@ -965,27 +990,10 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
|
|
|
|
|
sId := strconv.FormatInt(message.Id, 10)
|
|
|
|
|
sChatId := strconv.FormatInt(chatId, 10)
|
|
|
|
|
|
|
|
|
|
var jids []string
|
|
|
|
|
var isPM bool
|
|
|
|
|
if gateway.MessageOutgoingPermission && c.Session.Carbons {
|
|
|
|
|
isPM, err = c.IsPM(chatId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorf("Could not determine if chat is PM: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
isOutgoing := isPM && message.IsOutgoing
|
|
|
|
|
if isOutgoing {
|
|
|
|
|
for resource := range c.resourcesRange() {
|
|
|
|
|
jids = append(jids, c.jid+"/"+resource)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
jids = []string{c.jid}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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, isCarbon)
|
|
|
|
|
if auxText != "" {
|
|
|
|
|
gateway.SendMessage(jid, sChatId, auxText, sId, c.xmpp, reply, isOutgoing)
|
|
|
|
|
gateway.SendMessage(jid, sChatId, auxText, sId, c.xmpp, reply, isCarbon)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1172,9 +1180,12 @@ func (c *Client) resourcesRange() chan string {
|
|
|
|
|
|
|
|
|
|
// resend statuses to (to another resource, for example)
|
|
|
|
|
func (c *Client) roster(resource string) {
|
|
|
|
|
c.locks.resourcesLock.Lock()
|
|
|
|
|
if _, ok := c.resources[resource]; ok {
|
|
|
|
|
c.locks.resourcesLock.Unlock()
|
|
|
|
|
return // we know it
|
|
|
|
|
}
|
|
|
|
|
c.locks.resourcesLock.Unlock()
|
|
|
|
|
|
|
|
|
|
log.Warnf("Sending roster for %v", resource)
|
|
|
|
|
|
|
|
|
@ -1347,3 +1358,24 @@ func (c *Client) UpdateChatNicknames() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddToOutbox remembers the resource from which a message with given ID was sent
|
|
|
|
|
func (c *Client) AddToOutbox(xmppId, resource string) {
|
|
|
|
|
c.locks.outboxLock.Lock()
|
|
|
|
|
defer c.locks.outboxLock.Unlock()
|
|
|
|
|
|
|
|
|
|
c.outbox[xmppId] = resource
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Client) popFromOutbox(xmppId string) string {
|
|
|
|
|
c.locks.outboxLock.Lock()
|
|
|
|
|
defer c.locks.outboxLock.Unlock()
|
|
|
|
|
|
|
|
|
|
resource, ok := c.outbox[xmppId]
|
|
|
|
|
if ok {
|
|
|
|
|
delete(c.outbox, xmppId)
|
|
|
|
|
} else {
|
|
|
|
|
log.Warnf("No %v xmppId in outbox", xmppId)
|
|
|
|
|
}
|
|
|
|
|
return resource
|
|
|
|
|
}
|
|
|
|
|