Add ability to share locations to saved messages

This commit is contained in:
Chumva 2019-11-29 15:03:52 +02:00
parent fe29de8bdd
commit 65123d43f1
3 changed files with 25 additions and 12 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="saved_messages">Saved messages</string>
<string name="shared_string_end">End</string>
<string name="shared_string_start">Start</string>
<string name="shared_string_apply">Apply</string>

View file

@ -489,7 +489,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private fun updateList() {
val items: MutableList<TdApi.Object> = mutableListOf()
val chats: MutableList<TdApi.Chat> = mutableListOf()
val currentUser = telegramHelper.getCurrentUser()
val contacts = telegramHelper.getContacts()
val chatList = if (sharingMode) {
settings.getShareLocationChats()
@ -501,10 +500,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
if (chat != null) {
if (!sharingMode && settings.isSharingLocationToChat(chatId)) {
continue
} else if (telegramHelper.isPrivateChat(chat)) {
if ((chat.type as TdApi.ChatTypePrivate).userId == currentUser?.id) {
continue
}
}
chats.add(chat)
}
@ -512,9 +507,8 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
items.addAll(chats)
if (!sharingMode) {
for (user in contacts.values) {
val containsInChats =
chats.any { telegramHelper.getUserIdFromChatType(it.type) == user.id }
if ((!sharingMode && settings.isSharingLocationToUser(user.id)) || user.id == currentUser?.id || containsInChats) {
val containsInChats = chats.any { telegramHelper.getUserIdFromChatType(it.type) == user.id }
if ((!sharingMode && settings.isSharingLocationToUser(user.id)) || containsInChats) {
continue
}
items.add(user)
@ -606,9 +600,18 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
TelegramUiHelper.setupPhoto(app, holder.icon, photoPath, placeholderId, false)
val currentUserId = telegramHelper.getCurrentUserId()
val title = when (item) {
is TdApi.Chat -> item.title
is TdApi.User -> TelegramUiHelper.getUserName(item)
is TdApi.Chat -> {
if (telegramHelper.isPrivateChat(item) && (item.type as TdApi.ChatTypePrivate).userId == currentUserId) {
getString(R.string.saved_messages)
} else {
item.title
}
}
is TdApi.User -> {
if (item.id == currentUserId) getString(R.string.saved_messages) else TelegramUiHelper.getUserName(item)
}
else -> null
}

View file

@ -322,9 +322,18 @@ class SetTimeDialogFragment : BaseDialogFragment(), TelegramLocationListener, Te
TelegramUiHelper.setupPhoto(app, holder.icon, photoPath, placeholderId, false)
val currentUserId = telegramHelper.getCurrentUserId()
val title = when (item) {
is TdApi.Chat -> item.title
is TdApi.User -> TelegramUiHelper.getUserName(item)
is TdApi.Chat -> {
if (telegramHelper.isPrivateChat(item) && (item.type as TdApi.ChatTypePrivate).userId == currentUserId) {
getString(R.string.saved_messages)
} else {
item.title
}
}
is TdApi.User -> {
if (item.id == currentUserId) getString(R.string.saved_messages) else TelegramUiHelper.getUserName(item)
}
else -> null
}