public HttpStatusCodeResult Unstar(int id) { var conversation = ConversationService.Get(id); EntityService.Unstar(conversation); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public ActionResult Conversation(int id) { var model = new Messenger(); // get conversation model.Conversation = ConversationService.Get(id); if (model.Conversation == null) { ThrowResponseException(HttpStatusCode.NotFound, $"Conversation with id {id} not found"); } // mark conversation as read (if needed) if (model.Conversation.ReadAt == null) { model.Conversation = ConversationService.SetRead(id, DateTime.UtcNow); } else if (model.Conversation.LastMessage != null && model.Conversation.ReadAt < model.Conversation.LastMessage.CreatedAt) { // NOTE: do not assign the read conversation to model.Conversation since that will prevent rendering of the "New messages" separator ConversationService.SetRead(model.Conversation.Id, DateTime.UtcNow); } // get first page of messages (and reverse them for easier rendering in correct order) model.Messages = ConversationService.GetMessages(id, new QueryOptions { Top = MAX_PAGE_SIZE }); model.Messages.Reverse(); return(View(model)); }
public IHttpActionResult StopTyping(int id) { var conversation = ConversationService.Get(id); // push typing event to other conversation members PushService.PushToUsers("typing-stopped.weavy", new { Conversation = id, User = WeavyContext.Current.User, Name = WeavyContext.Current.User.Profile.Name ?? WeavyContext.Current.User.Username }, conversation.MemberIds.Where(x => x != WeavyContext.Current.User.Id)); return(Ok(conversation)); }
public async Task <HttpStatusCodeResult> Typing(int id) { var conversation = ConversationService.Get(id); // push typing event to other conversation members await PushService.PushToUsers(PushService.EVENT_TYPING, new TypingModel { Conversation = id, User = WeavyContext.Current.User }, conversation.MemberIds.Where(x => x != WeavyContext.Current.User.Id)); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public PartialViewResult PartialConversation(int id) { var model = ConversationService.Get(id); ViewBag.Messenger = new Messenger { Conversation = model }; return(PartialView("_Conversation", model)); }
public PartialViewResult PartialConversation(int id) { var model = ConversationService.Get(id); ViewBag.Messenger = new Messenger { Conversation = model, IsMessenger = IsMessenger(Request.Headers["Referer"]) }; return(PartialView("_Conversation", model)); }
/// <summary> /// Gets a conversation by its id. Throws a 404 http error if the conversation is not found. /// </summary> /// <param name="id"></param> private Conversation GetConversation(int id) { var conversation = ConversationService.Get(id); if (conversation == null) { ThrowResponseException(HttpStatusCode.NotFound, "Conversation with id " + id + " not found"); } return(conversation); }
public IHttpActionResult InsertMessage(int id, InsertMessageIn model) { var conversation = ConversationService.Get(id); if (conversation == null) { ThrowResponseException(HttpStatusCode.NotFound, "Conversation with id " + id + " not found"); } return(Ok(MessageService.Insert(new Message { Text = model.Text, }, conversation))); }
public PartialViewResult PartialMessages(int id, QueryOptions opts) { // limit page size to 25 opts.Top = Math.Min(opts.Top ?? MAX_PAGE_SIZE, MAX_PAGE_SIZE); var model = new Messenger(); model.Conversation = ConversationService.Get(id); model.Messages = ConversationService.GetMessages(model.Conversation.Id, opts); model.Messages.Reverse(); return(PartialView("_Messages", model)); }
public IHttpActionResult Get(int id) { // read conversation ConversationService.SetRead(id, DateTime.UtcNow); var conversation = ConversationService.Get(id); if (conversation == null) { ThrowResponseException(HttpStatusCode.NotFound, $"Conversation with id {id} not found."); } return(Ok(conversation)); }
public HttpStatusCodeResult Typing(int id) { if (ConfigurationService.Typing) { // push typing event to other conversation members var conversation = ConversationService.Get(id); PushService.PushToUsers(PushService.EVENT_TYPING, new TypingModel { Conversation = id, User = WeavyContext.Current.User }, conversation.MemberIds.Where(x => x != WeavyContext.Current.User.Id)); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public IHttpActionResult GetMessages(int id, QueryOptions opts) { var conversation = ConversationService.Get(id); if (conversation == null) { ThrowResponseException(HttpStatusCode.NotFound, "Conversation with id " + id + " not found"); } var messages = ConversationService.GetMessages(id, opts); messages.Reverse(); return(Ok(new ScrollableList <Message>(messages, Request.RequestUri))); }
public ActionResult SetName(int id, string name) { var conversation = ConversationService.Get(id); if (conversation == null || !conversation.IsRoom) { ThrowResponseException(HttpStatusCode.NotFound, "Conversation " + id + " not found."); } if (name.IsNullOrWhiteSpace()) { name = null; } conversation.Name = name; conversation = ConversationService.Update(conversation); // HACK: set Name to GetTitle() so that returned json has conversation title in the name property conversation.Name = conversation.GetTitle(); return(Content(conversation.SerializeToJson(), "application/json")); }
public HttpStatusCodeResult SetAvatar(int id, int?blobId) { var conversation = ConversationService.Get(id); if (conversation == null || !conversation.IsRoom) { ThrowResponseException(HttpStatusCode.NotFound, "Conversation " + id + " not found."); } if (blobId != null) { var blob = BlobService.Get(blobId.Value); conversation.Avatar = blob; } else { conversation.Avatar = null; } ConversationService.Update(conversation); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
/// <summary> /// Helper method for inserting message into specified conversation. /// </summary> /// <param name="id"></param> /// <param name="message"></param> /// <returns></returns> private Message CreateMessage(int id, MessageIn message) { Message msg = null; var conversation = ConversationService.Get(id); if (conversation == null) { ThrowResponseException(HttpStatusCode.NotFound, "Conversation with id " + id + " not found"); } // create and insert new message try { msg = MessageService.Insert(new Message { Text = message.Text }, conversation, blobs: message.Blobs, embeds: message.Embeds, meetings: message.Meetings); } catch (Exception ex) { // TODO: handle some way? _log.Warn(ex.Message); } return(msg); }
public IHttpActionResult Read(int id) { ConversationService.SetRead(id, readAt: DateTime.UtcNow); return(Ok(ConversationService.Get(id))); }
public PartialViewResult PartialInfo(int id) { var model = ConversationService.Get(id); return(PartialView("_InfoModal", model)); }
public Conversation Read(int id) { ConversationService.SetRead(id, readAt: DateTime.UtcNow); return(ConversationService.Get(id)); }
public IHttpActionResult SetUnread(int id) { ConversationService.SetRead(id, null); return(Ok(ConversationService.Get(id))); }
public ActionResult Messenger(int?id, QueryOptions opts) { // limit page size to 25 opts.Top = Math.Min(opts.Top ?? MAX_PAGE_SIZE, MAX_PAGE_SIZE); var model = new Messenger { ConversationId = id }; if (model.ConversationId != null) { // get selected conversation model.Conversation = ConversationService.Get(model.ConversationId.Value); if (model.Conversation == null) { ThrowResponseException(HttpStatusCode.NotFound, $"Conversation with id {model.ConversationId.Value} not found"); } } else { // get most recent conversation model.Conversation = ConversationService.Search(new ConversationQuery { OrderBy = "PinnedAt DESC, LastMessageAt DESC", Top = 1 }).FirstOrDefault(); } if (model.Conversation != null) { if (model.ConversationId != null) { // mark conversation as read (if needed) if (model.Conversation.ReadAt == null) { model.Conversation = ConversationService.SetRead(model.Conversation.Id, DateTime.UtcNow); } else if (model.Conversation.ReadAt < model.Conversation.LastMessage?.CreatedAt) { // NOTE: do not assign the read conversation to model.Conversation since that will prevent rendering of the "New messages" separator ConversationService.SetRead(model.Conversation.Id, DateTime.UtcNow); } } // get first page of messages (and reverse them for easier rendering in correct order) model.Messages = ConversationService.GetMessages(model.Conversation.Id, new QueryOptions { Top = MAX_PAGE_SIZE }); model.Messages.Reverse(); } // Meetings model.ZoomEnabled = ConfigurationService.ZoomMeetings; model.TeamsEnabled = ConfigurationService.TeamsMeetings; // NOTE: we load conversations last so that selected conversation does not appear unread in the list var query = new ConversationQuery(opts); query.UserId = User.Id; query.OrderBy = "PinnedAt DESC, LastMessageAt DESC"; model.Conversations = ConversationService.Search(query); // make sure selected conversation is visible in conversations list while (model.Conversation != null && !model.Conversations.Any(x => x.Id == model.Conversation.Id)) { query.Top += PageSizes.First(); model.Conversations = ConversationService.Search(query); } return(View(nameof(Messenger), model)); }