Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ConversationsApp/ViewModels/ConversationVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ConversationViewModel: NSObject {

private(set) var observableConversation: ObservableFetchRequestResult<PersistentConversationDataItem>?
lazy private(set) var observableMessageList = conversationsRepository.getObservableMessages(for: conversationSid)
private(set) var observervableTypingMemeberList: ObservableFetchRequestResult<PersistentParticipantDataItem>?
private(set) var observableTypingParticipantList: ObservableFetchRequestResult<PersistentParticipantDataItem>?
private(set) var messageItems: [MessageListItemCell] = [] {
didSet {
self.delegate?.messageListUpdated(from: oldValue, to: messageItems)
Expand All @@ -40,7 +40,7 @@ class ConversationViewModel: NSObject {

weak var delegate: ConversationViewModelDelegate?

// MARK: Init
// MARK: Initialize the Conversation
init(conversationSid: String, conversationsRepository: ConversationsRepositoryProtocol = ConversationsRepository.shared, messagesManager: MessagesManagerProtocol = MessagesManager()) {
self.conversationSid = conversationSid
self.conversationsRepository = conversationsRepository
Expand Down Expand Up @@ -68,17 +68,17 @@ class ConversationViewModel: NSObject {
messagesManager.reactToMessage(withSid: sid, withReaction: reaction)
}

// MARK: Deintialization
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for these.

// Deinitialization
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return MARK here please.

deinit {
// During transition, remove observers
unsubscribeFromConversationChanges()
}

// MARK: Methods
// Methods
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here please, too.

private func unsubscribeFromConversationChanges() {
observableConversation?.removeObserver(self)
observableMessageList.removeObserver(self)
observervableTypingMemeberList?.removeObserver(self)
observervableTypingMemberList?.removeObserver(self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be observableTypingParticipantList?

}

private func listenForConversationChanges() {
Expand All @@ -88,7 +88,7 @@ class ConversationViewModel: NSObject {
}

private func listenForTypingParticipant() {
observervableTypingMemeberList?.observe(with: self) {[weak self] participants in
observervableTypingMemberList?.observe(with: self) {[weak self] participants in
guard let participants = participants else {
return
}
Expand All @@ -107,7 +107,7 @@ class ConversationViewModel: NSObject {

func loadConversation() {
observableConversation = fetchConversation(sid: conversationSid)
observervableTypingMemeberList = conversationsRepository.getTypingParticipants(inConversation: conversationSid).data
observervableTypingMemberList = conversationsRepository.getTypingParticipants(inConversation: conversationSid).data
listenForConversationChanges()
listenForConversationMessagesChanges()
listenForTypingParticipant()
Expand Down