Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite MessageList store logic and refactor chat store #1161

Merged
merged 31 commits into from
Dec 8, 2019

Conversation

Jikstra
Copy link
Contributor

@Jikstra Jikstra commented Nov 30, 2019

  • Moves fetch/paging logic into frontend and store
  • Moves message convertion into backend
  • fixes scroll jumping by scrolling to a specific message

Missing:

  • day markers
  • sending messages
  • deleting messages
  • update on incoming msgs
  • some message methods aren't working properly
  • iron all those bugs out
    • Cannot convert undefined or null to object at Function.keys (<anonymous>) at module.exports../src/renderer/stores/MessageList.js.MessageListStore.effects.push (MessageList.js:123)
    • UI hangs on showing more message details
    • restore default state when deleting currently selected chat
    • selecting a chat with unread messages needs two clicks
    • sending a message doesn't scroll down to the message
  • make sure images have a fixed height

Fixes #1166
Fixes #1158
Fixes #477
Fixes #1180
Fixes #1122 (comment)
Fixes #712

@Jikstra Jikstra changed the title Feat fix messagelist2 [wip] Feat fix messagelist2 Nov 30, 2019
@Jikstra Jikstra force-pushed the feat_fix_messagelist2 branch from ed964b4 to 00a63c1 Compare November 30, 2019 23:28
@Jikstra Jikstra changed the title [wip] Feat fix messagelist2 Refactor Chat store and and rewrite MessageList store logic Dec 4, 2019
@Jikstra Jikstra changed the title Refactor Chat store and and rewrite MessageList store logic Rewrite MessageList store logic and refactor chat store Dec 4, 2019
Copy link
Member

@Simon-Laux Simon-Laux left a comment

Choose a reason for hiding this comment

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

Works nicely

Copy link
Member

@nicodh nicodh left a comment

Choose a reason for hiding this comment

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

This PR is too big to really go through all changes and compare it with the state before. Maybe if we go through it together?
we must avoid to have huge PRs - they often introduce bugs especially since we don't have enough tests.

const { chatId, messages, totalMessages } = payload
if (chatId === chatStore.getState().id) {
chatStore.setState({ ...state, totalMessages, messages: [...messages, ...state.messages] })
const messageIndex = state.messageIds.findIndex(mId => mId === msgId)
Copy link
Member

Choose a reason for hiding this comment

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

why not use indexOf here?

...state.messageIds.slice(0, messageIndex),
...state.messageIds.slice(messageIndex + 1)
]
const messages = { ...state.messages, [msgId]: null }
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add some comments here, what are you doing etc. all this index juggling is hard to read without comments

} else if (type === 'MESSAGE_CHANGED') {
return { ...state, messages: { ...state.messages, ...payload.messagesChanged } }
} else if (type === 'SENT_MESSAGE') {
const [messageId, message] = payload
Copy link
Member

Choose a reason for hiding this comment

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

if SENT_MESSAGE means message is sent and MESSAGE_DELIVERED means message is delivered, please rename the first MESSAGE_SENT, one could easily misread SEND_MESSAGE...

const { msgId } = payload
callDcMethod('messageList.deleteMessage', [msgId])
} else if (type === 'FETCH_MORE_MESSAGES') {
const oldestFetchedMessageIndex = Math.max(state.oldestFetchedMessageIndex - 30, 0)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we have a "buffer" variable instead of hard coded number? Would be more explicit...

})
})

ipcBackend.on('DC_EVENT_INCOMING_MSG', async (_, id, messageIdIncoming) => {
Copy link
Member

Choose a reason for hiding this comment

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

messageIdIncoming is never used...?


function convert (message) {
export function RenderMessage (props) {
const chatStoreDispatch = useChatStore()[1]
Copy link
Member

Choose a reason for hiding this comment

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

this is a bit hard to read, what about [state, chatStoreDispatch] = useChatStore() ?
then it looks more similar to useState...


const scrollPrepare = () => { previousScrollHeightMinusTop.current = doc.scrollHeight - doc.scrollTop }
useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

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

I really would like some comments in all these useEffect handler, what the related use case or scenario is. Very hard to understand by reading...

return this._log
}

getName () {
Copy link
Member

Choose a reason for hiding this comment

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

what is this function for?

const { deaddrop, onClose } = props
const chatStoreDispatch = useChatStore()[1]
const yes = async () => {
const messageId = deaddrop.msg.id
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

and it didn't work in my test

const oldestFetchedMessageIndex = messageIds.length - PAGE_SIZE
const newestFetchedMessageIndex = messageIds.length
const messageIdsToFetch = messageIds.slice(oldestFetchedMessageIndex, newestFetchedMessageIndex)
const messages = await callDcMethodAsync('messageList.getMessages', [messageIdsToFetch])
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need 3 times to call callDcMethodAsync?
Why is messageIDs not fetched together with chatList.selectChat
Why do we need to calculate messageIdsToFetch here? PAGE_SIZE could be a shared variable, so the calculation could be done also together with chatList.selectChat

Renaming
Bugfix accept contact request
Adapt Test dom helper
@nicodh nicodh merged commit 3b5638d into master Dec 8, 2019
@nicodh nicodh deleted the feat_fix_messagelist2 branch December 8, 2019 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment