コード例 #1
0
ファイル: Message.cs プロジェクト: leancloud/csharp-sdk
        public async Task Unread()
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();
            string           clientId         = Guid.NewGuid().ToString();
            LCIMClient       client           = new LCIMClient(clientId);
            LCIMConversation conversation     = await m1.CreateConversation(new string[] { clientId });

            LCIMTextMessage textMessage = new LCIMTextMessage("hello");
            await conversation.Send(textMessage);

            client.OnUnreadMessagesCountUpdated = (convs) => {
                foreach (LCIMConversation conv in convs)
                {
                    WriteLine($"unread count: {conv.Unread}");
                    //Assert.AreEqual(conv.Unread, 1);
                    //Assert.True(conv.LastMessage is LCIMTextMessage);
                    //LCIMTextMessage textMsg = conv.LastMessage as LCIMTextMessage;
                    //Assert.AreEqual(textMsg.Text, "hello");
                }
            };
            await client.Open();

            client.OnMessage = (conv, msg) => {
                WriteLine($"unread count: {conv.Unread}");
                Assert.AreEqual(conv.Unread, 2);
                Assert.True(conv.LastMessage is LCIMTextMessage);
                LCIMTextMessage textMsg = conv.LastMessage as LCIMTextMessage;
                Assert.AreEqual(textMsg.Text, "world");
                tcs.SetResult(true);
            };
            textMessage = new LCIMTextMessage("world");
            await conversation.Send(textMessage);

            await tcs.Task;
        }
コード例 #2
0
 public void UpdateItemData(object data)
 {
     if (data is MessageEntity messageEntity)
     {
         gameObject.SetActive(true);
         user = messageEntity.User;
         LCIMTextMessage message = messageEntity.Message as LCIMTextMessage;
         chatText.text = $"{user.GetNickname()}:{message.Text}";
     }
 }
コード例 #3
0
ファイル: Message.cs プロジェクト: leancloud/csharp-sdk
        public async Task Send()
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            int count = 0;

            m2.OnMessage = (conv, msg) => {
                WriteLine(msg.Id);
                if (msg is LCIMImageMessage imageMsg)
                {
                    WriteLine($"-------- url: {imageMsg.Url}");
                    count++;
                }
                else if (msg is LCIMFileMessage fileMsg)
                {
                    WriteLine($"-------- name: {fileMsg.Format}");
                    count++;
                }
                else if (msg is LCIMTextMessage textMsg)
                {
                    WriteLine($"-------- text: {textMsg.Text}");
                    count++;
                }
                if (count >= 3)
                {
                    tcs.SetResult(null);
                }
            };

            LCIMTextMessage textMessage = new LCIMTextMessage("hello, world");
            await conversation.Send(textMessage);

            Assert.NotNull(textMessage.Id);

            LCFile           image        = new LCFile("hello", "../../../../../assets/hello.png");
            LCIMImageMessage imageMessage = new LCIMImageMessage(image);
            await conversation.Send(imageMessage);

            Assert.NotNull(imageMessage.Id);

            LCFile          file        = new LCFile("apk", "../../../../../assets/test.apk");
            LCIMFileMessage fileMessage = new LCIMFileMessage(file);
            await conversation.Send(fileMessage);

            Assert.NotNull(fileMessage.Id);

            LCIMBinaryMessage binaryMessage = new LCIMBinaryMessage(System.Text.Encoding.UTF8.GetBytes("LeanCloud"));
            await conversation.Send(binaryMessage);

            Assert.NotNull(binaryMessage.Id);

            await tcs.Task;
        }
コード例 #4
0
ファイル: Message.cs プロジェクト: leancloud/csharp-sdk
        public async Task Recall()
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            m2.OnMessageRecalled = (conv, msgId) => {
                WriteLine($"{msgId} is recalled.");
                tcs.SetResult(null);
            };
            LCIMTextMessage textMessage = new LCIMTextMessage("I will be recalled.");
            await conversation.Send(textMessage);

            await Task.Delay(1000);

            await conversation.RecallMessage(textMessage);

            await tcs.Task;
        }
コード例 #5
0
ファイル: Message.cs プロジェクト: leancloud/csharp-sdk
        public async Task MentionAll()
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            m2.OnMessage = (conv, msg) => {
                Assert.True(msg.Mentioned);
                Assert.True(msg.MentionAll);
                tcs.SetResult(null);
            };

            LCIMTextMessage textMessage = new LCIMTextMessage("world")
            {
                MentionAll = true
            };
            await conversation.Send(textMessage);

            await tcs.Task;
        }
コード例 #6
0
    public async void Send()
    {
        string content = inputField.text;

        if (string.IsNullOrEmpty(content))
        {
            return;
        }

        try {
            LCIMTextMessage message = new LCIMTextMessage(content);
            await conversation.Send(message);

            AddMessage(message);
        } catch (LCException e) {
            LCUtils.LogException(e);
        }
    }
コード例 #7
0
    public void UpdateItemData(object data)
    {
        if (data is MessageEntity messageEntity)
        {
            gameObject.SetActive(true);

            string nickname = messageEntity.User.GetNickname();
            if (nickname.Length > 0)
            {
                firstNameText.text = nickname.Substring(0, 1);
            }
            LCIMTextMessage message = messageEntity.Message as LCIMTextMessage;
            contentText.text = message.Text;

            bool isMe = messageEntity.User.IsMe();
            layoutGroup.reverseArrangement = isMe;
            layoutGroup.childAlignment     = isMe ? TextAnchor.UpperRight : TextAnchor.UpperLeft;
            contentText.alignment          = isMe ? TextAnchor.MiddleRight : TextAnchor.MiddleLeft;
        }
    }
コード例 #8
0
ファイル: Message.cs プロジェクト: leancloud/csharp-sdk
        public async Task MentionList()
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            m2.OnMessage = (conv, msg) => {
                Assert.True(msg.Mentioned);
                Assert.True(msg.MentionIdList.Contains(m2.Id));
                tcs.SetResult(null);
            };

            LCIMTextMessage textMessage = new LCIMTextMessage("hello")
            {
                MentionIdList = new List <string> {
                    m2.Id
                }
            };
            await conversation.Send(textMessage);

            await tcs.Task;
        }
コード例 #9
0
    public async void Send()
    {
        string content = inputField.text;

        if (string.IsNullOrEmpty(content))
        {
            return;
        }

        try {
            LCIMTextMessage  message      = new LCIMTextMessage(content);
            LCIMConversation conversation = await LCManager.Instance.IMClient.GetConversation(WordConversationId);

            await conversation.Send(message);

            AddMessage(message);
        } catch (LCException e) {
            LCUtils.LogException(e);
        }
    }
コード例 #10
0
ファイル: Message.cs プロジェクト: leancloud/csharp-sdk
        public async Task Attributes()
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            m2.OnMessage = (conv, msg) => {
                Assert.True(msg is LCIMTypedMessage);
                LCIMTypedMessage typedMsg = msg as LCIMTypedMessage;
                Assert.AreEqual(typedMsg["k1"], 123);
                Assert.True((bool)typedMsg["k2"]);
                Assert.AreEqual(typedMsg["k3"], "code");
                tcs.SetResult(null);
            };
            LCIMTextMessage textMsg = new LCIMTextMessage("hi");

            textMsg["k1"] = 123;
            textMsg["k2"] = true;
            textMsg["k3"] = "code";
            await conversation.Send(textMsg);

            await tcs.Task;
        }
コード例 #11
0
ファイル: Message.cs プロジェクト: leancloud/csharp-sdk
        public async Task Update()
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            m2.OnMessageUpdated = (conv, msg) => {
                Assert.True(msg is LCIMTextMessage);
                LCIMTextMessage textMessage = msg as LCIMTextMessage;
                Assert.AreEqual(textMessage.Text, "world");
                WriteLine($"{msg.Id} is updated");
                tcs.SetResult(null);
            };
            LCIMTextMessage oldMessage = new LCIMTextMessage("hello");
            await conversation.Send(oldMessage);

            await Task.Delay(1000);

            LCIMTextMessage newMessage = new LCIMTextMessage("world");
            await conversation.UpdateMessage(oldMessage, newMessage);

            await tcs.Task;
        }
コード例 #12
0
ファイル: Client.cs プロジェクト: leancloud/csharp-sdk
        public async Task CreateChatRoom()
        {
            string     clientId = Guid.NewGuid().ToString();
            LCIMClient client   = new LCIMClient(clientId);

            await client.Open();

            client.OnInvited = (conv, initBy) => {
                WriteLine($"on invited: {initBy}");
            };

            string           name         = Guid.NewGuid().ToString();
            LCIMConversation conversation = await client.CreateChatRoom(name);

            string     visitorId = Guid.NewGuid().ToString();
            LCIMClient visitor   = new LCIMClient(visitorId);

            await visitor.Open();

            LCIMChatRoom chatRoom = await visitor.GetConversation(conversation.Id) as LCIMChatRoom;

            await chatRoom.Join();

            LCIMTextMessage textMessage = new LCIMTextMessage("hello, world");
            await conversation.Send(textMessage);

            int count = await chatRoom.GetMembersCount();

            ReadOnlyCollection <string> onlineMembers = await chatRoom.GetOnlineMembers();

            Assert.GreaterOrEqual(onlineMembers.Count, 1);
            foreach (string memberId in onlineMembers)
            {
                WriteLine($"{memberId} online");
            }

            await client.Close();

            await visitor.Close();
        }
コード例 #13
0
ファイル: Message.cs プロジェクト: leancloud/csharp-sdk
        public async Task AckAndRead()
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            m2.OnMessage = async(conv, msg) => {
                await conv.Read();
            };
            m1.OnMessageDelivered = (conv, msgId) => {
                WriteLine($"{msgId} is delivered.");
            };
            m1.OnMessageRead = (conv, msgId) => {
                WriteLine($"{msgId} is read.");
                tcs.SetResult(null);
            };
            LCIMTextMessage        textMessage = new LCIMTextMessage("hello");
            LCIMMessageSendOptions options     = new LCIMMessageSendOptions {
                Receipt = true
            };
            await conversation.Send(textMessage, options);

            await tcs.Task;
        }