Join private chats

This commit is contained in:
Richard Ramos 2020-05-28 10:58:25 -04:00 committed by RichΛrd
parent 1a829828c8
commit 3b8408d21a
12 changed files with 53 additions and 20 deletions

View File

@ -38,7 +38,7 @@ proc init*(self: ChatController) =
proc load*(self: ChatController, chatId: string) =
# TODO: we need a function to load the channels from the db.
# and... called from init() instead from nim_status_client
discard self.view.joinChat(chatId)
discard self.view.joinChat(chatId, ChatType.Public.int)
self.view.setActiveChannelByIndex(0)
proc handleMessage(self: ChatController, data: Signal) =

View File

@ -2,6 +2,7 @@ import NimQml
import Tables
import views/channels_list
import views/message_list
import ../../signals/types
import ../../models/chat
import random
@ -79,15 +80,19 @@ QtObject:
read = getMessageList
notify = activeChannelChanged
proc joinChat*(self: ChatsView, channel: string): int {.slot.} =
self.setActiveChannel(channel)
proc joinChat*(self: ChatsView, channel: string, chatTypeInt: int): int {.slot.} =
let chatType = ChatType(chatTypeInt)
if self.model.hasChannel(channel):
result = self.chats.chats.findById(channel)
else:
self.model.join(channel)
randomize()
let randomColorIndex = rand(channelColors.len - 1)
result = self.chats.addChatItemToList(ChatItem(id: channel, name: channel, color: channelColors[randomColorIndex]))
let chatItem = newChatItem(id = channel, chatType, color = channelColors[randomColorIndex])
result = self.chats.addChatItemToList(chatItem)
self.setActiveChannel(channel)
proc leaveActiveChat*(self: ChatsView) {.slot.} =
self.model.leave(self.activeChannel)

View File

@ -2,7 +2,6 @@ import eventemitter, sets, json, strutils
import ../status/utils
import ../status/chat as status_chat
import chronicles
import ../status/libstatus
import chat/chat_item
import chat/chat_message

View File

@ -1,4 +1,5 @@
import ../../signals/types
import ../../status/accounts as status_accounts
type ChatItem* = ref object
id*: string
@ -10,14 +11,22 @@ type ChatItem* = ref object
color*: string
identicon*: string
proc newChatItem*(): ChatItem =
proc newChatItem*(id: string, chatType: ChatType, lastMessage: string = "", timestamp: int64 = 0, unviewedMessagesCount: int = 0, color: string = "", identicon: string = ""): ChatItem =
new(result)
result.name = ""
result.lastMessage = ""
result.timestamp = 0
result.unviewedMessagesCount = 0
result.color = ""
result.identicon = ""
result.id = id
result.name = case chatType
of ChatType.Public: id
of ChatType.OneToOne: generateAlias(id)
of ChatType.PrivateGroupChat: "TODO: Private Group Name"
result.chatType = chatType
result.lastMessage = lastMessage
result.timestamp = timestamp
result.unviewedMessagesCount = unviewedMessagesCount
result.color = color
result.identicon = if identicon == "" and chatType == ChatType.OneToOne:
generateIdenticon(id)
else:
identicon
proc findById*(self: seq[ChatItem], id: string): int =
result = -1

View File

@ -17,7 +17,6 @@ Rectangle {
radius: 8
// Hide the box if it is filtered out
property bool isVisible: searchStr == "" || name.includes(searchStr)
property int chatTypeOneToOne: 1
visible: isVisible ? true : false
height: isVisible ? 64 : 0
@ -43,7 +42,7 @@ Rectangle {
radius: 50
Loader {
sourceComponent: chatType == chatTypeOneToOne ? imageIdenticon : letterIdenticon
sourceComponent: chatType == Constants.chatTypeOneToOne ? imageIdenticon : letterIdenticon
anchors.fill: parent
}
@ -62,7 +61,13 @@ Rectangle {
}
Text {
text: (name.charAt(0) == "#" ? name.charAt(1) : name.charAt(0)).toUpperCase()
text: {
if(chatType == Constants.chatTypeOneToOne){
return name;
} else {
return (name.charAt(0) == "#" ? name.charAt(1) : name.charAt(0)).toUpperCase();
}
}
opacity: 0.7
font.weight: Font.Bold
font.pixelSize: 21
@ -94,7 +99,7 @@ Rectangle {
Text {
id: contactInfo
text: chatType == chatTypeOneToOne ? name : "#" + name
text: chatType == Constants.chatTypeOneToOne ? name : "#" + name
anchors.right: contactTime.left
anchors.rightMargin: Theme.smallPadding
elide: Text.ElideRight

View File

@ -17,5 +17,10 @@ Item {
anchors.fill: parent
model: chatsModel.chats
delegate: Channel {}
onCountChanged: {
if (count > 0) {
currentIndex = count - 1;
}
}
}
}

View File

@ -127,8 +127,7 @@ Item {
anchors.fill: parent
onClicked : {
if(chatKey.text === "") return;
// chatsModel.joinChat(chatKey.text);
console.log("TODO: join private chat");
chatsModel.joinChat(chatKey.text, Constants.chatTypeOneToOne);
popup.close();
}
}

View File

@ -189,7 +189,7 @@ Item {
anchors.fill: parent
onClicked : {
if(channelName.text === "") return;
chatsModel.joinChat(channelName.text);
chatsModel.joinChat(channelName.text, Constants.chatTypePublic);
popup.close();
}
}

View File

@ -24,7 +24,7 @@ Rectangle {
MouseArea {
anchors.fill: parent
onClicked: chatsModel.joinChat(channel)
onClicked: chatsModel.joinChat(channel, Constants.chatTypePublic)
cursorShape: Qt.PointingHandCursor
}
}

9
ui/imports/Constants.qml Normal file
View File

@ -0,0 +1,9 @@
pragma Singleton
import QtQuick 2.8
QtObject {
readonly property int chatTypeOneToOne: 1
readonly property int chatTypePublic: 2
readonly property int chatTypePrivateGroupChat: 3
}

View File

@ -1,2 +1,3 @@
module Theme
singleton Theme 1.0 ./Theme.qml
singleton Constants 1.0 ./Constants.qml

View File

@ -15,6 +15,7 @@ SOURCES +=
RESOURCES += \
imports/Theme.qml \
imports/Constants.qml \
main.qml
# Additional import path used to resolve QML modules in Qt Creator's code model