Example #1
0
        public async Task <ActionResult> updateChatroom(string activityId, string memberId)
        {
            await InitializationModel();

            try
            {
                int index = 0;
                _activityHandler.InitializeChatroom(activityId, await _databaseSystem.GetChatData(activityId));
                List <Message> messages = _activityHandler.GetChatData(activityId);
                // 清除黑名單人員的訊息
                while (messages.Count > index)
                {
                    if (_memberHandler.IsBlack(memberId, messages[index].MemberId))
                    {
                        messages.RemoveAt(index);
                    }
                    else
                    {
                        index++;
                    }
                }
                return(Json(new { success = true, responseText = messages }, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json(new { success = false, responseText = "連結聊天室失敗" }, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
        public async Task GetChatDataTest()
        {
            DatabaseSystem databaseSystem = new DatabaseSystem();
            List <Message> messages       = new List <Message>();

            Message  message  = new Message("unitTest1", "unitTest1", "unitTestMessage");
            Activity activity = new Activity();

            activity.ActivityId     = "99";
            activity.ActivityName   = "unitTest2";
            activity.HomeOwnerId    = "unitTest1";
            activity.ActivityDate   = "2020/02/02";
            activity.ActivityNote   = "unitTest";
            activity.NumberOfPeople = "3";
            await databaseSystem.InsertActivity(activity);

            await databaseSystem.SendMessage("99", message);

            messages = await databaseSystem.GetChatData("99");

            await databaseSystem.Delete("99", "Activity");

            Assert.AreEqual("unitTest1", messages[0].MemberId);
        }