/// <summary> /// gathers list of a supergroup chat memnbers /// </summary> /// <param name="superGroupId">supergroupId to gathering it's chats</param> /// <param name="timeOut">timeout in milliseconds for operations</param> /// <returns>list of chat members</returns> private async Task <List <ChatMember> > getSuperGroupChatMembers(long superGroupId, int timeOut = 30000) { // response object to return List <ChatMember> chatMembers = new List <ChatMember>(); int limit = 200; while (true) { // gatering chat members [ skipping gathered users count which means offset ] var res = await _api .executeCommand(new GetSupergroupMembers(superGroupId, null, chatMembers.Count, limit), typeof(ChatMembers), timeOut); // check if response gathered successfully if (res.status != Enum.ResponseStatus.Success) { break; } // casting response ChatMembers members = res.obj as ChatMembers; // check if we reached end of list if (members.Members.Length <= 0) { break; } // adding members chatMembers.AddRange(members.Members); await Task.Delay(250); } return(chatMembers); }
public async Task <IActionResult> AddUserToChat(string chatId, AddUserToChatRequest request) { using (var db = ArangoDatabase.CreateWithSetting()) { var usersInChatGraph = db.Graph("ChatsUserGraph"); var edge = new ChatMembers { Chat = chatId, User = request.UserId }; await usersInChatGraph.InsertEdgeAsync <ChatMembers>(edge); return(Ok()); } }
public override string ToString() { var sb = new StringBuilder("GetJoinedSquareChatsResponse("); bool __first = true; if (Chats != null && __isset.chats) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Chats: "); Chats.ToString(sb); } if (ChatMembers != null && __isset.chatMembers) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("ChatMembers: "); ChatMembers.ToString(sb); } if (Statuses != null && __isset.statuses) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Statuses: "); Statuses.ToString(sb); } if (ContinuationToken != null && __isset.continuationToken) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("ContinuationToken: "); ContinuationToken.ToString(sb); } sb.Append(")"); return(sb.ToString()); }
public Command(Skype skype, string commandPreffix, ChatMessage msg) { this.Skype = skype; var text = msg.Body.Substring(commandPreffix.Length); var pieces = text.Split(' '); Name = pieces.First(); Arguments = pieces.Skip(1).ToArray(); ArgumentsText = String.Join(" ", pieces.Skip(1)); ChatMembers = msg.Chat.MemberObjects.OfType <IChatMember>() .Select(o => new ChatMember { Handle = o.Handle }) .ToList(); SenderUser = msg.Sender; SenderMember = ChatMembers.FirstOrDefault(m => m.Handle == SenderUser.Handle); Message = msg; }
public async Task <IActionResult> CreateChat(CreateChatRequest request) { using (var db = ArangoDatabase.CreateWithSetting()) { var user = await db.Query <User>() .Where(u => u.Key == HttpContext.User.Identity.Name) .Select(u => u) .FirstOrDefaultAsync(); var group = await db.Query <Group>() .Where(g => g.Key == request.ProjectId) .Select(g => g) .FirstOrDefaultAsync(); if (user == null || group == null) { return(BadRequest()); } var rootGroup = await Database.GetRootGroup(request.ProjectId); var chat = new Chat { Name = request.Name, Messages = new List <Message>(), IsGroup = request.IsGroup, ProjectId = rootGroup.Key }; var createdChat = await db.InsertAsync <Chat>(chat); var usersInChatGraph = db.Graph("ChatsUsersGraph"); var userToAdd = new ChatMembers { Chat = createdChat.Id, User = user.Id }; await usersInChatGraph.InsertEdgeAsync <ChatMembers>(userToAdd); var notificationMessage = $"{user.Username} te ha agregado al chat {chat.Name} en el proyecto {group.Name}"; foreach (var userId in request.Members) { var memberUser = Database.Query <User>().Where(u => u.Key == userId).Select(u => u).FirstOrDefault(); if (memberUser?.Key == HttpContext.User.Identity.Name) { continue; } userToAdd = new ChatMembers { Chat = createdChat.Id, User = $"User/{userId}" }; await usersInChatGraph.InsertEdgeAsync <ChatMembers>(userToAdd); var notification = new Notification { Read = false, Message = notificationMessage, Priority = NotificationPriority.Medium, Context = $"project/{rootGroup.Key}/messages" }; await NotificationHub.Clients .Group($"User/{userId}") .SendAsync("notificationReceived", notification); memberUser?.Notifications.Add(notification); await db.UpdateByIdAsync <User>(memberUser?.Id, memberUser); } return(Ok()); } }