Code Monkey home page Code Monkey logo

Comments (12)

antoine92190 avatar antoine92190 commented on May 27, 2024 1

@mryellow Issue may be fixed by this commit 1509e5e
Could you confirm that it solves the issue?

from vue-advanced-chat.

mryellow avatar mryellow commented on May 27, 2024

When Room.computed.room is executed on initial loading the roomId is an empty string as room has not yet been defined.

https://github.com/antoine92190/vue-advanced-chat/blob/c6ce2a905dc9e2f8be800e309d33a4759e8d2824/src/ChatWindow/Room.vue#L384-L386

https://github.com/antoine92190/vue-advanced-chat/blob/c6ce2a905dc9e2f8be800e309d33a4759e8d2824/src/ChatWindow/ChatWindow.vue#L26

from vue-advanced-chat.

antoine92190 avatar antoine92190 commented on May 27, 2024

@mryellow Unfortunately I cannot reproduce, it works fine on my side.
Could you share the code your are using so I can reproduce the issue?

from vue-advanced-chat.

mryellow avatar mryellow commented on May 27, 2024

Adding immediate: true to ChatWindow.watch.roomId looks to be part of the solution, that way fetchRoom is called during initialisation.

I can bypass some of the type issues by making roomId strings and passing :room-id="'1'" to chat-window.

<import>
./node_modules/vue-advanced-chat/dist/vue-advanced-chat.css
</import>

<component>
/**
* Component to display chat interface and communicate with backend
*
* @example Display a chat box
* <chat :room="someValue" :user="someValue">
*/
module.exports = {
	props: {
		room: {type: String, default: ''},
		user: {type: String, default: ''},
	},
	data() {
		return {
			theme: 'light',
			styles: { container: { borderRadius: '4px' } },
			messages: [
				{
					_id: 7890,
					content: 'message 1',
					sender_id: 1234,
					username: 'John Doe',
					date: '27 May',
					timestamp: '10:20',
					seen: true,
					disable_actions: false,
					disable_reactions: false,
					file: null,
					reactions: {
						wink: [
							1234, // USER_ID
							4321
						],
						laughing: [
							1234
						]
					}
				}
			],
		};
	},
	computed: {
		rooms() {
			return [
				{
					roomId: '1',
					roomName: 'Room 1',
					lastMessage: {
						content: 'Last message received',
						sender_id: 1234,
						username: 'John Doe',
						timestamp: '10:20',
						date: 123242424,
						seen: false,
						new: true
					},
					users: [
						{
							_id: 1234,
							username: 'John Doe',
							status: {
								state: 'online',
								last_changed: 'today, 14:30'
							}
						},
						{
							_id: 4321,
							username: 'John Snow',
							status: {
								state: 'offline',
								last_changed: '14 July, 20:00'
							}
						}
					],
					typingUsers: [ 4321 ]
				}
			];
		}
	},
	created() {
		this.$debugging = true;
		// TODO: Re-implement or attach from outside?
		//if (this.$props.loader) this.$loader.start();
	},
	mounted() {
		this.build();
	},
	methods: {
		build() {
			this.$debug('Build!');
		},
	},
};
</component>

<template>
	<div>
		<chat-window
			:theme="theme"
			:styles="styles"
			:current-user-id="user"
			:rooms="rooms"
			:messages="messages"
			:room-id="'1'"
			:single-room="true"
			:show-files="false"
			:show-reaction-emojis="false"
		/>
	</div>
</template>

from vue-advanced-chat.

antoine92190 avatar antoine92190 commented on May 27, 2024

@mryellow I can add immediate: true to ChatWindow.watch.roomId, indeed it seems to work that way. Why do you say it's only part of the solution?

I don't see the roomId type as an issue, roomId: '1' should not be considered the same as roomId: 1.
So you can either do :roomId="'1'" as you said, or roomId="1", or pass the id as a variable with the correct type.

Let me know if adding immediate: true would be enough to solve your issue.

from vue-advanced-chat.

antoine92190 avatar antoine92190 commented on May 27, 2024

Actually, there was indeed a type issue with roomId. Just fixed it: b44eae1

from vue-advanced-chat.

antoine92190 avatar antoine92190 commented on May 27, 2024

Just added the immediate: true to roomId watcher: 3f3c87b

from vue-advanced-chat.

mryellow avatar mryellow commented on May 27, 2024

Why do you say it's only part of the solution?

Just wasn't completely isolated and understood. Didn't see a singleRoom chat rendering with my tweaks.

Will be away for an hour or 3 and then will dig deeper.

Another solution to the immediate: true which crossed my mind is running fetchRoom from within mounted hook.

from vue-advanced-chat.

antoine92190 avatar antoine92190 commented on May 27, 2024

Got it, didn't see any side effect from using immediate: true, and it solved the issue on my side.
Let me know if you find anything else. Thanks for the help!

from vue-advanced-chat.

mryellow avatar mryellow commented on May 27, 2024

Didn't find anything definitive, just adding notes.

Not seeing roomId being selected and :single-room="true" still results in blank page. Strangely :show-rooms-list="false" shows the rooms list regardless.

Looking for differences in the flow:

With chat-container roomId watcher being immediate: true, fetchRoom (the method) is fired and room is set as it should be.

Alternative when clicking on the room via rooms-list:

openRoom is fired, which sets selectedRoomId and triggers a fetchRoom event. A watcher on room also sets selectedRoomId however this path is not reached on initial load so selectedRoomId is never set.

Perhaps this rooms-list watcher too could be immediate so that selectedRoomId is defined on initialisation:

    room: {
      immediate: true,
      handler: function handler(val) {
        if (val) this.selectedRoomId = val.roomId;
      }
    }

This makes initial loading fire in the same order as clicking the rooms list, however still doesn't actually "enter" that room.

from vue-advanced-chat.

antoine92190 avatar antoine92190 commented on May 27, 2024

I'm closing this issue as this is probably fixed in the commit mentioned above.
Feel free to reopen otherwise.

from vue-advanced-chat.

mryellow avatar mryellow commented on May 27, 2024

Yeah sorry I saw your reply and then got busy.

Haven't tested but looks like you're on the right track with it.

from vue-advanced-chat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.