parent
dcad109bac
commit
7fbd37a8f7
|
@ -260,6 +260,7 @@ proc load(self: AppController) =
|
|||
self.nodeConfigurationService.init()
|
||||
self.contactsService.init()
|
||||
self.chatService.init()
|
||||
self.messageService.init()
|
||||
self.communityService.init()
|
||||
self.bookmarkService.init()
|
||||
self.tokenService.init()
|
||||
|
|
|
@ -42,7 +42,7 @@ method delete*(self: Controller) =
|
|||
|
||||
method init*(self: Controller) =
|
||||
self.events.on(SIGNAL_SEARCH_MESSAGES_LOADED) do(e:Args):
|
||||
let args = SearchMessagesLoadedArgs(e)
|
||||
let args = MessagesArgs(e)
|
||||
self.delegate.onSearchMessagesDone(args.messages)
|
||||
|
||||
method activeSectionId*(self: Controller): string =
|
||||
|
|
|
@ -7,7 +7,6 @@ import ../../../../../../app_service/service/community/service as community_serv
|
|||
import ../../../../../../app_service/service/chat/service as chat_service
|
||||
import ../../../../../../app_service/service/message/service as message_service
|
||||
|
||||
import ../../../../../core/signals/types
|
||||
import eventemitter
|
||||
|
||||
export controller_interface
|
||||
|
@ -52,6 +51,11 @@ method init*(self: Controller) =
|
|||
return
|
||||
self.delegate.newMessagesLoaded(args.messages, args.reactions, args.pinnedMessages)
|
||||
|
||||
self.events.on(SIGNAL_NEW_MESSAGE_RECEIVED) do(e: Args):
|
||||
var evArgs = MessagesArgs(e)
|
||||
for message in evArgs.messages:
|
||||
self.delegate.messageAdded(message)
|
||||
|
||||
self.events.on(SIGNAL_SENDING_SUCCESS) do(e:Args):
|
||||
let args = MessageSendingSuccess(e)
|
||||
if(self.chatId != args.chat.id):
|
||||
|
|
|
@ -126,7 +126,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
|
|||
|
||||
self.view.setLoadingHistoryMessagesInProgress(false)
|
||||
|
||||
method onSendingMessageSuccess*(self: Module, message: MessageDto) =
|
||||
method messageAdded*(self: Module, message: MessageDto) =
|
||||
let sender = self.controller.getContactById(message.`from`)
|
||||
let senderDisplayName = sender.userNameOrAlias()
|
||||
let amISender = message.`from` == singletonInstance.userProfile.getPubKey()
|
||||
|
@ -141,6 +141,9 @@ method onSendingMessageSuccess*(self: Module, message: MessageDto) =
|
|||
message.timestamp, message.contentType.ContentType, message.messageType)
|
||||
|
||||
self.view.model().prependItem(item)
|
||||
|
||||
method onSendingMessageSuccess*(self: Module, message: MessageDto) =
|
||||
self.messageAdded(message)
|
||||
self.view.emitSendingMessageSuccessSignal()
|
||||
|
||||
method onSendingMessageError*(self: Module) =
|
||||
|
|
|
@ -13,6 +13,9 @@ method onReactionRemoved*(self: AccessInterface, messageId: string, emojiId: int
|
|||
method onPinUnpinMessage*(self: AccessInterface, messageId: string, pin: bool) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method messageAdded*(self: AccessInterface, message: MessageDto) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onSendingMessageSuccess*(self: AccessInterface, message: MessageDto) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import NimQml, tables, json, sequtils, chronicles
|
|||
|
||||
import eventemitter
|
||||
import ../../../app/core/tasks/[qt, threadpool]
|
||||
import ../../../app/core/signals/types
|
||||
|
||||
import status/statusgo_backend_new/messages as status_go
|
||||
|
||||
|
@ -21,6 +22,7 @@ const CURSOR_VALUE_IGNORE = "ignore"
|
|||
|
||||
# Signals which may be emitted by this service:
|
||||
const SIGNAL_MESSAGES_LOADED* = "new-messagesLoaded" #Once we are done with refactoring we should remove "new-" from all signals
|
||||
const SIGNAL_NEW_MESSAGE_RECEIVED* = "SIGNAL_NEW_MESSAGE_RECEIVED"
|
||||
const SIGNAL_MESSAGE_PINNED* = "new-messagePinned"
|
||||
const SIGNAL_MESSAGE_UNPINNED* = "new-messageUnpinned"
|
||||
const SIGNAL_SEARCH_MESSAGES_LOADED* = "new-searchMessagesLoaded"
|
||||
|
@ -31,7 +33,7 @@ const SIGNAL_MESSAGE_REACTION_REMOVED* = "new-messageReactionRemoved"
|
|||
include async_tasks
|
||||
|
||||
type
|
||||
SearchMessagesLoadedArgs* = ref object of Args
|
||||
MessagesArgs* = ref object of Args
|
||||
messages*: seq[MessageDto]
|
||||
|
||||
MessagesLoadedArgs* = ref object of Args
|
||||
|
@ -78,6 +80,12 @@ QtObject:
|
|||
result.pinnedMsgCursor = initTable[string, string]()
|
||||
result.lastUsedPinnedMsgCursor = initTable[string, string]()
|
||||
|
||||
proc init*(self: Service) =
|
||||
self.events.on(SignalType.Message.event) do(e: Args):
|
||||
var evArgs = MessageSignal(e)
|
||||
if (evArgs.messages.len > 0):
|
||||
self.events.emit(SIGNAL_NEW_MESSAGE_RECEIVED, MessagesArgs(messages: evArgs.messages))
|
||||
|
||||
proc initialMessagesFetched(self: Service, chatId: string): bool =
|
||||
return self.msgCursor.hasKey(chatId)
|
||||
|
||||
|
@ -279,7 +287,7 @@ QtObject:
|
|||
|
||||
proc finishAsyncSearchMessagesWithError*(self: Service, errorMessage: string) =
|
||||
error "error: ", methodName="onAsyncSearchMessages", errDescription = errorMessage
|
||||
self.events.emit(SIGNAL_SEARCH_MESSAGES_LOADED, SearchMessagesLoadedArgs())
|
||||
self.events.emit(SIGNAL_SEARCH_MESSAGES_LOADED, MessagesArgs())
|
||||
|
||||
proc onAsyncSearchMessages*(self: Service, response: string) {.slot.} =
|
||||
let responseObj = response.parseJson
|
||||
|
@ -303,7 +311,7 @@ QtObject:
|
|||
|
||||
var messages = map(messagesArray.getElems(), proc(x: JsonNode): MessageDto = x.toMessageDto())
|
||||
|
||||
let data = SearchMessagesLoadedArgs(messages: messages)
|
||||
let data = MessagesArgs(messages: messages)
|
||||
self.events.emit(SIGNAL_SEARCH_MESSAGES_LOADED, data)
|
||||
|
||||
proc asyncSearchMessages*(self: Service, chatId: string, searchTerm: string, caseSensitive: bool) =
|
||||
|
|
Loading…
Reference in New Issue