aboutsummaryrefslogtreecommitdiff
path: root/telegram/handlers.go
diff options
context:
space:
mode:
Diffstat (limited to 'telegram/handlers.go')
-rw-r--r--telegram/handlers.go45
1 files changed, 43 insertions, 2 deletions
diff --git a/telegram/handlers.go b/telegram/handlers.go
index 0d1cda9..6f6d339 100644
--- a/telegram/handlers.go
+++ b/telegram/handlers.go
@@ -55,6 +55,33 @@ func (c *Client) cleanTempFile(path string) {
}
}
+func (c *Client) sendMarker(chatId, messageId int64, typ gateway.MarkerType) {
+ if xmppId, err := gateway.IdsDB.GetByTgIds(c.Session.Login, c.jid, chatId, messageId); err == nil {
+ resource := c.getFromOutbox(xmppId)
+
+ var stringType string
+ if typ == gateway.MarkerTypeReceived {
+ stringType = "received"
+ } else if typ == gateway.MarkerTypeDisplayed {
+ stringType = "displayed"
+ }
+ log.WithFields(log.Fields{
+ "xmppId": xmppId,
+ "resource": resource,
+ }).Debugf("marker: %s", stringType)
+
+ if resource != "" {
+ gateway.SendMessageMarker(
+ c.jid+"/"+resource,
+ strconv.FormatInt(chatId, 10),
+ c.xmpp,
+ typ,
+ xmppId,
+ )
+ }
+ }
+}
+
func (c *Client) updateHandler() {
listener := c.client.GetListener()
defer listener.Close()
@@ -141,6 +168,12 @@ func (c *Client) updateHandler() {
uhOh()
}
c.updateChatTitle(typedUpdate)
+ case client.TypeUpdateChatReadOutbox:
+ typedUpdate, ok := update.(*client.UpdateChatReadOutbox)
+ if !ok {
+ uhOh()
+ }
+ c.updateChatReadOutbox(typedUpdate)
default:
// log only handled types
continue
@@ -239,7 +272,7 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
xmppId, err := gateway.IdsDB.GetByTgIds(c.Session.Login, c.jid, update.ChatId, update.MessageId)
var ignoredResource string
if err == nil {
- ignoredResource = c.popFromOutbox(xmppId)
+ ignoredResource = c.popFromEditOutbox(xmppId)
} else {
log.Infof("Couldn't retrieve XMPP message ids for %v, an echo may happen", update.MessageId)
}
@@ -294,19 +327,23 @@ func (c *Client) updateAuthorizationState(update *client.UpdateAuthorizationStat
}
}
-// clean uploaded files
func (c *Client) updateMessageSendSucceeded(update *client.UpdateMessageSendSucceeded) {
+ // replace message ID in local database
log.Debugf("replace message %v with %v", update.OldMessageId, update.Message.Id)
if err := gateway.IdsDB.ReplaceTgId(c.Session.Login, c.jid, update.Message.ChatId, update.OldMessageId, update.Message.Id); err != nil {
log.Errorf("failed to replace %v with %v: %v", update.OldMessageId, update.Message.Id, err.Error())
}
+ c.sendMarker(update.Message.ChatId, update.Message.Id, gateway.MarkerTypeReceived)
+
+ // clean uploaded files
file, _ := c.contentToFile(update.Message.Content)
if file != nil && file.Local != nil {
c.cleanTempFile(file.Local.Path)
}
}
func (c *Client) updateMessageSendFailed(update *client.UpdateMessageSendFailed) {
+ // clean uploaded files
file, _ := c.contentToFile(update.Message.Content)
if file != nil && file.Local != nil {
c.cleanTempFile(file.Local.Path)
@@ -328,3 +365,7 @@ func (c *Client) updateChatTitle(update *client.UpdateChatTitle) {
chat.Title = update.Title
}
}
+
+func (c *Client) updateChatReadOutbox(update *client.UpdateChatReadOutbox) {
+ c.sendMarker(update.ChatId, update.LastReadOutboxMessageId, gateway.MarkerTypeDisplayed)
+}