Skip to content
Closed
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/app/chat/event_handling.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ proc handleChatEvents(self: ChatController) =
# app to be slower
self.status.events.on("chatUpdate") do(e: Args):
var evArgs = ChatUpdateArgs(e)

echo "CHAT UPDATES: ", $evArgs.chats


self.view.hideLoadingIndicator()
self.view.updateChats(evArgs.chats)
self.view.pushMessages(evArgs.messages)
Expand All @@ -67,6 +71,9 @@ proc handleChatEvents(self: ChatController) =
self.view.reactions.push(evArgs.emojiReactions)
if (evArgs.communities.len > 0):
for community in evArgs.communities.mitems:

echo "COMMUNITY UPDATE: ", $community

if self.view.communities.isUserMemberOfCommunity(community.id) and not community.admin and not community.isMember:
discard self.view.communities.leaveCommunity(community.id)
continue
Expand Down
59 changes: 50 additions & 9 deletions src/app/chat/views/communities.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ type
InProgress,
Error

proc ensureCorrectChatPositions(community: var Community, chat: Chat) =
var i = 0
for c in community.chats:
if (c.categoryId == chat.categoryId and c.id != chat.id):
if (c.position == 0):
community.chats[i].position = 1

if (c.position >= chat.position+1):
community.chats[i].position = c.position + 1

i = i + 1
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a WIP attempt to update the chat item positions until we get a response from status-go.

This is the part I need help with.



proc mergeChat(community: var Community, chat: Chat): bool =
var i = 0
for c in community.chats:
Expand Down Expand Up @@ -90,11 +103,17 @@ QtObject:

result.add(community)

proc updateCommunityChat*(self: CommunitiesView, newChat: Chat) =
proc updateCommunityChat*(self: CommunitiesView, newChat: Chat, ensureCorrectPositions = false) =
var community = self.joinedCommunityList.getCommunityById(newChat.communityId)
if (community.id == ""):
return

#if ensureCorrectPositions:
# This is to visually put the updated chat in the correct (new)
# position so we don't get a funny flicker effect once the position
# was updated in the backend.
#ensureCorrectChatPositions(community, newChat)
#else:
Copy link
Member Author

Choose a reason for hiding this comment

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

For the time being I've commented it out to ensure drag and drop works otherwise.

let found = mergeChat(community, newChat)

if (not found):
Expand Down Expand Up @@ -228,6 +247,16 @@ QtObject:
proc addCommunityToList*(self: CommunitiesView, community: var Community) =
var communities = @[community]
community = self.populateChats(communities)[0]

#echo "COMMUNITY CHATS: ", $community.chats

for cat in community.categories:
echo "Category: ", cat.name

for c in community.chats:
if c.categoryId == cat.id:
echo "-> ", c.name, ": ", c.position
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just debugging output which can be ignored and will be removed before merge.

Helps inspecting what chat items belong to which categories when we get an update from status-go.

That's how I verified the bug reported in status-im/status-go#2376


let communityCheck = self.communityList.getCommunityById(community.id)
if (communityCheck.id == ""):
self.communityList.addCommunityItemToList(community)
Expand Down Expand Up @@ -353,14 +382,6 @@ QtObject:
error "Error reorder the category", msg = e.msg
result = fmt"Error reorder the category: {e.msg}"

proc reorderCommunityChannel*(self: CommunitiesView, communityId: string, categoryId: string, chatId: string, position: int): string {.slot} =
result = ""
try:
self.status.chat.reorderCommunityChannel(communityId, categoryId, chatId, position)
except Exception as e:
error "Error reorder the channel", msg = e.msg
result = fmt"Error reorder the channel: {e.msg}"


proc setObservedCommunity*(self: CommunitiesView, communityId: string) {.slot.} =
if(communityId == ""): return
Expand Down Expand Up @@ -510,6 +531,26 @@ QtObject:
chat.muted = true
return chat

proc reorderCommunityChannel*(self: CommunitiesView, communityId: string, categoryId: string, chatId: string, position: int): string {.slot} =

var chat = self.getChannel(chatId)
chat.categoryId = categoryId
chat.position = position

# Update chat object and persist new position in memory until
# backend has been updated with new chat position.
self.updateCommunityChat(chat, true)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is part of visually updating the new order in QML, but before we the reorder signal was sent to status-go.

updateCommunityChat performs updateChats eventually, which is what we need. We just need to make sure that the positions of each chat item is updated correctly before that (see comment above).


result = ""

try:
echo "REQUEST REORDER: ", position
self.status.chat.reorderCommunityChannel(communityId, categoryId, chatId, position)
except Exception as e:
error "Error reorder the channel", msg = e.msg
result = fmt"Error reorder the channel: {e.msg}"


proc deleteCommunityChat*(self: CommunitiesView, communityId: string, channelId: string): string {.slot.} =
try:
self.status.chat.deleteCommunityChat(communityId, channelId)
Expand Down
2 changes: 1 addition & 1 deletion ui/app/AppLayouts/Chat/CommunityColumn.qml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Item {
ScrollView {
id: chatGroupsContainer
anchors.top: membershipRequests.bottom
anchors.topMargin: Style.current.padding
anchors.topMargin: Style.current.padding - 8
Copy link
Member Author

Choose a reason for hiding this comment

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

I've added this because, with the new drag and drop capabilities, users can drag out of a category, To make that work, there's an additional 8px space at the top of the StatusChatListAndCategories component, so I'm substracting it here.

We actually need to check whether the "uncategorized" chat list is indeed empty and only then substract the height here (because only then the new drop area is active and visible)

anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter

Expand Down