public static void PublishChatMessages(this BahamutPubSubService service, ObjectId senderId, ShareChat chat, ChatMessage msg)
        {
            foreach (var user in chat.UserIds)
            {
                if (user != senderId)
                {

                    var idstr = user.ToString();
                    var cacheModel = new BahamutCacheModel
                    {
                        AppUniqueId = Startup.Appname,
                        CacheDateTime = DateTime.UtcNow,
                        UniqueId = idstr,
                        DeserializableString = msg.Id.ToString(),
                        Type = ChatMessage.NotifyType,
                        ExtraInfo = chat.Id.ToString()
                    };
                    Startup.ServicesProvider.GetBahamutCacheService().PushCacheModelToList(cacheModel);
                    var pbModel = new BahamutPublishModel
                    {
                        NotifyType = "Toronto",
                        ToUser = idstr,
                        CustomCmd = "UsrNewMsg",
                        NotifyInfo = JsonConvert.SerializeObject(new { LocKey = "NEW_MSG_NOTIFICATION" })
                    };
                    Startup.ServicesProvider.GetBahamutPubSubService().PublishBahamutUserNotifyMessage(PublishConstants.NotifyId, pbModel);
                }
            }
        }
Esempio n. 2
0
 public async Task<ShareChat> GetOrCreateChat(string chatId, string userId, string shareId,  string audienceId)
 {
     
     try
     {
         var chat = await ChatCollection.Find(m => m.ChatId == chatId).SingleAsync();
         return chat;
     }
     catch (Exception)
     {
         var newChat = new ShareChat()
         {
             ChatId = chatId,
             ShareId = new ObjectId(shareId),
             Time = DateTime.UtcNow,
             UserIds = new ObjectId[] { new ObjectId(userId), new ObjectId(audienceId) }
         };
         await ChatCollection.InsertOneAsync(newChat);
         return newChat;
     }
     
 }