sql server - Storing chat conversations in sql database using signalR -


i'm developing class library contains generic methods these scenarios:

  • live support chat (1 on 1 private text chat, many admins , guests)
  • rooms many users can send broadcast , private messages

these 2 features above implemented , it's necessary application save messages.

my question is, best way store chat conversations in sql database:

  1. everytime click send, insert message in database?

  2. create list each user , everytime click send, message saved on list of user sent message. if user disconnects, i'm going iterate list of messages , each message insert of them in db.

are there other solutions?

what i'm doing following. have method located on hub class:

public void savemessagetodb(string username, string message) {     var ctx = new testentities1();      var msg = new tbl_conversation {msg = message};     ctx.tbl_conversation.add(msg);      ctx.savechanges();            } 

i call method savemessagetodb on client side html file this:

$('#btnsendmessage').click(function () {        var msg = $("#txtmessage").val();         if (msg.length > 0) {             var username = $('#husername').val();            // <<<<<-- ***** return server [  savemessagetodb  ] *****            objhub.server.savemessagetodb(username, msg); 

if decide store chats in database, need insert/update messages happen.

if using persistentconnection can hook onreceivedasync event , insert / update data event:

protected override task onconnectedasync(irequest request, string connectionid) {     _clients.add(connectionid, string.empty);     chatdata chatdata = new chatdata("server", "a new user has joined room.");     return connection.broadcast(chatdata); } 

or in signalr class inherits hub, can persist db right before have notified clients.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -