Fix "All" number for chat description
This commit is contained in:
parent
dcac4cb6a8
commit
c15f294dc4
2 changed files with 90 additions and 7 deletions
|
@ -85,6 +85,7 @@ class TelegramHelper private constructor() {
|
|||
|
||||
var listener: TelegramListener? = null
|
||||
private val incomingMessagesListeners = HashSet<TelegramIncomingMessagesListener>()
|
||||
private val fullInfoUpdatesListeners = HashSet<FullInfoUpdatesListener>()
|
||||
|
||||
fun addIncomingMessagesListener(listener: TelegramIncomingMessagesListener) {
|
||||
incomingMessagesListeners.add(listener)
|
||||
|
@ -94,6 +95,14 @@ class TelegramHelper private constructor() {
|
|||
incomingMessagesListeners.remove(listener)
|
||||
}
|
||||
|
||||
fun addFullInfoUpdatesListener(listener: FullInfoUpdatesListener) {
|
||||
fullInfoUpdatesListeners.add(listener)
|
||||
}
|
||||
|
||||
fun removeFullInfoUpdatesListener(listener: FullInfoUpdatesListener) {
|
||||
fullInfoUpdatesListeners.remove(listener)
|
||||
}
|
||||
|
||||
fun getChatList(): TreeSet<OrderedChat> {
|
||||
synchronized(chatList) {
|
||||
return TreeSet(chatList.filter { !it.isChannel })
|
||||
|
@ -130,9 +139,21 @@ class TelegramHelper private constructor() {
|
|||
return res
|
||||
}
|
||||
|
||||
fun getBasicGroupFullInfo(id: Int) = basicGroupsFullInfo[id]
|
||||
fun getBasicGroupFullInfo(id: Int): TdApi.BasicGroupFullInfo? {
|
||||
val res = basicGroupsFullInfo[id]
|
||||
if (res == null) {
|
||||
requestBasicGroupFullInfo(id)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
fun getSupergroupFullInfo(id: Int) = supergroupsFullInfo[id]
|
||||
fun getSupergroupFullInfo(id: Int): TdApi.SupergroupFullInfo? {
|
||||
val res = supergroupsFullInfo[id]
|
||||
if (res == null) {
|
||||
requestSupergroupFullInfo(id)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
fun isGroup(chat: TdApi.Chat): Boolean {
|
||||
return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup
|
||||
|
@ -180,6 +201,11 @@ class TelegramHelper private constructor() {
|
|||
fun updateLocationMessages()
|
||||
}
|
||||
|
||||
interface FullInfoUpdatesListener {
|
||||
fun onBasicGroupFullInfoUpdated(groupId: Int, info: TdApi.BasicGroupFullInfo)
|
||||
fun onSupergroupFullInfoUpdated(groupId: Int, info: TdApi.SupergroupFullInfo)
|
||||
}
|
||||
|
||||
interface TelegramAuthorizationRequestListener {
|
||||
fun onRequestTelegramAuthenticationParameter(parameterType: TelegramAuthenticationParameterType)
|
||||
fun onTelegramAuthorizationRequestError(code: Int, message: String)
|
||||
|
@ -366,6 +392,42 @@ class TelegramHelper private constructor() {
|
|||
listener?.onTelegramChatsRead()
|
||||
}
|
||||
|
||||
private fun requestBasicGroupFullInfo(id: Int) {
|
||||
client?.send(TdApi.GetBasicGroupFullInfo(id)) { obj ->
|
||||
when (obj.constructor) {
|
||||
TdApi.Error.CONSTRUCTOR -> {
|
||||
val error = obj as TdApi.Error
|
||||
if (error.code != IGNORED_ERROR_CODE) {
|
||||
listener?.onTelegramError(error.code, error.message)
|
||||
}
|
||||
}
|
||||
TdApi.BasicGroupFullInfo.CONSTRUCTOR -> {
|
||||
val info = obj as TdApi.BasicGroupFullInfo
|
||||
basicGroupsFullInfo[id] = info
|
||||
fullInfoUpdatesListeners.forEach { it.onBasicGroupFullInfoUpdated(id, info) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestSupergroupFullInfo(id: Int) {
|
||||
client?.send(TdApi.GetSupergroupFullInfo(id)) { obj ->
|
||||
when (obj.constructor) {
|
||||
TdApi.Error.CONSTRUCTOR -> {
|
||||
val error = obj as TdApi.Error
|
||||
if (error.code != IGNORED_ERROR_CODE) {
|
||||
listener?.onTelegramError(error.code, error.message)
|
||||
}
|
||||
}
|
||||
TdApi.SupergroupFullInfo.CONSTRUCTOR -> {
|
||||
val info = obj as TdApi.SupergroupFullInfo
|
||||
supergroupsFullInfo[id] = info
|
||||
fullInfoUpdatesListeners.forEach { it.onSupergroupFullInfoUpdated(id, info) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestCurrentUser(){
|
||||
client?.send(TdApi.GetMe()) { obj ->
|
||||
when (obj.constructor) {
|
||||
|
@ -1013,11 +1075,21 @@ class TelegramHelper private constructor() {
|
|||
}
|
||||
TdApi.UpdateBasicGroupFullInfo.CONSTRUCTOR -> {
|
||||
val updateBasicGroupFullInfo = obj as TdApi.UpdateBasicGroupFullInfo
|
||||
basicGroupsFullInfo[updateBasicGroupFullInfo.basicGroupId] = updateBasicGroupFullInfo.basicGroupFullInfo
|
||||
val id = updateBasicGroupFullInfo.basicGroupId
|
||||
if (basicGroupsFullInfo.containsKey(id)) {
|
||||
val info = updateBasicGroupFullInfo.basicGroupFullInfo
|
||||
basicGroupsFullInfo[id] = info
|
||||
fullInfoUpdatesListeners.forEach { it.onBasicGroupFullInfoUpdated(id, info) }
|
||||
}
|
||||
}
|
||||
TdApi.UpdateSupergroupFullInfo.CONSTRUCTOR -> {
|
||||
val updateSupergroupFullInfo = obj as TdApi.UpdateSupergroupFullInfo
|
||||
supergroupsFullInfo[updateSupergroupFullInfo.supergroupId] = updateSupergroupFullInfo.supergroupFullInfo
|
||||
val id = updateSupergroupFullInfo.supergroupId
|
||||
if (supergroupsFullInfo.containsKey(id)) {
|
||||
val info = updateSupergroupFullInfo.supergroupFullInfo
|
||||
supergroupsFullInfo[id] = info
|
||||
fullInfoUpdatesListeners.forEach { it.onSupergroupFullInfoUpdated(id, info) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ private const val CHAT_VIEW_TYPE = 0
|
|||
private const val LOCATION_ITEM_VIEW_TYPE = 1
|
||||
|
||||
class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessagesListener,
|
||||
TelegramLocationListener, TelegramCompassListener {
|
||||
FullInfoUpdatesListener, TelegramLocationListener, TelegramCompassListener {
|
||||
|
||||
private val app: TelegramApplication
|
||||
get() = activity?.application as TelegramApplication
|
||||
|
@ -75,12 +75,14 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
locationViewCache = app.uiUtils.getUpdateLocationViewCache()
|
||||
updateList()
|
||||
telegramHelper.addIncomingMessagesListener(this)
|
||||
telegramHelper.addFullInfoUpdatesListener(this)
|
||||
startLocationUpdate()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
telegramHelper.removeIncomingMessagesListener(this)
|
||||
telegramHelper.removeFullInfoUpdatesListener(this)
|
||||
stopLocationUpdate()
|
||||
}
|
||||
|
||||
|
@ -130,6 +132,14 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
|
||||
override fun updateLocationMessages() {}
|
||||
|
||||
override fun onBasicGroupFullInfoUpdated(groupId: Int, info: TdApi.BasicGroupFullInfo) {
|
||||
app.runInUIThread { updateList() }
|
||||
}
|
||||
|
||||
override fun onSupergroupFullInfoUpdated(groupId: Int, info: TdApi.SupergroupFullInfo) {
|
||||
app.runInUIThread { updateList() }
|
||||
}
|
||||
|
||||
override fun updateLocation(location: Location?) {
|
||||
val loc = this.location
|
||||
val newLocation = loc == null && location != null
|
||||
|
@ -299,8 +309,9 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
item.privateChat -> "" // FIXME
|
||||
else -> {
|
||||
val live = getString(R.string.shared_string_live)
|
||||
// val all = getString(R.string.shared_string_all)
|
||||
"$live ${item.liveMembersCount}"
|
||||
val all = getString(R.string.shared_string_all)
|
||||
val liveStr = "$live ${item.liveMembersCount}"
|
||||
if (item.membersCount > 0) "$liveStr • $all ${item.membersCount}" else liveStr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue