delete dialogs
delete messages (+ for all & mark as spam)
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.meloda.fast.api
|
||||
|
||||
object ApiExtensions {
|
||||
|
||||
val Boolean.intString get() = (if (this) 1 else 0).toString()
|
||||
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import android.text.SpannableString
|
||||
import android.text.style.StyleSpan
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.meloda.fast.R
|
||||
import com.meloda.fast.api.model.VkConversation
|
||||
import com.meloda.fast.api.model.VkGroup
|
||||
import com.meloda.fast.api.model.VkMessage
|
||||
import com.meloda.fast.api.model.VkUser
|
||||
@@ -16,6 +17,64 @@ import com.meloda.fast.api.model.base.attachments.BaseVkAttachmentItem
|
||||
|
||||
object VkUtils {
|
||||
|
||||
fun getMessageUser(message: VkMessage, profiles: Map<Int, VkUser>): VkUser? {
|
||||
return (if (!message.isUser()) null
|
||||
else profiles[message.fromId]).also { message.user.value = it }
|
||||
}
|
||||
|
||||
fun getMessageGroup(message: VkMessage, groups: Map<Int, VkGroup>): VkGroup? {
|
||||
return (if (!message.isGroup()) null
|
||||
else groups[message.fromId]).also { message.group.value = it }
|
||||
}
|
||||
|
||||
fun getMessageAvatar(
|
||||
message: VkMessage,
|
||||
messageUser: VkUser?,
|
||||
messageGroup: VkGroup?
|
||||
): String? {
|
||||
return when {
|
||||
message.isUser() -> messageUser?.photo200
|
||||
message.isGroup() -> messageGroup?.photo200
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun getMessageTitle(
|
||||
message: VkMessage,
|
||||
messageUser: VkUser?,
|
||||
messageGroup: VkGroup?
|
||||
): String? {
|
||||
return when {
|
||||
message.isUser() -> messageUser?.fullName
|
||||
message.isGroup() -> messageGroup?.name
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun getConversationUser(conversation: VkConversation, profiles: Map<Int, VkUser>): VkUser? {
|
||||
return (if (!conversation.isUser()) null
|
||||
else profiles[conversation.id]).also { conversation.user.value = it }
|
||||
}
|
||||
|
||||
fun getConversationGroup(conversation: VkConversation, groups: Map<Int, VkGroup>): VkGroup? {
|
||||
return (if (!conversation.isGroup()) null
|
||||
else groups[conversation.id]).also { conversation.group.value = it }
|
||||
}
|
||||
|
||||
fun getConversationAvatar(
|
||||
conversation: VkConversation,
|
||||
conversationUser: VkUser?,
|
||||
conversationGroup: VkGroup?
|
||||
): String? {
|
||||
return when {
|
||||
conversation.ownerId == VKConstants.FAST_GROUP_ID -> null
|
||||
conversation.isUser() -> conversationUser?.photo200
|
||||
conversation.isGroup() -> conversationGroup?.photo200
|
||||
conversation.isChat() -> conversation.photo200
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun prepareMessageText(text: String, forConversations: Boolean? = null): String {
|
||||
return text.apply {
|
||||
if (forConversations == true) replace("\n", "")
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.meloda.fast.api.model
|
||||
|
||||
import android.os.Parcelable
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import androidx.room.PrimaryKey
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Entity(tableName = "conversations")
|
||||
@@ -34,6 +37,14 @@ data class VkConversation(
|
||||
var lastMessage: VkMessage? = null,
|
||||
) : Parcelable {
|
||||
|
||||
@Ignore
|
||||
@IgnoredOnParcel
|
||||
val user = MutableLiveData<VkUser?>()
|
||||
|
||||
@Ignore
|
||||
@IgnoredOnParcel
|
||||
val group = MutableLiveData<VkGroup?>()
|
||||
|
||||
fun isChat() = type == "chat"
|
||||
fun isUser() = type == "user"
|
||||
fun isGroup() = type == "group"
|
||||
|
||||
@@ -23,4 +23,9 @@ data class ConversationsGetRequest(
|
||||
extended?.let { this["extended"] = it.toString() }
|
||||
startMessageId?.let { this["start_message_id"] = it.toString() }
|
||||
}
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class ConversationsDeleteRequest(val peerId: Int) : Parcelable {
|
||||
val map get() = mapOf("peer_id" to peerId.toString())
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.meloda.fast.api.model.request
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.meloda.fast.api.ApiExtensions.intString
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
@@ -20,9 +21,9 @@ data class MessagesGetHistoryRequest(
|
||||
).apply {
|
||||
count?.let { this["count"] = it.toString() }
|
||||
offset?.let { this["offset"] = it.toString() }
|
||||
extended?.let { this["extended"] = (if (it) 1 else 0).toString() }
|
||||
extended?.let { this["extended"] = it.intString }
|
||||
startMessageId?.let { this["start_message_id"] = it.toString() }
|
||||
rev?.let { this["rev"] = (if (it) 1 else 0).toString() }
|
||||
rev?.let { this["rev"] = it.intString }
|
||||
fields?.let { this["fields"] = it }
|
||||
}
|
||||
|
||||
@@ -51,8 +52,8 @@ data class MessagesSendRequest(
|
||||
lon?.let { this["lon"] = it.toString() }
|
||||
replyTo?.let { this["reply_to"] = it.toString() }
|
||||
stickerId?.let { this["sticker_id"] = it.toString() }
|
||||
disableMentions?.let { this["disable_mentions"] = (if (it) 1 else 0).toString() }
|
||||
dontParseLinks?.let { this["dont_parse_links"] = (if (it) 1 else 0).toString() }
|
||||
disableMentions?.let { this["disable_mentions"] = it.intString }
|
||||
dontParseLinks?.let { this["dont_parse_links"] = it.intString }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,11 +66,25 @@ data class MessagesMarkAsImportantRequest(
|
||||
val map
|
||||
get() = mutableMapOf(
|
||||
"message_ids" to messagesIds.joinToString { it.toString() },
|
||||
"important" to (if (important) 1 else 0).toString()
|
||||
"important" to important.intString
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class MessagesGetLongPollServerRequest(
|
||||
val needPts: Boolean,
|
||||
val version: Int
|
||||
) : Parcelable {
|
||||
|
||||
val map
|
||||
get() = mutableMapOf(
|
||||
"need_pts" to needPts.intString,
|
||||
"version" to version.toString()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@Parcelize
|
||||
data class MessagesPinMessageRequest(
|
||||
val peerId: Int,
|
||||
@@ -93,14 +108,27 @@ data class MessagesUnPinMessageRequest(val peerId: Int) : Parcelable {
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class MessagesGetLongPollServerRequest(
|
||||
val needPts: Boolean,
|
||||
val version: Int
|
||||
data class MessagesDeleteRequest(
|
||||
val peerId: Int,
|
||||
val messagesIds: List<Int>? = null,
|
||||
val conversationsMessagesIds: List<Int>? = null,
|
||||
val isSpam: Boolean? = null,
|
||||
val deleteForAll: Boolean? = null
|
||||
) : Parcelable {
|
||||
|
||||
val map
|
||||
get() = mutableMapOf(
|
||||
"need_pts" to (if (needPts) 1 else 0).toString(),
|
||||
"version" to version.toString()
|
||||
)
|
||||
"peer_id" to peerId.toString()
|
||||
).apply {
|
||||
isSpam?.let { this["spam"] = it.intString }
|
||||
deleteForAll?.let { this["delete_for_all"] = it.intString }
|
||||
messagesIds?.let {
|
||||
this["message_ids"] = it.joinToString { id -> id.toString() }
|
||||
}
|
||||
|
||||
conversationsMessagesIds?.let {
|
||||
this["conversation_message_ids"] = it.joinToString { id -> id.toString() }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ object VkUrls {
|
||||
|
||||
object Conversations {
|
||||
const val Get = "$API/messages.getConversations"
|
||||
const val Delete = "$API/messages.deleteConversation"
|
||||
}
|
||||
|
||||
object Users {
|
||||
@@ -22,10 +23,11 @@ object VkUrls {
|
||||
const val GetHistory = "$API/messages.getHistory"
|
||||
const val Send = "$API/messages.send"
|
||||
const val MarkAsImportant = "$API/messages.markAsImportant"
|
||||
const val Pin = "$API/messages.pin"
|
||||
const val Unpin = "$API/messages.unpin"
|
||||
const val GetLongPollServer = "$API/messages.getLongPollServer"
|
||||
const val GetLongPollHistory = "$API/messages.getLongPollHistory"
|
||||
const val Pin = "$API/messages.pin"
|
||||
const val Unpin = "$API/messages.unpin"
|
||||
const val Delete = "$API/messages.delete"
|
||||
}
|
||||
|
||||
|
||||
|
||||
+6
-3
@@ -1,8 +1,9 @@
|
||||
package com.meloda.fast.api.network.datasource
|
||||
|
||||
import com.meloda.fast.api.model.VkConversation
|
||||
import com.meloda.fast.api.network.repo.ConversationsRepo
|
||||
import com.meloda.fast.api.model.request.ConversationsDeleteRequest
|
||||
import com.meloda.fast.api.model.request.ConversationsGetRequest
|
||||
import com.meloda.fast.api.network.repo.ConversationsRepo
|
||||
import com.meloda.fast.database.dao.ConversationsDao
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -11,8 +12,10 @@ class ConversationsDataSource @Inject constructor(
|
||||
private val dao: ConversationsDao
|
||||
) {
|
||||
|
||||
suspend fun getAllChats(params: ConversationsGetRequest) = repo.getAllChats(params.map)
|
||||
suspend fun get(params: ConversationsGetRequest) = repo.get(params.map)
|
||||
|
||||
suspend fun storeConversations(conversations: List<VkConversation>) = dao.insert(conversations)
|
||||
suspend fun delete(params: ConversationsDeleteRequest) = repo.delete(params.map)
|
||||
|
||||
suspend fun store(conversations: List<VkConversation>) = dao.insert(conversations)
|
||||
|
||||
}
|
||||
@@ -29,6 +29,9 @@ class MessagesDataSource @Inject constructor(
|
||||
suspend fun unpin(params: MessagesUnPinMessageRequest) =
|
||||
repo.unpin(params.map)
|
||||
|
||||
suspend fun delete(params: MessagesDeleteRequest) =
|
||||
repo.delete(params.map)
|
||||
|
||||
suspend fun store(messages: List<VkMessage>) = dao.insert(messages)
|
||||
|
||||
suspend fun getCached(peerId: Int) = dao.getByPeerId(peerId)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.meloda.fast.api.network.repo
|
||||
|
||||
import com.meloda.fast.api.base.ApiResponse
|
||||
import com.meloda.fast.api.model.response.ConversationsGetResponse
|
||||
import com.meloda.fast.api.network.Answer
|
||||
import com.meloda.fast.api.network.VkUrls
|
||||
import com.meloda.fast.api.model.response.ConversationsGetResponse
|
||||
import retrofit2.http.FieldMap
|
||||
import retrofit2.http.FormUrlEncoded
|
||||
import retrofit2.http.POST
|
||||
@@ -12,6 +12,10 @@ interface ConversationsRepo {
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(VkUrls.Conversations.Get)
|
||||
suspend fun getAllChats(@FieldMap params: Map<String, String>): Answer<ApiResponse<ConversationsGetResponse>>
|
||||
suspend fun get(@FieldMap params: Map<String, String>): Answer<ApiResponse<ConversationsGetResponse>>
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(VkUrls.Conversations.Delete)
|
||||
suspend fun delete(@FieldMap params: Map<String, String>): Answer<ApiResponse<Any>>
|
||||
|
||||
}
|
||||
@@ -36,4 +36,8 @@ interface MessagesRepo {
|
||||
@POST(VkUrls.Messages.Unpin)
|
||||
suspend fun unpin(@FieldMap params: Map<String, String>): Answer<ApiResponse<Any>>
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(VkUrls.Messages.Delete)
|
||||
suspend fun delete(@FieldMap params: Map<String, String>): Answer<ApiResponse<Any>>
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user