Skip to content

Commit

Permalink
Fix invalid ChatId.Chat deserialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
mukel committed Oct 16, 2017
1 parent c86e4aa commit 786ef9c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.mukel.telegrambot4s.methods

import info.mukel.telegrambot4s.models.{ChatId, Message, ReplyMarkup}
import info.mukel.telegrambot4s.models.{Message, ReplyMarkup}

/** Use this method to send a game.
* On success, the sent Message is returned.
Expand All @@ -15,7 +15,7 @@ import info.mukel.telegrambot4s.models.{ChatId, Message, ReplyMarkup}
* If not empty, the first button must launch the game.
*/
case class SendGame(
chatId : ChatId.Chat,
chatId : Long,
gameShortName : String,
disableNotification : Option[Boolean] = None,
replyToMessageId : Option[Int] = None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.mukel.telegrambot4s.methods

import info.mukel.telegrambot4s.models.Currency.Currency
import info.mukel.telegrambot4s.models.{ChatId, InlineKeyboardMarkup, LabeledPrice, Message}
import info.mukel.telegrambot4s.models.{InlineKeyboardMarkup, LabeledPrice, Message}

/**
* Use this method to send invoices.
Expand Down Expand Up @@ -33,7 +33,7 @@ import info.mukel.telegrambot4s.models.{ChatId, InlineKeyboardMarkup, LabeledPri
* If not empty, the first button must be a Pay button.
*/
case class SendInvoice(
chatId : ChatId.Chat,
chatId : Long,
title : String,
description : String,
payload : String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,12 @@ case class Message(
groupChatCreated : Option[Boolean] = None,
supergroupChatCreated : Option[Boolean] = None,
channelChatCreated : Option[Boolean] = None,
migrateToChatId : Option[ChatId.Chat] = None,
migrateFromChatId : Option[ChatId.Chat] = None,
migrateToChatId : Option[Long] = None,
migrateFromChatId : Option[Long] = None,
pinnedMessage : Option[Message] = None,
successfulPayment : Option[SuccessfulPayment] = None
) {

def source: ChatId.Chat = ChatId.Chat(chat.id)

@deprecated("Use .source instead", "telegrambo4s 2.0.1")
def sender = source
def source: Long = chat.id // ChatId.Chat(chat.id)
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ package info.mukel.telegrambot4s.models
* @param retryAfter Integer Optional. In case of exceeding flood control, the number of seconds left to wait before the request can be repeated
*/
case class ResponseParameters(
migrateToChatId : Option[ChatId.Chat] = None,
migrateToChatId : Option[Long] = None,
retryAfter : Option[Int] = None
)
4 changes: 2 additions & 2 deletions examples/src/main/scala/CallbacksBot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import info.mukel.telegrambot4s.Implicits._
import info.mukel.telegrambot4s.api.declarative.{Callbacks, Commands}
import info.mukel.telegrambot4s.api.{Extractors, Polling}
import info.mukel.telegrambot4s.methods.EditMessageReplyMarkup
import info.mukel.telegrambot4s.models.{InlineKeyboardButton, InlineKeyboardMarkup}
import info.mukel.telegrambot4s.models.{ChatId, InlineKeyboardButton, InlineKeyboardMarkup}

/**
* Show how to use callbacks, and it's shortcomings.
Expand Down Expand Up @@ -43,7 +43,7 @@ class CallbacksBot(token: String) extends ExampleBot(token)
} /* do */ {
request(
EditMessageReplyMarkup(
msg.source, // msg.chat.id
ChatId(msg.source), // msg.chat.id
msg.messageId,
replyMarkup = markupCounter(n + 1)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,15 @@ class MarshallingSuite extends FlatSpec with MockFactory with Matchers with Test
fromJson[MaskPositionType](""""chin"""") === (MaskPositionType.Chin)
toJson(MaskPositionType.Mouth) === ("mouth")
}

it should "correctly de/serialize Message.migrateToChatId" in {
fromJson[Message](
"""{
|"message_id": 1,
|"date": 1,
|"chat": {"id": 123, "type": "private"},
|"migrate_to_chat_id": 12345678901234567
|}""".stripMargin)
.migrateToChatId === 12345678901234567L
}
}

0 comments on commit 786ef9c

Please sign in to comment.