parent
923350a46f
commit
22839f177b
|
@ -585,18 +585,21 @@ QtObject:
|
|||
proc getLinkPreviewData*(self: ChatsView, link: string, uuid: string) {.slot.} =
|
||||
self.getLinkPreviewData("linkPreviewDataReceived", link, uuid)
|
||||
|
||||
proc joinChat*(self: ChatsView, channel: string, chatTypeInt: int): int {.slot.} =
|
||||
var chatType = ChatType(chatTypeInt)
|
||||
proc getChatType*(self: ChatsView, channel: string): int {.slot.} =
|
||||
let selectedChannel = self.getChannelById(channel)
|
||||
if not selectedChannel.isNil:
|
||||
chatType = selectedChannel.chatType
|
||||
self.status.chat.join(channel, chatType)
|
||||
self.setActiveChannel(channel)
|
||||
chatType.int
|
||||
if selectedChannel == nil:
|
||||
return -1
|
||||
selectedChannel.chatType.int
|
||||
|
||||
proc joinChatWithENS*(self: ChatsView, channel: string, ensName: string): int {.slot.} =
|
||||
self.status.chat.join(channel, ChatType.OneToOne, ensName=status_ens.addDomain(ensName))
|
||||
proc joinPublicChat*(self: ChatsView, channel: string): int {.slot.} =
|
||||
self.status.chat.createPublicChat(channel)
|
||||
self.setActiveChannel(channel)
|
||||
ChatType.Public.int
|
||||
|
||||
proc joinPrivateChat*(self: ChatsView, pubKey: string, ensName: string): int {.slot.} =
|
||||
self.status.chat.createOneToOneChat(pubKey, if ensName != "": status_ens.addDomain(ensName) else: "")
|
||||
self.setActiveChannel(pubKey)
|
||||
ChatType.OneToOne.int
|
||||
|
||||
proc messagesLoaded*(self: ChatsView) {.signal.}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ proc cleanSpamChatGroups(self: ChatModel, chats: seq[Chat], contacts: seq[Profil
|
|||
if contact.address == member.id:
|
||||
isContact = true
|
||||
if not isContact and not joined:
|
||||
status_chat.deactivateChat(chat)
|
||||
discard status_chat.deactivateChat(chat)
|
||||
else:
|
||||
result.add(chat)
|
||||
else:
|
||||
|
@ -128,28 +128,17 @@ proc hasChannel*(self: ChatModel, chatId: string): bool =
|
|||
proc getActiveChannel*(self: ChatModel): string =
|
||||
if (self.channels.len == 0): "" else: toSeq(self.channels.values)[self.channels.len - 1].id
|
||||
|
||||
proc join*(self: ChatModel, chatId: string, chatType: ChatType, ensName: string = "", pubKey: string = "") =
|
||||
if self.hasChannel(chatId): return
|
||||
|
||||
var chat = newChat(chatId, ChatType(chatType))
|
||||
self.channels[chat.id] = chat
|
||||
let joined = times.toUnix(times.getTime()) * 1000
|
||||
status_chat.saveChat(chatId, chatType, color=chat.color, ensName=ensName, profile=pubKey, joined=joined)
|
||||
if ensName != "":
|
||||
chat.name = ensName
|
||||
chat.ensName = ensName
|
||||
|
||||
proc emitTopicAndJoin(self: ChatModel, chat: Chat) =
|
||||
let filterResult = status_chat.loadFilters(@[status_chat.buildFilter(chat)])
|
||||
|
||||
var topics:seq[MailserverTopic] = @[]
|
||||
let parsedResult = parseJson(filterResult)["result"]
|
||||
for topicObj in parsedResult:
|
||||
if ($topicObj["chatId"].getStr == chatId):
|
||||
if ($topicObj["chatId"].getStr == chat.id):
|
||||
topics.add(MailserverTopic(
|
||||
topic: $topicObj["topic"].getStr,
|
||||
discovery: topicObj["discovery"].getBool,
|
||||
negotiated: topicObj["negotiated"].getBool,
|
||||
chatIds: @[chatId],
|
||||
chatIds: @[chat.id],
|
||||
lastRequest: 1
|
||||
))
|
||||
|
||||
|
@ -160,6 +149,34 @@ proc join*(self: ChatModel, chatId: string, chatType: ChatType, ensName: string
|
|||
|
||||
self.events.emit("channelJoined", ChannelArgs(chat: chat))
|
||||
|
||||
|
||||
proc join*(self: ChatModel, chatId: string, chatType: ChatType, ensName: string = "", pubKey: string = "") =
|
||||
if self.hasChannel(chatId): return
|
||||
var chat = newChat(chatId, ChatType(chatType))
|
||||
self.channels[chat.id] = chat
|
||||
status_chat.saveChat(chatId, chatType, color=chat.color, ensName=ensName, profile=pubKey)
|
||||
self.emitTopicAndJoin(chat)
|
||||
|
||||
|
||||
proc createOneToOneChat*(self: ChatModel, publicKey: string, ensName: string = "") =
|
||||
if self.hasChannel(publicKey): return
|
||||
var chat = newChat(publicKey, ChatType.OneToOne)
|
||||
if ensName != "":
|
||||
chat.name = ensName
|
||||
chat.ensName = ensName
|
||||
self.channels[chat.id] = chat
|
||||
discard status_chat.createOneToOneChat(publicKey)
|
||||
self.emitTopicAndJoin(chat)
|
||||
|
||||
|
||||
proc createPublicChat*(self: ChatModel, chatId: string) =
|
||||
if self.hasChannel(chatId): return
|
||||
var chat = newChat(chatId, ChatType.Public)
|
||||
self.channels[chat.id] = chat
|
||||
discard status_chat.createPublicChat(chatId)
|
||||
self.emitTopicAndJoin(chat)
|
||||
|
||||
|
||||
proc updateContacts*(self: ChatModel, contacts: seq[Profile]) =
|
||||
for c in contacts:
|
||||
self.contacts[c.id] = c
|
||||
|
@ -253,7 +270,7 @@ proc leave*(self: ChatModel, chatId: string) =
|
|||
let leaveGroupResponse = status_chat.leaveGroupChat(chatId)
|
||||
self.emitUpdate(leaveGroupResponse)
|
||||
|
||||
status_chat.deactivateChat(self.channels[chatId])
|
||||
discard status_chat.deactivateChat(self.channels[chatId])
|
||||
|
||||
# TODO: REMOVE MAILSERVER TOPIC
|
||||
self.channels.del(chatId)
|
||||
|
|
|
@ -71,7 +71,7 @@ proc addContact*(self: ContactModel, id: string, localNickname: string): string
|
|||
let updating = contact.systemTags.contains(":contact/added")
|
||||
if not updating:
|
||||
contact.systemTags.add(":contact/added")
|
||||
status_chat.saveChat(getTimelineChatId(contact.id), ChatType.Profile, ensName=contact.ensName, profile=contact.id)
|
||||
discard status_chat.createProfileChat(contact.id)
|
||||
let nickname =
|
||||
if (localNickname == ""):
|
||||
contact.localNickname
|
||||
|
|
|
@ -37,9 +37,18 @@ proc saveChat*(chatId: string, chatType: ChatType, active: bool = true, color: s
|
|||
}
|
||||
])
|
||||
|
||||
proc deactivateChat*(chat: Chat) =
|
||||
proc createPublicChat*(chatId: string):string =
|
||||
callPrivateRPC("createPublicChat".prefix, %* [{"ID": chatId}])
|
||||
|
||||
proc createOneToOneChat*(chatId: string):string =
|
||||
callPrivateRPC("createOneToOneChat".prefix, %* [{"ID": chatId}])
|
||||
|
||||
proc deactivateChat*(chat: Chat):string =
|
||||
chat.isActive = false
|
||||
discard callPrivateRPC("saveChat".prefix, %* [chat.toJsonNode])
|
||||
callPrivateRPC("deactivateChat".prefix, %* [{ "ID": chat.id }])
|
||||
|
||||
proc createProfileChat*(pubKey: string):string =
|
||||
callPrivateRPC("createProfileChat".prefix, %* [{ "ID": pubKey }])
|
||||
|
||||
proc sortChats(x, y: Chat): int =
|
||||
var t1 = x.lastMessage.whisperTimestamp
|
||||
|
|
|
@ -44,12 +44,20 @@ Item {
|
|||
clip: true
|
||||
onLinkActivated: function (link) {
|
||||
if(link.startsWith("#")) {
|
||||
const channelName = link.substring(1);
|
||||
const chatType = chatsModel.communities.activeCommunity.active ? Constants.chatTypeCommunity : Constants.chatTypePublic;
|
||||
const foundChatType = chatsModel.joinChat(link.substring(1), chatType);
|
||||
if (foundChatType === Constants.chatTypePublic && chatsModel.communities.activeCommunity.active) {
|
||||
const foundChatType = chatsModel.getChatType(channelName);
|
||||
|
||||
if(foundChatType == -1 || foundChatType !== Constants.chatTypePublic){
|
||||
chatsModel.joinPublicChat(channelName);
|
||||
if(chatsModel.communities.activeCommunity.active) {
|
||||
chatsModel.communities.activeCommunity.active = false
|
||||
appMain.changeAppSection(Constants.chat)
|
||||
}
|
||||
} else {
|
||||
chatsModel.setActiveChannel(channelName);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ PopupMenu {
|
|||
onTriggered: {
|
||||
if (messageContextMenu.isProfile) {
|
||||
appMain.changeAppSection(Constants.chat)
|
||||
chatsModel.joinChat(fromAuthor, Constants.chatTypeOneToOne)
|
||||
chatsModel.joinPrivateChat(fromAuthor, "")
|
||||
} else {
|
||||
showReplyArea()
|
||||
}
|
||||
|
|
|
@ -8,12 +8,7 @@ import "./"
|
|||
|
||||
ModalPopup {
|
||||
function doJoin(pk, ensName) {
|
||||
if(Utils.isChatKey(pk)){
|
||||
chatsModel.joinChat(pk, Constants.chatTypeOneToOne);
|
||||
} else {
|
||||
chatsModel.joinChatWithENS(pk, ensName);
|
||||
}
|
||||
|
||||
chatsModel.joinPrivateChat(pk, Utils.isChatKey(pk) ? "" : ensName);
|
||||
popup.close();
|
||||
}
|
||||
|
||||
|
@ -35,12 +30,7 @@ ModalPopup {
|
|||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
onUserClicked: function (isContact, pubKey, ensName) {
|
||||
if(Utils.isChatKey(pubKey)){
|
||||
chatsModel.joinChat(pubKey, Constants.chatTypeOneToOne);
|
||||
} else {
|
||||
chatsModel.joinChatWithENS(pubKey, ensName);
|
||||
}
|
||||
|
||||
chatsModel.joinPrivateChat(pubKey, Utils.isChatKey(pubKey) ? "" : ensName);
|
||||
popup.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -341,7 +341,7 @@ ModalPopup {
|
|||
width: visible ? implicitWidth : 0
|
||||
onClicked: {
|
||||
appMain.changeAppSection(Constants.chat)
|
||||
chatsModel.joinChat(fromAuthor, Constants.chatTypeOneToOne)
|
||||
chatsModel.joinPrivateChat(fromAuthor, "");
|
||||
popup.close()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ ModalPopup {
|
|||
if (!validate()) {
|
||||
return
|
||||
}
|
||||
chatsModel.joinChat(channelName.text, Constants.chatTypePublic);
|
||||
chatsModel.joinPublicChat(channelName.text);
|
||||
popup.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ Rectangle {
|
|||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
chatsModel.joinChat(channel, Constants.chatTypePublic)
|
||||
chatsModel.joinPublicChat(channel);
|
||||
onJoin()
|
||||
}
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
|
|
|
@ -62,7 +62,7 @@ Rectangle {
|
|||
contactContextMenu.popup()
|
||||
return
|
||||
}
|
||||
chatsModel.joinChat(container.address, Constants.chatTypeOneToOne)
|
||||
chatsModel.joinPrivateChat(container.address, "");
|
||||
changeAppSection(Constants.chat)
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ Rectangle {
|
|||
text: qsTrId("send-message")
|
||||
onTriggered: {
|
||||
changeAppSection(Constants.chat)
|
||||
chatsModel.joinChat(address, Constants.chatTypeOneToOne)
|
||||
chatsModel.joinPrivateChat(address, "")
|
||||
}
|
||||
enabled: !container.isBlocked
|
||||
}
|
||||
|
|
|
@ -367,7 +367,7 @@ QtObject {
|
|||
const pk = link.substring(index + 3)
|
||||
result.title = qsTr("Start a 1 on 1 chat with %1").arg(utilsModel.generateAlias(pk))
|
||||
result.callback = function () {
|
||||
chatsModel.joinChat(pk, Constants.chatTypeOneToOne);
|
||||
chatsModel.joinPrivateChat(pk, "");
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ QtObject {
|
|||
const chatId = link.substring(index + 1)
|
||||
result.title = qsTr("Join the %1 public channel").arg(chatId)
|
||||
result.callback = function () {
|
||||
chatsModel.joinChat(chatId, Constants.chatTypePublic);
|
||||
chatsModel.joinPublicChat(chatId);
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit dd49e604d49a2906dfad6ac1e459b72de014e2c0
|
||||
Subproject commit 92032c7158b80908508cd67c08ac6f6c75eee35b
|
Loading…
Reference in New Issue