|
|
|
@ -73,6 +73,20 @@ func (c *Client) updateHandler() {
|
|
|
|
|
}
|
|
|
|
|
c.updateNewChat(typedUpdate)
|
|
|
|
|
log.Debugf("%#v", typedUpdate.Chat)
|
|
|
|
|
case client.TypeUpdateChatPosition:
|
|
|
|
|
typedUpdate, ok := update.(*client.UpdateChatPosition)
|
|
|
|
|
if !ok {
|
|
|
|
|
uhOh()
|
|
|
|
|
}
|
|
|
|
|
c.updateChatPosition(typedUpdate)
|
|
|
|
|
log.Debugf("%#v", typedUpdate)
|
|
|
|
|
case client.TypeUpdateChatLastMessage:
|
|
|
|
|
typedUpdate, ok := update.(*client.UpdateChatLastMessage)
|
|
|
|
|
if !ok {
|
|
|
|
|
uhOh()
|
|
|
|
|
}
|
|
|
|
|
c.updateChatLastMessage(typedUpdate)
|
|
|
|
|
log.Debugf("%#v", typedUpdate)
|
|
|
|
|
case client.TypeUpdateNewMessage:
|
|
|
|
|
typedUpdate, ok := update.(*client.UpdateNewMessage)
|
|
|
|
|
if !ok {
|
|
|
|
@ -142,30 +156,8 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) {
|
|
|
|
|
|
|
|
|
|
c.cache.SetChat(update.Chat.Id, update.Chat)
|
|
|
|
|
|
|
|
|
|
var isChannel = false
|
|
|
|
|
chatType := update.Chat.Type.ChatTypeType()
|
|
|
|
|
if chatType == client.TypeChatTypeSupergroup {
|
|
|
|
|
typeSupergroup, ok := update.Chat.Type.(*client.ChatTypeSupergroup)
|
|
|
|
|
if !ok {
|
|
|
|
|
uhOh()
|
|
|
|
|
}
|
|
|
|
|
isChannel = typeSupergroup.IsChannel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// don't subscribe to channel posters
|
|
|
|
|
if !((isChannel && update.Chat.LastReadInboxMessageId == 0) ||
|
|
|
|
|
// don't subscribe to chats with no conversation
|
|
|
|
|
// (manual adding will trigger a subscribe anyway)
|
|
|
|
|
(update.Chat.LastReadInboxMessageId == 0 &&
|
|
|
|
|
update.Chat.LastReadOutboxMessageId == 0 &&
|
|
|
|
|
chatType == client.TypeChatTypePrivate)) {
|
|
|
|
|
gateway.SendPresence(
|
|
|
|
|
c.xmpp,
|
|
|
|
|
c.jid,
|
|
|
|
|
gateway.SPFrom(strconv.FormatInt(update.Chat.Id, 10)),
|
|
|
|
|
gateway.SPType("subscribe"),
|
|
|
|
|
gateway.SPNickname(update.Chat.Title),
|
|
|
|
|
)
|
|
|
|
|
if update.Chat.Positions != nil && len(update.Chat.Positions) > 0 {
|
|
|
|
|
c.subscribeToID(update.Chat.Id, update.Chat)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if update.Chat.Id < 0 {
|
|
|
|
@ -174,6 +166,20 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) {
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// chat position is updated
|
|
|
|
|
func (c *Client) updateChatPosition(update *client.UpdateChatPosition) {
|
|
|
|
|
if update.Position != nil && update.Position.Order != 0 {
|
|
|
|
|
go c.subscribeToID(update.ChatId, nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// chat last message is updated
|
|
|
|
|
func (c *Client) updateChatLastMessage(update *client.UpdateChatLastMessage) {
|
|
|
|
|
if update.Positions != nil && len(update.Positions) > 0 {
|
|
|
|
|
go c.subscribeToID(update.ChatId, nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// message received
|
|
|
|
|
func (c *Client) updateNewMessage(update *client.UpdateNewMessage) {
|
|
|
|
|
go func() {
|
|
|
|
|