tangled
alpha
login
or
join now
moth11.net
/
lrcd
2
fork
atom
websocket-based lrcproto server
2
fork
atom
overview
issues
pulls
pipelines
this should publish in progress posts on disconnect
moth11.net
6 months ago
0ff8088a
38adb092
+15
-6
1 changed file
expand all
collapse all
unified
split
server.go
+15
-6
server.go
···
211
delete(s.clients, client)
212
close(client.dataChan)
213
s.clientsMu.Unlock()
0
214
215
s.idmapsMu.Lock()
0
216
for _, id := range client.myIDs { // remove myself from the idToClient map
217
delete(s.idToClient, id)
218
}
···
306
case *lrcpb.Event_Init:
307
s.handleInit(msg, client)
308
case *lrcpb.Event_Pub:
309
-
s.handlePub(msg, client)
310
case *lrcpb.Event_Insert:
311
s.handleInsert(msg, client)
312
case *lrcpb.Event_Delete:
···
328
}
329
330
func (s *Server) handleInit(msg *lrcpb.Event_Init, client *client) {
0
331
curID := s.clientToID[client]
332
if curID != nil {
0
333
return
334
}
335
newID := s.lastID + 1
336
s.lastID = newID
337
-
s.idmapsMu.Lock()
338
s.clientToID[client] = &newID
339
s.idToClient[newID] = client
340
s.idmapsMu.Unlock()
···
391
}
392
}
393
394
-
func (s *Server) handlePub(msg *lrcpb.Event_Pub, client *client) {
0
395
curID := s.clientToID[client]
396
if curID == nil {
0
397
return
398
}
399
-
s.idmapsMu.Lock()
400
s.clientToID[client] = nil
401
s.idmapsMu.Unlock()
402
-
msg.Pub.Id = curID
403
-
event := &lrcpb.Event{Msg: msg}
404
if s.pubChan != nil {
405
select {
406
case s.pubChan <- PubEvent{ID: *curID, Body: *client.post}:
···
415
}
416
417
func (s *Server) handleInsert(msg *lrcpb.Event_Insert, client *client) {
0
418
curID := s.clientToID[client]
0
419
if curID == nil {
420
return
421
}
···
447
}
448
449
func (s *Server) handleDelete(msg *lrcpb.Event_Delete, client *client) {
0
450
curID := s.clientToID[client]
0
451
if curID == nil {
452
return
453
}
···
495
}
496
497
func (s *Server) handleEditBatch(msg *lrcpb.Event_Editbatch, client *client) {
0
498
curID := s.clientToID[client]
0
499
if curID == nil {
500
return
501
}
···
211
delete(s.clients, client)
212
close(client.dataChan)
213
s.clientsMu.Unlock()
214
+
s.handlePub(client)
215
216
s.idmapsMu.Lock()
217
+
delete(s.clientToID, client)
218
for _, id := range client.myIDs { // remove myself from the idToClient map
219
delete(s.idToClient, id)
220
}
···
308
case *lrcpb.Event_Init:
309
s.handleInit(msg, client)
310
case *lrcpb.Event_Pub:
311
+
s.handlePub(client)
312
case *lrcpb.Event_Insert:
313
s.handleInsert(msg, client)
314
case *lrcpb.Event_Delete:
···
330
}
331
332
func (s *Server) handleInit(msg *lrcpb.Event_Init, client *client) {
333
+
s.idmapsMu.Lock()
334
curID := s.clientToID[client]
335
if curID != nil {
336
+
s.idmapsMu.Unlock()
337
return
338
}
339
newID := s.lastID + 1
340
s.lastID = newID
0
341
s.clientToID[client] = &newID
342
s.idToClient[newID] = client
343
s.idmapsMu.Unlock()
···
394
}
395
}
396
397
+
func (s *Server) handlePub(client *client) {
398
+
s.idmapsMu.Lock()
399
curID := s.clientToID[client]
400
if curID == nil {
401
+
s.idmapsMu.Unlock()
402
return
403
}
0
404
s.clientToID[client] = nil
405
s.idmapsMu.Unlock()
406
+
event := &lrcpb.Event{Msg: &lrcpb.Event_Pub{Pub: &lrcpb.Pub{Id: curID}}}
0
407
if s.pubChan != nil {
408
select {
409
case s.pubChan <- PubEvent{ID: *curID, Body: *client.post}:
···
418
}
419
420
func (s *Server) handleInsert(msg *lrcpb.Event_Insert, client *client) {
421
+
s.idmapsMu.Lock()
422
curID := s.clientToID[client]
423
+
s.idmapsMu.Unlock()
424
if curID == nil {
425
return
426
}
···
452
}
453
454
func (s *Server) handleDelete(msg *lrcpb.Event_Delete, client *client) {
455
+
s.idmapsMu.Lock()
456
curID := s.clientToID[client]
457
+
s.idmapsMu.Unlock()
458
if curID == nil {
459
return
460
}
···
502
}
503
504
func (s *Server) handleEditBatch(msg *lrcpb.Event_Editbatch, client *client) {
505
+
s.idmapsMu.Lock()
506
curID := s.clientToID[client]
507
+
s.idmapsMu.Unlock()
508
if curID == nil {
509
return
510
}