add getLastUpdatedTime

This commit is contained in:
Chumva 2018-08-16 13:16:58 +03:00
parent f1ece52940
commit 9e697a4080
5 changed files with 19 additions and 39 deletions

View file

@ -1,4 +1,5 @@
<resources>
<string name="time_ago">ago</string>
<string name="last_response">Last response</string>
<string name="shared_string_group">Group</string>
<string name="logout_no_internet_msg">To properly log out from your Telegram account, the Internet is needed.</string>

View file

@ -177,6 +177,14 @@ class TelegramHelper private constructor() {
return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup
}
fun getLastUpdatedTime(message: TdApi.Message): Int {
return if (message.editDate != 0) {
message.editDate
} else {
message.date
}
}
fun isPrivateChat(chat: TdApi.Chat): Boolean = chat.type is TdApi.ChatTypePrivate
private fun isChannel(chat: TdApi.Chat): Boolean {
@ -485,9 +493,7 @@ class TelegramHelper private constructor() {
val viaBot = isOsmAndBot(message.viaBotUserId)
val oldContent = message.content
if (oldContent is TdApi.MessageText) {
message.content = parseOsmAndBotLocation(oldContent.text.text).apply {
created = message.date
}
message.content = parseOsmAndBotLocation(oldContent.text.text)
} else if (oldContent is TdApi.MessageLocation && (fromBot || viaBot)) {
message.content = parseOsmAndBotLocation(message)
}
@ -761,13 +767,7 @@ class TelegramHelper private constructor() {
name = getOsmAndBotDeviceName(message)
lat = messageLocation.location.latitude
lon = messageLocation.location.longitude
created = message.date
val date = message.editDate
lastUpdated = if (date != 0) {
date
} else {
message.date
}
lastUpdated = getLastUpdatedTime(message)
}
}
@ -777,7 +777,6 @@ class TelegramHelper private constructor() {
name = oldContent.name
lat = messageLocation.location.latitude
lon = messageLocation.location.longitude
created = oldContent.created
lastUpdated = (System.currentTimeMillis() / 1000).toInt()
}
}
@ -1069,9 +1068,7 @@ class TelegramHelper private constructor() {
synchronized(message) {
val newContent = updateMessageContent.newContent
message.content = if (newContent is TdApi.MessageText) {
val messageOsmAndBotLocation = parseOsmAndBotLocation(newContent.text.text)
messageOsmAndBotLocation.created = message.date
messageOsmAndBotLocation
parseOsmAndBotLocation(newContent.text.text)
} else if (newContent is TdApi.MessageLocation &&
(isOsmAndBot(message.senderUserId) || isOsmAndBot(message.viaBotUserId))) {
parseOsmAndBotLocationContent(message.content as MessageOsmAndBotLocation, newContent)

View file

@ -54,13 +54,7 @@ object TelegramUiHelper {
val type = chat.type
val message = messages.firstOrNull()
if (message != null) {
val lastUpdated = message.editDate
res.lastUpdated = if (lastUpdated != 0) {
lastUpdated
} else {
message.date
}
res.created = message.date
res.lastUpdated = helper.getLastUpdatedTime(message)
}
if (type is TdApi.ChatTypePrivate || type is TdApi.ChatTypeSecret) {
val userId = getUserIdFromChatType(type)
@ -130,7 +124,6 @@ object TelegramUiHelper {
latLon = LatLon(content.lat, content.lon)
placeholderId = R.drawable.img_user_picture
lastUpdated = content.lastUpdated
created = content.created
}
} else {
null
@ -152,13 +145,7 @@ object TelegramUiHelper {
photoPath = helper.getUserPhotoPath(user)
placeholderId = R.drawable.img_user_picture
userId = message.senderUserId
val editDate = message.editDate
lastUpdated = if (editDate != 0) {
editDate
} else {
message.date
}
created = message.date
lastUpdated = helper.getLastUpdatedTime(message)
}
}
@ -178,8 +165,6 @@ object TelegramUiHelper {
internal set
var lastUpdated: Int = 0
internal set
var created: Int = 0
internal set
abstract fun canBeOpenedOnMap(): Boolean

View file

@ -363,7 +363,8 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
private fun getListItemLiveTimeDescr(item: ListItem):String {
return getString(R.string.last_response) +
": ${OsmandFormatter.getFormattedDuration(app, getListItemLiveTime(item))}"
": ${OsmandFormatter.getFormattedDuration(app, getListItemLiveTime(item))} " +
getString(R.string.time_ago)
}
private fun getListItemLiveTime(item: ListItem): Long = (System.currentTimeMillis() / 1000) - item.lastUpdated

View file

@ -291,11 +291,7 @@ class SetTimeDialogFragment : DialogFragment(), TelegramLocationListener, Telegr
val message = telegramHelper.getChatMessages(chat.id).firstOrNull()
val content = message?.content
if (message != null && content is TdApi.MessageLocation && (location != null && content.location != null)) {
val lastUpdated = if (message.editDate != 0) {
message.editDate
} else {
message.date
}
val lastUpdated = telegramHelper.getLastUpdatedTime(message)
holder.description?.visibility = View.VISIBLE
holder.description?.text = getListItemLiveTimeDescr(lastUpdated)
@ -328,8 +324,8 @@ class SetTimeDialogFragment : DialogFragment(), TelegramLocationListener, Telegr
override fun getItemCount() = chats.size
private fun getListItemLiveTimeDescr(lastUpdated: Int): String {
return getString(R.string.last_response) +
": ${OsmandFormatter.getFormattedDuration(app, getListItemLiveTime(lastUpdated))}"
return "${OsmandFormatter.getFormattedDuration(app, getListItemLiveTime(lastUpdated))} " +
getString(R.string.time_ago)
}
private fun getListItemLiveTime(lastUpdated: Int): Long {