Convert TelegramHelper#isAppropriateMessage to extension function

This commit is contained in:
Alex Sytnyk 2018-07-02 17:37:08 +03:00
parent c9148af7f6
commit d98e870765

View file

@ -573,20 +573,20 @@ class TelegramHelper private constructor() {
listener?.onTelegramStatusChanged(prevAuthState, newAuthState) listener?.onTelegramStatusChanged(prevAuthState, newAuthState)
} }
private fun isAppropriateMessage(message: TdApi.Message): Boolean { private fun TdApi.Message.isAppropriate(): Boolean {
if (message.isOutgoing || message.isChannelPost) { if (isOutgoing || isChannelPost) {
return false return false
} }
val lastEdited = Math.max(message.date, message.editDate) val lastEdited = Math.max(date, editDate)
if (TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) - lastEdited > MESSAGE_ACTIVE_TIME_SEC) { if (TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) - lastEdited > MESSAGE_ACTIVE_TIME_SEC) {
return false return false
} }
val content = message.content val content = content
return when (content) { return when (content) {
is TdApi.MessageLocation -> true is TdApi.MessageLocation -> true
is TdApi.MessageText -> { is TdApi.MessageText -> {
if (content.text.text.startsWith("{")) { if (content.text.text.startsWith("{")) {
if (users[message.senderUserId]?.username == OSMAND_BOT_USERNAME) { if (users[senderUserId]?.username == OSMAND_BOT_USERNAME) {
return true return true
} }
} }
@ -795,7 +795,7 @@ class TelegramHelper private constructor() {
TdApi.UpdateNewMessage.CONSTRUCTOR -> { TdApi.UpdateNewMessage.CONSTRUCTOR -> {
val updateNewMessage = obj as TdApi.UpdateNewMessage val updateNewMessage = obj as TdApi.UpdateNewMessage
val message = updateNewMessage.message val message = updateNewMessage.message
if (isAppropriateMessage(message)) { if (message.isAppropriate()) {
usersLocationMessages[message.id] = message usersLocationMessages[message.id] = message
val chatTitle = chats[message.chatId]?.title val chatTitle = chats[message.chatId]?.title
if (chatTitle != null) { if (chatTitle != null) {