MCPcopy Create free account
hub / github.com/daodst/chat / NewStreamTokenFromString

Function NewStreamTokenFromString

syncapi/types/types.go:282–320  ·  view source on GitHub ↗
(tok string)

Source from the content-addressed store, hash-verified

280}
281
282func NewStreamTokenFromString(tok string) (token StreamingToken, err error) {
283 if len(tok) < 1 {
284 err = ErrMalformedSyncToken
285 return
286 }
287 if tok[0] != SyncTokenTypeStream[0] {
288 err = ErrMalformedSyncToken
289 return
290 }
291 // Migration: Remove everything after and including '.' - we previously had tokens like:
292 // s478_0_0_0_0_13.dl-0-2 but we have now removed partitioned stream positions
293 tok = strings.Split(tok, ".")[0]
294 parts := strings.Split(tok[1:], "_")
295 var positions [9]StreamPosition
296 for i, p := range parts {
297 if i >= len(positions) {
298 break
299 }
300 var pos int
301 pos, err = strconv.Atoi(p)
302 if err != nil {
303 err = ErrMalformedSyncToken
304 return
305 }
306 positions[i] = StreamPosition(pos)
307 }
308 token = StreamingToken{
309 PDUPosition: positions[0],
310 TypingPosition: positions[1],
311 ReceiptPosition: positions[2],
312 SendToDevicePosition: positions[3],
313 InvitePosition: positions[4],
314 AccountDataPosition: positions[5],
315 DeviceListPosition: positions[6],
316 NotificationDataPosition: positions[7],
317 PresencePosition: positions[8],
318 }
319 return token, nil
320}
321
322// PrevEventRef represents a reference to a previous event in a state event upgrade
323type PrevEventRef struct {

Callers 2

TestSyncTokensFunction · 0.85
UnmarshalTextMethod · 0.85

Calls 2

StreamPositionTypeAlias · 0.85
SplitMethod · 0.80

Tested by 1

TestSyncTokensFunction · 0.68