/// <summary> /// 根据成员名字组成默认群名 /// </summary> /// <returns></returns> private string GetNewGroupName() { var newName = string.Empty; var newNameBd = new StringBuilder(); var nameList = GroupMemberList.Select(c => c.User.userName).ToArray(); foreach (var name in nameList) { if (newNameBd.Length >= 10) { break; } else { newNameBd.Append(name + ","); } } newName = newNameBd.ToString().Substring(0, 10) + "..."; return(newName); }
//public string NewGroupPicture; /// <summary> /// 更新讨论组 /// </summary> private void UpdateGroup() { if (GroupInfo == null) { return; } AntSdkUpdateGroupInput input = new AntSdkUpdateGroupInput(); input.userId = AntSdkService.AntSdkLoginOutput.userId; input.groupId = this.GroupInfo.groupId; NewGroupMemberList = new List <AntSdkContact_User>(); foreach (ContactInfoViewModel vm in GroupMemberList) { if (!OriginalMemberIds.Contains(vm.User.userId)) { if (input.userIds == null) { input.userIds = new List <string>(); } input.userIds.Add(vm.User.userId); if (input.userNames == null) { input.userNames = new List <string>(); } input.userNames.Add(vm.User.userName); NewGroupMemberList.Add(vm.User); } } if (NewGroupMemberList.Count != 0) { BaseOutput output = new BaseOutput(); var errCode = 0; string errMsg = string.Empty; //TODO:AntSdk_Modify //DONE:AntSdk_Modify var isResult = AntSdkService.UpdateGroup(input, ref errCode, ref errMsg); if (!isResult) { NewGroupMemberList = null; MessageBoxWindow.Show(errMsg, GlobalVariable.WarnOrSuccess.Warn); return; } //if (!(new HttpService()).UpdateGroup(input, ref output, ref errMsg)) //{ // NewGroupMemberList = null; // if (output.errorCode != "1004") // { // MessageBoxWindow.Show(errMsg,GlobalVariable.WarnOrSuccess.Warn); // } // return; // //OnUpdateGroupEvent(input.groupId, input.userIds); //} string[] ThreadParams = new string[3]; ThreadParams[0] = this.GroupInfo.groupId; ThreadParams[1] = ImageHandle.GetGroupPicture(GroupMemberList.Select(c => c.Photo).ToList()); ThreadParams[2] = string.IsNullOrEmpty(this.GroupInfo.groupName) ? "" : this.GroupInfo.groupName; Thread UpdateGroupPictureThread = new Thread(GroupPublicFunction.UpdateGroupPicture); UpdateGroupPictureThread.Start(ThreadParams); //this.NewGroupPicture = input.groupPicture; } App.Current.Dispatcher.BeginInvoke((Action)(() => { this.close.Invoke(); })); }
private void CreateGroup() { // 讨论组名不能为空 //if (string.IsNullOrWhiteSpace(GroupName)) //{ // GroupNameBorderBrush = new SolidColorBrush(Colors.Red); // //GroupNameBorderThickness = new Thickness(1, 1, 1, 1); // return; //} //else //{ // GroupNameBorderBrush = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#e0e0e0")); // //GroupNameBorderThickness = new Thickness(0); //} // 讨论组成员不能少于3 if (GroupMemberList == null || GroupMemberList.Count < 3) { MessageBoxWindow.Show("讨论组至少需要包括三个成员", GlobalVariable.WarnOrSuccess.Warn); return; } if (string.IsNullOrWhiteSpace(GroupName.Trim(' ')))//自定义群名为空 取默认值 { GroupName = GetNewGroupName(); } GroupName = GroupName.TrimStart(' '); #region 旧代码 CreateGroupInput input = new CreateGroupInput(); input.token = AntSdkService.AntSdkLoginOutput.token; input.version = GlobalVariable.Version; input.userId = AntSdkService.AntSdkLoginOutput.userId; input.groupName = GroupName; //获取讨论组成员头像 //List<string> picList = new List<string>(); //foreach (ContactInfoViewModel m in GroupMemberList) //{ // picList.Add(m.Photo); //} //input.groupPicture = ImageHandle.GetGroupPicture(picList); //input.groupPicture =; input.userIds = string.Join(",", GroupMemberList.Select(c => c.User.userId).ToArray()); //CreateGroupOutput output = new CreateGroupOutput(); var errCode = 0; var errMsg = string.Empty; //if (!(new HttpService()).CreateGroup(input, ref output, ref errMsg)) //{ // if (output.errorCode != "1004") // { // MessageBoxWindow.Show(errMsg,GlobalVariable.WarnOrSuccess.Warn); // } // return; //} //output.group.groupPicture = ImageHandle.GetGroupPicture(GroupMemberList.Select(c => c.Photo).ToList()); //ThreadPool.QueueUserWorkItem(m => //{ //}); #endregion AntSdkCreateGroupInput newGroupInput = new AntSdkCreateGroupInput(); newGroupInput.userId = AntSdkService.AntSdkLoginOutput.userId; newGroupInput.groupName = GroupName; newGroupInput.userIds = GroupMemberList.Select(c => c.User.userId).ToArray(); //newGroupInput.groupPicture = ImageHandle.GetGroupPicture(GroupMemberList.Select(c => c.Photo).ToList()); //TODO:AntSdk_Modify //DONE:AntSdk_Modify AntSdkCreateGroupOutput createGroupOutput = AntSdkService.CreateGroup(newGroupInput, ref errCode, ref errMsg); if (createGroupOutput == null) { if (!AntSdkService.AntSdkIsConnected) { errMsg = "网络已断开,请检查网络"; } if (!string.IsNullOrEmpty(errMsg)) { MessageBoxWindow.Show(errMsg, GlobalVariable.WarnOrSuccess.Warn); } return; } createGroupOutput.groupPicture = ImageHandle.GetGroupPicture(GroupMemberList.Select(c => c.Photo).ToList()); //异步更新讨论组头像,这里需要用前台线程,因此不能用线程池 string[] ThreadParams = new string[3]; ThreadParams[0] = createGroupOutput.groupId; ThreadParams[1] = createGroupOutput.groupPicture; ThreadParams[2] = string.IsNullOrEmpty(createGroupOutput.groupName) ? "" : createGroupOutput.groupName; Thread UpdateGroupPictureThread = new Thread(GroupPublicFunction.UpdateGroupPicture); UpdateGroupPictureThread.Start(ThreadParams); this.CreateGroupOutput = createGroupOutput; App.Current.Dispatcher.BeginInvoke((Action)(() => { this.close.Invoke(); })); }