refactor(general): new convenient methods added to chat and contact services
- `getOneToOneChatNameAndImage` method added to the chat service, we should use where ever in the app we need to display one to one chat image and name - `getContactNameAndImage` method added to the contacts service, we should use when we want to display pretty contact name and correct image/identicon depends what user set
This commit is contained in:
parent
4c42809a68
commit
64c0148bbf
|
@ -116,8 +116,8 @@ method searchMessages*(self: Controller, searchTerm: string) =
|
||||||
|
|
||||||
self.messageService.asyncSearchMessages(communities, chats, self.searchTerm, false)
|
self.messageService.asyncSearchMessages(communities, chats, self.searchTerm, false)
|
||||||
|
|
||||||
method getPrettyChatName*(self: Controller, chatId: string): string =
|
method getOneToOneChatNameAndImage*(self: Controller, chatId: string): tuple[name: string, image: string] =
|
||||||
return self.chatService.prettyChatName(chatId)
|
return self.chatService.getOneToOneChatNameAndImage(chatId)
|
||||||
|
|
||||||
method getContactById*(self: Controller, contactId: string): ContactsDto =
|
method getContactNameAndImage*(self: Controller, contactId: string): tuple[name: string, image: string] =
|
||||||
return self.contactsService.getContactById(contactId)
|
return self.contactsService.getContactNameAndImage(contactId)
|
|
@ -51,8 +51,9 @@ method getChatDetails*(self: AccessInterface, communityId, chatId: string): Chat
|
||||||
method searchMessages*(self: AccessInterface, searchTerm: string) {.base.} =
|
method searchMessages*(self: AccessInterface, searchTerm: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method getPrettyChatName*(self: AccessInterface, chatId: string): string {.base.} =
|
method getOneToOneChatNameAndImage*(self: AccessInterface, chatId: string): tuple[name: string, image: string]
|
||||||
|
{.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method getContactById*(self: AccessInterface, contactId: string): ContactsDto {.base.} =
|
method getContactNameAndImage*(self: AccessInterface, contactId: string): tuple[name: string, image: string] {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
|
@ -66,13 +66,6 @@ method viewDidLoad*(self: Module) =
|
||||||
method getModuleAsVariant*(self: Module): QVariant =
|
method getModuleAsVariant*(self: Module): QVariant =
|
||||||
return self.viewVariant
|
return self.viewVariant
|
||||||
|
|
||||||
proc getContactNameAndImage(self: Module, id: string): tuple[name: string, image: string] =
|
|
||||||
let contactDto = self.controller.getContactById(id)
|
|
||||||
result.name = contactDto.userNameOrAlias()
|
|
||||||
result.image = contactDto.identicon
|
|
||||||
if(contactDto.image.thumbnail.len > 0):
|
|
||||||
result.image = contactDto.image.thumbnail
|
|
||||||
|
|
||||||
proc buildLocationMenuForChat(self: Module): location_menu_item.Item =
|
proc buildLocationMenuForChat(self: Module): location_menu_item.Item =
|
||||||
var item = location_menu_item.initItem(conf.CHAT_SECTION_ID, SEARCH_MENU_LOCATION_CHAT_SECTION_NAME, "", "chat", "",
|
var item = location_menu_item.initItem(conf.CHAT_SECTION_ID, SEARCH_MENU_LOCATION_CHAT_SECTION_NAME, "", "chat", "",
|
||||||
false)
|
false)
|
||||||
|
@ -85,7 +78,7 @@ proc buildLocationMenuForChat(self: Module): location_menu_item.Item =
|
||||||
var chatName = c.name
|
var chatName = c.name
|
||||||
var chatImage = c.identicon
|
var chatImage = c.identicon
|
||||||
if(c.chatType == ChatType.OneToOne):
|
if(c.chatType == ChatType.OneToOne):
|
||||||
(chatName, chatImage) = self.getContactNameAndImage(c.id)
|
(chatName, chatImage) = self.controller.getOneToOneChatNameAndImage(c.id)
|
||||||
|
|
||||||
let subItem = location_menu_sub_item.initSubItem(c.id, chatName, chatImage, "", c.color, chatImage.len == 0)
|
let subItem = location_menu_sub_item.initSubItem(c.id, chatName, chatImage, "", c.color, chatImage.len == 0)
|
||||||
subItems.add(subItem)
|
subItems.add(subItem)
|
||||||
|
@ -189,7 +182,7 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) =
|
||||||
var chatName = c.name
|
var chatName = c.name
|
||||||
var chatImage = c.identicon
|
var chatImage = c.identicon
|
||||||
if(c.chatType == ChatType.OneToOne):
|
if(c.chatType == ChatType.OneToOne):
|
||||||
(chatName, chatImage) = self.getContactNameAndImage(c.id)
|
(chatName, chatImage) = self.controller.getOneToOneChatNameAndImage(c.id)
|
||||||
|
|
||||||
var rawChatName = chatName
|
var rawChatName = chatName
|
||||||
if(chatName.startsWith("@")):
|
if(chatName.startsWith("@")):
|
||||||
|
@ -210,12 +203,12 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) =
|
||||||
continue
|
continue
|
||||||
|
|
||||||
let chatDto = self.controller.getChatDetails("", m.chatId)
|
let chatDto = self.controller.getChatDetails("", m.chatId)
|
||||||
let (senderName, senderImage) = self.getContactNameAndImage(m.`from`)
|
let (senderName, senderImage) = self.controller.getContactNameAndImage(m.`from`)
|
||||||
if(chatDto.communityId.len == 0):
|
if(chatDto.communityId.len == 0):
|
||||||
var chatName = chatDto.name
|
var chatName = chatDto.name
|
||||||
var chatImage = chatDto.identicon
|
var chatImage = chatDto.identicon
|
||||||
if(chatDto.chatType == ChatType.OneToOne):
|
if(chatDto.chatType == ChatType.OneToOne):
|
||||||
(chatName, chatImage) = self.getContactNameAndImage(chatDto.id)
|
(chatName, chatImage) = self.controller.getOneToOneChatNameAndImage(chatDto.id)
|
||||||
|
|
||||||
let item = result_item.initItem(m.id, m.text, $m.timestamp, m.`from`, senderName,
|
let item = result_item.initItem(m.id, m.text, $m.timestamp, m.`from`, senderName,
|
||||||
SEARCH_RESULT_MESSAGES_SECTION_NAME, senderImage, "", chatName, "", chatImage, chatDto.color, chatImage.len == 0)
|
SEARCH_RESULT_MESSAGES_SECTION_NAME, senderImage, "", chatName, "", chatImage, chatDto.color, chatImage.len == 0)
|
||||||
|
|
|
@ -76,5 +76,5 @@ method setActiveItemSubItem*(self: Controller, itemId: string, subItemId: string
|
||||||
|
|
||||||
self.delegate.activeItemSubItemSet(self.activeItemId, self.activeSubItemId)
|
self.delegate.activeItemSubItemSet(self.activeItemId, self.activeSubItemId)
|
||||||
|
|
||||||
method getPrettyChatName*(self: Controller, chatId: string): string =
|
method getOneToOneChatNameAndImage*(self: Controller, chatId: string): tuple[name: string, image: string] =
|
||||||
return self.chatService.prettyChatName(chatId)
|
return self.chatService.getOneToOneChatNameAndImage(chatId)
|
|
@ -38,5 +38,6 @@ method getChatDetailsForChatTypes*(self: AccessInterface, types: seq[ChatType]):
|
||||||
method setActiveItemSubItem*(self: AccessInterface, itemId: string, subItemId: string) {.base.} =
|
method setActiveItemSubItem*(self: AccessInterface, itemId: string, subItemId: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method getPrettyChatName*(self: AccessInterface, chatId: string): string {.base.} =
|
method getOneToOneChatNameAndImage*(self: AccessInterface, chatId: string): tuple[name: string, image: string]
|
||||||
|
{.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
|
@ -72,9 +72,11 @@ proc buildChatUI(self: Module, events: EventEmitter, chatService: chat_service.S
|
||||||
let hasNotification = c.unviewedMessagesCount > 0 or c.unviewedMentionsCount > 0
|
let hasNotification = c.unviewedMessagesCount > 0 or c.unviewedMentionsCount > 0
|
||||||
let notificationsCount = c.unviewedMentionsCount
|
let notificationsCount = c.unviewedMentionsCount
|
||||||
var chatName = c.name
|
var chatName = c.name
|
||||||
|
var chatImage = c.identicon
|
||||||
if(c.chatType == ChatType.OneToOne):
|
if(c.chatType == ChatType.OneToOne):
|
||||||
chatName = self.controller.getPrettyChatName(c.id)
|
(chatName, chatImage) = self.controller.getOneToOneChatNameAndImage(c.id)
|
||||||
let item = initItem(c.id, chatName, c.identicon, c.color, c.description, c.chatType.int, hasNotification,
|
|
||||||
|
let item = initItem(c.id, chatName, chatImage, c.color, c.description, c.chatType.int, hasNotification,
|
||||||
notificationsCount, c.muted, false, 0)
|
notificationsCount, c.muted, false, 0)
|
||||||
self.view.appendItem(item)
|
self.view.appendItem(item)
|
||||||
self.addSubmodule(c.id, false, events, chatService, communityService, messageService)
|
self.addSubmodule(c.id, false, events, chatService, communityService, messageService)
|
||||||
|
|
|
@ -53,9 +53,8 @@ method getChatById*(self: Service, chatId: string): ChatDto =
|
||||||
|
|
||||||
return self.chats[chatId]
|
return self.chats[chatId]
|
||||||
|
|
||||||
method prettyChatName*(self: Service, chatId: string): string =
|
method getOneToOneChatNameAndImage*(self: Service, chatId: string): tuple[name: string, image: string] =
|
||||||
let contact = self.contactService.getContactById(chatId)
|
return self.contactService.getContactNameAndImage(chatId)
|
||||||
return contact.userNameOrAlias()
|
|
||||||
|
|
||||||
# TODO refactor this to new object types
|
# TODO refactor this to new object types
|
||||||
proc parseChatResponse*(self: Service, response: string): (seq[Chat], seq[Message]) =
|
proc parseChatResponse*(self: Service, response: string): (seq[Chat], seq[Message]) =
|
||||||
|
|
|
@ -23,7 +23,8 @@ method getChatsOfChatTypes*(self: ServiceInterface, types: seq[chat_dto.ChatType
|
||||||
method getChatById*(self: ServiceInterface, chatId: string): ChatDto {.base.} =
|
method getChatById*(self: ServiceInterface, chatId: string): ChatDto {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method prettyChatName*(self: ServiceInterface, chatId: string): string {.base.} =
|
method getOneToOneChatNameAndImage*(self: ServiceInterface, chatId: string): tuple[name: string, image: string]
|
||||||
|
{.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method parseChatResponse*(self: ServiceInterface, response: string): (seq[Chat], seq[Message]) {.base.} =
|
method parseChatResponse*(self: ServiceInterface, response: string): (seq[Chat], seq[Message]) {.base.} =
|
||||||
|
|
|
@ -110,7 +110,16 @@ QtObject:
|
||||||
hasAddedUs: false
|
hasAddedUs: false
|
||||||
)
|
)
|
||||||
|
|
||||||
proc saveContact(self: Service, contact: ContactsDto) =
|
proc getContactNameAndImage*(self: Service, publicKey: string): tuple[name: string, image: string] =
|
||||||
|
## This proc should be used accross the app in order to have for the same contact
|
||||||
|
## same image and name displayed everywhere in the app.
|
||||||
|
let contactDto = self.getContactById(publicKey)
|
||||||
|
result.name = contactDto.userNameOrAlias()
|
||||||
|
result.image = contactDto.identicon
|
||||||
|
if(contactDto.image.thumbnail.len > 0):
|
||||||
|
result.image = contactDto.image.thumbnail
|
||||||
|
|
||||||
|
proc saveContact(self: Service, contact: ContactsDto) =
|
||||||
# we must keep local contacts updated
|
# we must keep local contacts updated
|
||||||
self.contacts[contact.id] = contact
|
self.contacts[contact.id] = contact
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue