Skip to content

Instantly share code, notes, and snippets.

@dalyons
Last active August 29, 2015 14:02
Show Gist options
  • Save dalyons/f184fe48b908a9f1749e to your computer and use it in GitHub Desktop.
Save dalyons/f184fe48b908a9f1749e to your computer and use it in GitHub Desktop.
gapped messages
//so this was built for a different style of API (typed objects, can choose client list object renderer based on type)
// example url: /coversation/:id/messages
[
{
type: 'application/vnd.text.message+json',
id: 123,
text: "whatevs",
seq: 1234
},
{
type: 'application/vnd.image.message+json',
id: 122,
text: "really",
seq: 1233
},
//... 20 more messages
{
type: 'application/vnd.gap+json',
seq: 1232,
count: 1200,
// Could use a href here instead of just providing the params, but we dont use hrefs for much else in API.
params: {
since_seq: 0,
max_seq: 1232
}
// Which you use to build an api call like: 'http://someapi.com/conversation/:id/messages?since_seq=0&max_seq=1232'
}
]
/*
- The client caches the gap object in the same list backing, in the server given order.
- The gap object can be represented visually as a split, ala Twitter, showing the count of messages 'skipped' by the gap.
- When clients click on the gap(or whatever), it expands in place, by fetching the href of the gap object and inserting
the returned items in the list in place of the gap.
- The 'gap expansion' href can also return a new gap at the end of the list, if there's say 100s of items. That way,
the gap can be continiously expanded by the client until the user dosent care to anymore, or there's no more gaps.
- This response includes a http header for getting new items since the ones returned in this set,
which clients would use for updates (eg pull to update).
eg Link: "http://blah.com/conversations/:id/messages?since_seq=1234 rel=new"
- Note that the 'new' response *may also include a gap*, if too many new messages have been posted since last update.
clients usually end up with lists like this:
| m | m | m | m | m | m | m | m | m | m | G
although in a fast moving stream, this often happens:
| m | m | m | m | m | m | m | m | m | m | G | m | m | m | m | m | m | m | m | m | m | G
In either case, the clients have an easy way to track & optionally load whatever message gaps they see in a message stream.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment