|
@@ -23,7 +23,7 @@ protocol ChatListViewModelProtocol: class, UISearchResultsUpdating {
|
|
|
var emptySearchText: String? { get }
|
|
|
|
|
|
/// returns ROW of table
|
|
|
- func deleteChat(chatId: Int) -> Int
|
|
|
+ func deleteChat(chatId: Int) -> Int?
|
|
|
func archiveChatToggle(chatId: Int)
|
|
|
func pinChatToggle(chatId: Int)
|
|
|
func refreshData()
|
|
@@ -201,13 +201,18 @@ class ChatListViewModel: NSObject, ChatListViewModelProtocol {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- func deleteChat(chatId: Int) -> Int {
|
|
|
+ func deleteChat(chatId: Int) -> Int? {
|
|
|
// find index of chatId
|
|
|
let indexToDelete = Array(0..<chatList.length).filter { chatList.getChatId(index: $0) == chatId }.first
|
|
|
+ let chat = dcContext.getChat(chatId: chatId)
|
|
|
dcContext.deleteChat(chatId: chatId)
|
|
|
updateChatList(notifyListener: false)
|
|
|
safe_assert(indexToDelete != nil)
|
|
|
- return indexToDelete ?? -1
|
|
|
+ // Do not return the index of the tableview cell for the selfTalk chat:
|
|
|
+ // Immediately after deleting the chat, a message to the device talk chat gets added.
|
|
|
+ // If the device talk chat was not existing it would be created and added to the table data source.
|
|
|
+ // That case invalidates the index.
|
|
|
+ return chat.isSelfTalk ? nil : indexToDelete
|
|
|
}
|
|
|
|
|
|
func archiveChatToggle(chatId: Int) {
|