Merge branch 'dev/multiple-notes'

This commit is contained in:
Ryan Peters
2024-01-06 21:10:06 -05:00
16 changed files with 161 additions and 60 deletions

View File

@ -14,11 +14,29 @@ namespace BinaryDad.Notes
this.noteService = noteService;
}
public async Task SaveNote(string content)
public override Task OnConnectedAsync()
{
noteService.Save(content);
var noteName = Context.GetHttpContext().Request.Query["noteName"];
await Clients.Others.SendAsync("updateNote", content);
NoteContext.ClientNotes[Context.ConnectionId] = noteName;
return base.OnConnectedAsync();
}
public async Task SaveNote(string content, string? noteName)
{
noteService.SaveText(content, noteName);
// find all other connections except for the current one
var clientConnections = NoteContext.ClientNotes
.Where(c => c.Value == noteName && c.Key != Context.ConnectionId)
.Select(c => c.Key)
.ToList();
// update note for all other clients
await Clients
.Clients(clientConnections)
.SendAsync("updateNote", content);
}
}
}