//send messages in the group private async Task SendMessagesAsync(int groupNo, TextMessageContent message) { await InitGroupAsync(groupNo); var api = Global.APIBase.CreateMessageAPI(); foreach (var userInfo in GroupInfo[groupNo].Users) { var msg = new Message { EncryptedData = await userInfo.EncryptHelper.Encrypt(message), FromUserId = Me.User.UserId, ToUserId = userInfo.User.UserId, GroupId = GroupInfo[groupNo].Group.GroupId }; await api.PostMessageAsync(msg); } await GetMessagesAsync(groupNo); }
public TextMessage(string textContent) { msgtype = "text"; text = new TextMessageContent { content = textContent }; }
private void testBtn_Click(object sender, EventArgs e) { if (!ChatClient.Instance().IsLogined()) { appendLog("没有登录,无法测试"); return; } if (ChatClient.Instance().GetConnectionStatus() != ConnectionStatus.KConnectionStatusConnected) { appendLog("不在已连接状态,无法测试"); return; } appendLog("开始测试"); string currentUserId = ChatClient.Instance().GetCurrentUserId(); appendLog("当前登录用户id是:" + currentUserId); UserInfo userInfo = ChatClient.Instance().GetUserInfo(currentUserId, false); if (userInfo == null) { appendLog("当前登录用户信息为空,这可能是因为本地没有存储,协议栈会去服务器同步,同步后会通过用户信息更新回调来通知"); } else { appendLog("当前登录用户名:" + userInfo.DisplayName); } Int64 deltaTime = ChatClient.Instance().GetServerDeltaTime(); appendLog("当前设备与服务器之间的时间差为:" + deltaTime); List <ConversationInfo> convs = ChatClient.Instance().GetConversationInfos(new List <ConversationType>() { ConversationType.SingleType, ConversationType.GroupType, ConversationType.ChannelType }, new List <int>() { 0 }); appendLog("获取到 " + convs.Count() + " 条会话记录"); Conversation conv = new Conversation(ConversationType.SingleType, "cgc8c8VV", 0); ConversationInfo convInfo = ChatClient.Instance().GetConversationInfo(conv); if (convInfo != null) { appendLog("获取到一个会话记录成功"); } else { appendLog("获取到一个会话记录失败"); } List <ConversationSearchInfo> searchConvs = ChatClient.Instance().SearchConversation("hello", new List <ConversationType>() { ConversationType.SingleType, ConversationType.GroupType, ConversationType.ChannelType }, new List <int>() { 0 }); appendLog("搜索到了 " + searchConvs.Count() + " 条会话信息"); ChatClient.Instance().RemoveConversation(conv, false); appendLog("移除会话信息"); convInfo = ChatClient.Instance().GetConversationInfo(conv); if (convInfo != null) { appendLog("获取到一个会话记录成功"); } else { appendLog("获取到一个会话记录失败"); } ChatClient.Instance().SetConversationTop(conv, true, () => { appendLog("set conversation top success"); }, (int errorCode) => { appendLog("set conversation top failure " + errorCode); }); FileMessageContent fileMsg = new FileMessageContent(); fileMsg.LocalPath = "d:\\Debug.zip"; TextMessageContent txt = new TextMessageContent(); txt.Content = "你好 world"; txt.Extra = "{\"key\":\"value\"}"; ChatClient.Instance().SendMessage(conv, txt, null, 0, (long uid, long ts) => { appendLog("send success"); ChatClient.Instance().RecallMessage(uid, () => { ChatClient.Instance().GetMessageByUid(uid); }, (int errorCode) => { }); }, (int sended, int total) => { appendLog("send progress:(" + total + ":" + sended + ")"); }, (int errorcode) => { appendLog("send failure"); }); string readmefile = @"..\..\..\..\README.md"; if (!File.Exists(readmefile)) { readmefile = @"..\..\..\README.md"; } string filestr = Convert.ToBase64String(File.ReadAllBytes(readmefile)); ChatClient.Instance().UploadMedia("readme&.md", filestr, MediaType.MediaTypeFile, (string remoteUrl) => { appendLog("upload done"); }, (int sended, int total) => { appendLog("upload progress"); }, (int errorcode) => { appendLog("upload error"); }); ChatClient.Instance().CreateGroup(null, "testGroup", null, GroupType.GroupTypeRestricted, null, null, null, (string groupId) => { appendLog("create group done"); }, (int errorcode) => { appendLog("create error"); }); List <ConversationType> types = new List <ConversationType>(); types.Add(ConversationType.SingleType); types.Add(ConversationType.GroupType); List <MessageEx> messages = ChatClient.Instance().GetMessages(types, null, null, 0, 100, null); appendLog("get message count" + messages.Count()); }