processone / ejabberd

Robust, Ubiquitous and Massively Scalable Messaging Platform (XMPP, MQTT, SIP Server)
https://www.process-one.net/en/ejabberd/
Other
6k stars 1.5k forks source link

How to get the current date for created_at when create a Multi-User Chat. #4202

Open vietnguyen87 opened 2 months ago

vietnguyen87 commented 2 months ago

I created a room with API https://docs.ejabberd.im/archive/24_02/admin-api/#create-room-with-opts . But column created_at in table muc_room was not getting the current date.

image

Help me fix this. Please.

prefiks commented 2 months ago

This column got repurposed, and now it keeps info about date of room hibernation (or sentinel value of 1970 when room is alive).

prefiks commented 2 months ago

So what you see here is correct behaviour per current code.

vietnguyen87 commented 2 months ago

In case I want to know when this room was created, where can I get it? @prefiks

prefiks commented 2 months ago

You can't any more.

vietnguyen87 commented 2 months ago

By the way, can you tell me? Can I get a list of members in the room with their roles via admin api ?

prefiks commented 2 months ago

You probably could use ejabberdctl get_room_occupants room conference.server.com. It require mod_muc_admin module enabled in config. Docs here: https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#get-room-occupants

vietnguyen87 commented 2 months ago

yes, i got it. But i get nothing when user disconnect.

prefiks commented 2 months ago

So you don't want to see roles but what affiliations are stored in a room (roles are only set for online users). Check https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#get-room-affiliations

vietnguyen87 commented 2 months ago

Yeah, thanks so much. I also get another issue. Please help me. When i join a room or send a message, it's created many chat records in archive for all users in room like the image below. kind = chat and txt is empty. Please see last 4 records. this room have 3 members. i connect with user 1 (owner) and user 2, user 3 are members.

image

Please....

prefiks commented 2 months ago

What those messages contain? Could you expand xml of one of those?

They look like messages to individual room member (and not sent to all members of a room), and as such are stored in sender and recipient archive.

vietnguyen87 commented 2 months ago

It's full description in xml. this room have 3 members.

Screenshot 2024-04-16 at 17 43 51

prefiks commented 2 months ago

This message have type "chat" so it's handled like regular message between two peers (as it in fact is), so it get stored in recipient and sender archive. What do you expect to happen with those message, they never get stored?

vietnguyen87 commented 2 months ago

But obviously I sent it to the room as a groupchat kind. and i understand everybody in this room will received it. I think it needs content saved in txt and kind is groupchat.

Suppose I want to get the chat history of user3 in room2 from the last message at (timestamp). How can i do it?

prefiks commented 2 months ago

Ah, those are mucsub events that are generated for muc messages. This is how mucsub works, it notifies subscribers that aren't in room, by sending those. And those message are allowed to be stored in archive or offline storage, because this is only way that offline user can know about those.

vietnguyen87 commented 2 months ago

thanks @prefiks. Let's me clarify something

  1. Multi User Chat in XMPP is presence based. When you are online you get the message. When you get offline, you leave the room and will not get anymore message until you join the room again by sending a presence message. The only way that offline user can receive message is use MUC/Sub protocol to subscribe to chat rooms. And those message are allowed to be stored in archive or offline storage like a message between two peers.
  2. To get history of user from the last message at (timestamp) in MUC/Sub i have to parse the xml column, right? in case, taking full control of the message management on the client side.
prefiks commented 2 months ago

Generally you don't need to parse anything, as there is already code in ejabberd that handles all this in mod_mam module, that respond to request described in https://xmpp.org/extensions/xep-0313.html.

Are you trying add external management of those outside ejabberd?

vietnguyen87 commented 2 months ago

I'm talking with ejabberd by golang. and clients (Web/App) connect with Chat Service (golang) and use go xmpp library https://pkg.go.dev/github.com/xmppo/go-xmpp

prefiks commented 2 months ago

Then you should send something like this: https://xmpp.org/extensions/xep-0313.html#filter-time (ideally example 8 from that), with time from last message that you seen, and you should receive messages that were archived after that one.

vietnguyen87 commented 2 months ago

Thanks @prefiks, let's me try.

Neustradamus commented 2 weeks ago

@vietnguyen87: What are your news since your latest comment?

vietnguyen87 commented 1 week ago

hi @Neustradamus , because i'm using ejabberd like a core chat system and golang service to communicate with client (Mobile app). So, i can handle something like: add created_at, get history chat... on my golang service.