public async void CreateGroupChat() { var groupChat = await client.CreateConversationAsync(members : new string[] { "Jerry", "Harry" }); await client.InviteAsync(groupChat, "Bob"); await client.KickAsync(groupChat, "Harry"); await client.LeftAsync(groupChat); }
//添加好友事件监听(好友邀请事件:同意,拒绝,好友邀请反馈事件:同意) private void OnInvited(object sender, AVIMOnInvitedEventArgs e) { //排除自身引发的事件 if (e.InvitedBy != AVUser.CurrentUser.ObjectId) { App.Current.Dispatcher.Invoke((Action)(async() => { AVIMConversation InvitedConversation = await User.GetConversationAsync(e.ConversationId); AVUser InvitedUser = await AVUser.Query.GetAsync(e.InvitedBy); //好友邀请事件 if (InvitedConversation.IsUnique) { //同意 if (MessageBox.Show(InvitedUser.Username + "请求添加您为好友,是否通过?", "添加好友请求", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { //将对方加入自己的FriendsConversation await User.InviteAsync(FriendsConversation, e.InvitedBy); //重新获取FriendsConversation==》不必要 FriendsConversation = await User.GetConversationAsync(AVUser.CurrentUser.Get <string>("Friends")); //重新绑定listbox数据 BindingFriendListSrouce(e.InvitedBy); } //拒绝 else { //拒绝即为删除邀请者创建的Conversation try { List <string> members = new List <string>(); members.Add(AVUser.CurrentUser.ObjectId); members.Add(InvitedUser.ObjectId); await(await AVObject.GetQuery("_Conversation").WhereEqualTo("m", members).FirstAsync()).DeleteAsync(); } catch { try { List <string> members = new List <string>(); members.Add(InvitedUser.ObjectId); members.Add(AVUser.CurrentUser.ObjectId); await(await AVObject.GetQuery("_Conversation").WhereEqualTo("m", members).FirstAsync()).DeleteAsync(); } catch { MessageBox.Show("给舔狗一条活路吧"); } } finally { new Tip("提醒", "已拒绝 " + InvitedUser.Username + "的好友邀请", 3); } } } //好友邀请反馈事件:同意 if (!InvitedConversation.IsUnique) { //将对方加入自己的FriendsConversation if (!FriendsConversation.MemberIds.Contains(e.InvitedBy)) { new Tip("提醒", "已成功添加 " + InvitedUser.Username); await User.InviteAsync(FriendsConversation, e.InvitedBy); //重新获取FriendsConversation==》不必要 FriendsConversation = await User.GetConversationAsync(AVUser.CurrentUser.Get <string>("Friends")); //重新绑定listbox数据 BindingFriendListSrouce(e.InvitedBy); } } })); } }