Send a message to all members of the chat

45 views
Skip to first unread message

Victor Login (batazor)

unread,
Sep 21, 2023, 3:21:16 AMSep 21
to Tinode General
I want to send a message to all chat members from the server side, what method or go-channel should I use to do this?

I've been debugging this for a couple of days now, but haven't found out how to do it.

Gene

unread,
Sep 21, 2023, 11:39:51 AMSep 21
to Tinode General
If I understand your question correctly, you want to send a message to all users in the system. If that's the question then there is no such mechanism.

Victor Login (batazor)

unread,
Sep 21, 2023, 1:36:05 PMSep 21
to Tinode General
More like something similar to a new message notification, but from the server side.

Gene

unread,
Sep 21, 2023, 1:40:37 PMSep 21
to Tinode General
Server sends notifications for new messages. 

You may want to describe the desired functionality in detail otherwise I do not understand your questions.

Message has been deleted

Victor Login (batazor)

unread,
Sep 21, 2023, 1:57:27 PMSep 21
to Tinode General
All right. Okay. I've made a thread mechanism above topics.
To do this I add tags like `thread:<messageId/topicId>` to the message/topic tags, it works fine, but now I need to send a notification to the other members of the chat - hey, we have a new thread from the message `reqid: 5` - re-render the message -> view with the chat.

I think ideally it's to send a `data` type message to all chat members, I can send it to the author via `sess.queueOut(&ServerComMessage{})` - but I don't understand how to do it with the others members of the topic

Gene

unread,
Sep 21, 2023, 2:19:21 PMSep 21
to Tinode General
If I understand your use case correctly, the threads are within a group chat. I.e. your thread is a kind of a subgroup. What you need is to track the thread membership: you need to keep a list of users who are not just the members of the group but also members of the thread. You can do it in two ways: either the hard and proper way on the server, or the quick and dirty way on the client(s). 

If you do it on the server then it would involve a lot of work with CRUD ops for thread/subgroup membership.

If you do it on the client, your server would need to include [thread ID] into the notification payload, your clients would check if the current user is a member of the given thread and then either show or discard the notification.

In-app notifications are sent from this module: https://github.com/tinode/chat/blob/master/server/pres.go

Victor Login (batazor)

unread,
Oct 2, 2023, 9:47:46 AMOct 2
to Tinode General
I try this way:

```
message, err := t.svc.messages.Get(t.name, msgId)
if err != nil {
    return fmt.Errorf("failed to get message: %v", err)
}

data := &ServerComMessage{
    Data: &MsgServerData{
        Id: message.Id,
        Topic: message.Topic,
        From: message.From,
        Timestamp: time.Now(),
        SeqId: t.lastID,
        Head: message.Head,
        Content: message.Content,
    },
    // Internal-only values.
    Id: message.Id,
    RcptTo: message.Topic,
    AsUser: message.From,
    Timestamp: time.Now(),
    sess: sreg.sess,
}

t.broadcastToSessions(data)
```

I did it based on the `publish` method, but for some reason the response is not coming back

Victor Login (batazor)

unread,
Oct 2, 2023, 9:49:40 AMOct 2
to Tinode General
```
sreg.sess.queueOut(&ServerComMessage{

Data: &MsgServerData{
Id:        message.Id,
Topic:     message.Topic,
From:      fmt.Sprintf("usr%s", message.From),
Timestamp: message.CreatedAt,
DeletedAt: message.DeletedAt,
SeqId:     message.SeqId,

Head:      message.Head,
Content:   message.Content,
},
})
```

I'd ideally like to get this behavior, but for all users [userUid1, userUid2, ....]

Gene

unread,
Oct 2, 2023, 12:07:59 PMOct 2
to Tinode General
I'm not sure what your question is. If you need assistance with coding or debugging your application, then we charge $225/hour, 8 hours minimum.

Victor Login (batazor)

unread,
Oct 2, 2023, 12:27:27 PMOct 2
to Tinode General
My question is, do I understand correctly that we can send messages to members by posting messages using the broadcastToSessions method?
 https://github.com/tinode/chat/blob/4184ed941080daec1bb6b7804f64fb6a4fc2818d/server/topic.go#L1252

Gene

unread,
Oct 2, 2023, 2:16:15 PMOct 2
to Tinode General
Yes, you can use broadcastToSessions to send message to currently attached sessions
Reply all
Reply to author
Forward
0 new messages