Exemplo n.º 1
0
        public HttpStatusCodeResult Unstar(int id)
        {
            var conversation = ConversationService.Get(id);

            EntityService.Unstar(conversation);
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        public PartialViewResult PartialConversation(int id)
        {
            var model = ConversationService.Get(id);

            ViewBag.Messenger = new Messenger {
                Conversation = model
            };
            return(PartialView("_Conversation", model));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        /// <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)));
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
 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));
 }
Exemplo n.º 12
0
        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)));
        }
Exemplo n.º 13
0
        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"));
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        /// <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);
        }
Exemplo n.º 16
0
 public IHttpActionResult Read(int id)
 {
     ConversationService.SetRead(id, readAt: DateTime.UtcNow);
     return(Ok(ConversationService.Get(id)));
 }
Exemplo n.º 17
0
        public PartialViewResult PartialInfo(int id)
        {
            var model = ConversationService.Get(id);

            return(PartialView("_InfoModal", model));
        }
Exemplo n.º 18
0
 public Conversation Read(int id)
 {
     ConversationService.SetRead(id, readAt: DateTime.UtcNow);
     return(ConversationService.Get(id));
 }
Exemplo n.º 19
0
 public IHttpActionResult SetUnread(int id)
 {
     ConversationService.SetRead(id, null);
     return(Ok(ConversationService.Get(id)));
 }
Exemplo n.º 20
0
        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));
        }