Go to specific seq

85 views
Skip to first unread message

Dragos

unread,
May 25, 2022, 7:30:15 AM5/25/22
to Tinode General
Hi,
Let's say that I have a chat with 500 messages, seqs going from 1 to 500.

When I first access the topic it downloads 20 messages, from 480 to 500.
Now I want to go to the message with seq 150, display it alongside 20 ealier and 20 later messages. Like 130....150...170.
Also when I scroll down it should download the next 20 messages from 171(included) to 192(excluded).

Is this possible ?

As of now I can only do it if there are no cached messages in the topic.messages(). Otherwise it will behave like this:
1. go to seq 150 and download 130 to 170
2. when I scroll down it will go from 170 to 480 and those in between won't be dowloaded

When I scroll up to get older messages it works well from 150 to 130 to 110, etc but if I scrool up from the bottom it won't download new messages and will display the 170 right before 480.

When I have a specific seq to go to I use

since= mySeq - 20
before= mySeq + 20
INITIAL_MESSAGE_COUNT = 20

getParams = topic.startMetaQuery().withLaterDesc().withSub()   getParams.withData(since, before, INITIAL_MESSAGE_COUNT)
await topic.subscribe(getParams.build(), setParams)
await topic.getMeta({ what: "desc" })





Gene

unread,
May 25, 2022, 12:21:40 PM5/25/22
to Tinode General
On Wednesday, May 25, 2022 at 4:30:15 AM UTC-7 Dragos wrote:
Hi,
Let's say that I have a chat with 500 messages, seqs going from 1 to 500.

When I first access the topic it downloads 20 messages, from 480 to 500.
Now I want to go to the message with seq 150, display it alongside 20 ealier and 20 later messages. Like 130....150...170.
Also when I scroll down it should download the next 20 messages from 171(included) to 192(excluded).

Is this possible ?

If you want custom scroll logic then you should implement it.  
Please send a pull request if you feel it's useful for most people.

Dragos

unread,
May 25, 2022, 2:58:08 PM5/25/22
to Tinode General
I am making my own client in VueJS. So there is no logic like I need already in the sdk of the react app, right ?

Gene

unread,
May 25, 2022, 3:21:54 PM5/25/22
to Tinode General
On Wednesday, May 25, 2022 at 11:58:08 AM UTC-7 Dragos wrote:
I am making my own client in VueJS. So there is no logic like I need already in the sdk of the react app, right ?

As you correctly mentioned in your first message, the SDK supports requests for arbitrary ranges withData(since, before, INITIAL_MESSAGE_COUNT) 
But if you want to detect gaps in cached message ranges then you would have to add this logic yourself.
Message has been deleted

Dragos

unread,
May 26, 2022, 3:55:43 AM5/26/22
to Tinode General
There is one more details, what if a message inside the range I request was replaced by another message(edit) with seq outside of the range I am requesting ? Is there a way to know if a message was replaced ?

For example:

I have 500 seqs.
I download from 200 to 250. The message with seq 210 was replaced by the message with seq 300 then that message was replaced by a message with seq 400(the edit was edited). Now the 210 seq message will not be replaced in the list because 210 and 300 are not present.

Similar thing with replies. A message inside the seqs could be a reply to an older message  or a message from the seqs could have as reply a message outiside the seq range. Message with seq 220 have the message with seq 260 as reply. They won't be displayed.

My ideea for these 2 problems would be to group edits and replies inside the parent message and not deliver them as normal messages on topic.onData.
message = {
<allready existing fields>
edits: [] //array of messages that are edits of the parent(replace)
reply: {} //message that is reply to the parent, the client app will handle the way the reply is displayed or replies: [] array with the messages that are replies to the parent

Gene

unread,
May 26, 2022, 11:57:44 AM5/26/22
to Tinode General
On Thursday, May 26, 2022 at 12:55:43 AM UTC-7 Dragos wrote:
There is one more details, what if a message inside the range I request was replaced by another message(edit) with seq outside of the range I am requesting ? Is there a way to know if a message was replaced ?

For example:

I have 500 seqs.
I download from 200 to 250. The message with seq 210 was replaced by the message with seq 300 then that message was replaced by a message with seq 400(the edit was edited). Now the 210 seq message will not be replaced in the list because 210 and 300 are not present.

That's not what usually happens. Usually the client downloads the latest 450-500 messages, then the previous 400-450 (or whatever the page size is), etc.
Also, most of the edits happen very quickly, usually within a few messages from the original.

If your message seq-400 is a new version of message seq-300, then you just show the seq-400, you don't need to have the seq-300 in order to show the seq-400.

In your scenario you, if you somehow get a page from the middle first, you would have to fetch seq-300 in a separate call. You can keep it in a list, like we do it here;

Similar thing with replies. A message inside the seqs could be a reply to an older message  or a message from the seqs could have as reply a message outiside the seq range. Message with seq 220 have the message with seq 260 as reply. They won't be displayed.

You would have to fetch a page to display it. Again, it's usually not a problem as most replies happen within a show time frame.
 
My ideea for these 2 problems would be to group edits and replies inside the parent message and not deliver them as normal messages on topic.onData.
message = {
<allready existing fields>
edits: [] //array of messages that are edits of the parent(replace)
reply: {} //message that is reply to the parent, the client app will handle the way the reply is displayed or replies: [] array with the messages that are replies to the parent

We considered that too, and it had a bunch of problems of its own.

Simona Stoiconi

unread,
Oct 30, 2022, 9:33:02 AM10/30/22
to Tinode General
That's not what usually happens. Usually the client downloads the latest 450-500 messages, then the previous 400-450 (or whatever the page size is), etc.
Also, most of the edits happen very quickly, usually within a few messages from the original.

This must be the first chatting app where messages gone missing is acceptable because it's usually not a problem.

Gene

unread,
Nov 1, 2022, 12:02:56 AM11/1/22
to Tinode General
On Sunday, October 30, 2022 at 6:33:02 AM UTC-7 Simona Stoiconi wrote:
That's not what usually happens. Usually the client downloads the latest 450-500 messages, then the previous 400-450 (or whatever the page size is), etc.
Also, most of the edits happen very quickly, usually within a few messages from the original.

This must be the first chatting app where messages gone missing is acceptable because it's usually not a problem.

You may want to learn the issue at hand first, then add your comments.

Simona Stoiconi

unread,
Nov 29, 2022, 12:05:13 PM11/29/22
to Tinode General
User loads first page of messages (ids 1 through 10). Message 11 is a reply to message 1. Well, too bad; that reply does not deserve to be shown.

You may want to make a better API at hand.

Gene

unread,
Nov 29, 2022, 12:10:51 PM11/29/22
to Tinode General
On Tuesday, November 29, 2022 at 9:05:13 AM UTC-8 Simona Stoiconi wrote:
User loads first page of messages (ids 1 through 10). Message 11 is a reply to message 1. Well, too bad; that reply does not deserve to be shown.

If you deliberately do a wrong thing then it should not be a surprise to you that you get a wrong result.

Gene

unread,
Nov 29, 2022, 12:14:49 PM11/29/22
to Tinode General
On Tuesday, November 29, 2022 at 9:05:13 AM UTC-8 Simona Stoiconi wrote:
User loads first page of messages (ids 1 through 10). Message 11 is a reply to message 1. Well, too bad; that reply does not deserve to be shown.

You may want to make a better API at hand.

You trying to be a part of problem as opposed as a part of a solution is your choice. If you continue to do so I will ask you to leave.
Reply all
Reply to author
Forward
0 new messages