|
|
|
@ -205,27 +205,24 @@ func (c *Client) updateChatLastMessage(update *client.UpdateChatLastMessage) {
|
|
|
|
|
func (c *Client) updateNewMessage(update *client.UpdateNewMessage) {
|
|
|
|
|
chatId := update.Message.ChatId
|
|
|
|
|
|
|
|
|
|
c.SendMessageLock.Lock()
|
|
|
|
|
c.SendMessageLock.Unlock()
|
|
|
|
|
xmppId, err := gateway.IdsDB.GetByTgIds(c.Session.Login, c.jid, chatId, update.Message.Id)
|
|
|
|
|
var ignoredResource string
|
|
|
|
|
if err == nil {
|
|
|
|
|
ignoredResource = c.popFromOutbox(xmppId)
|
|
|
|
|
} else {
|
|
|
|
|
log.Infof("Couldn't retrieve XMPP message ids for %v, an echo may happen", update.Message.Id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// guarantee sequential message delivering per chat
|
|
|
|
|
lock := c.getChatMessageLock(chatId)
|
|
|
|
|
go func() {
|
|
|
|
|
lock.Lock()
|
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
|
|
|
|
|
// ignore self outgoing messages
|
|
|
|
|
if update.Message.IsOutgoing &&
|
|
|
|
|
update.Message.SendingState != nil &&
|
|
|
|
|
update.Message.SendingState.MessageSendingStateType() == client.TypeMessageSendingStatePending {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.WithFields(log.Fields{
|
|
|
|
|
"chat_id": chatId,
|
|
|
|
|
}).Warn("New message from chat")
|
|
|
|
|
|
|
|
|
|
c.ProcessIncomingMessage(chatId, update.Message, ignoredResource)
|
|
|
|
|
c.ProcessIncomingMessage(chatId, update.Message)
|
|
|
|
|
|
|
|
|
|
c.updateLastMessageHash(update.Message.ChatId, update.Message.Id, update.Message.Content)
|
|
|
|
|
}()
|
|
|
|
|