Exemplo n.º 1
0
        public override void OpenChat(FrontendManager fm, ChatModel chat_)
        {
            Trace.Call(fm, chat_);

            var room = Rooms.Single(r => r.Name.Equals(chat_.Name));

            Client.Post <object>(String.Format("/room/{0}/join.json", room.Id), null);
            room = Client.Get <RoomResponse>(String.Format("/room/{0}.json", room.Id)).Room;
            var chat = Session.GetChat(room.Name, ChatType.Group, this) as GroupChatModel;

            if (chat == null)
            {
                chat = Session.CreateChat <GroupChatModel>(room.Id.ToString(), room.Name, this);
            }

            var bld = CreateMessageBuilder();

            bld.AppendMessage(room.Topic);
            chat.Topic = bld.ToMessage();

            Session.AddChat(chat);

            /* Fill what we know about the users, this is only the currently-connected ones */
            lock (Users) {
                foreach (User user in room.Users)
                {
                    if (!Users.ContainsKey(user.Id))
                    {
                        Users[user.Id] = CreatePerson(user);
                    }
                    Session.AddPersonToGroupChat(chat, Users[user.Id]);
                }
            }

            /* Show the recent messages, then go live. FIXME: race condition */
            var recent = Client.Get <MessagesResponse>(String.Format("/room/{0}/recent.json", chat.ID)).Messages;

            foreach (Message message in recent)
            {
                ShowMessage(this, new MessageReceivedEventArgs(chat, message));
            }

            Session.SyncChat(chat);
            chat.IsSynced = true; // Let the part and join messages take affect

            var stream = new CampfireEventStream(chat, BaseUri, new NetworkCredential(Key, "X"));

            lock (EventStreams)
                EventStreams.Add(chat, stream);

            stream.MessageReceived += ShowMessage;
            stream.ErrorReceived   += ShowError;
            stream.Start();
        }
Exemplo n.º 2
0
        public override void OpenChat(FrontendManager fm, ChatModel chat_)
        {
            Trace.Call(fm, chat_);

            var room = Rooms.Single(r => r.Name.Equals(chat_.Name));
            Client.Post<object>(String.Format("/room/{0}/join.json", room.Id), null);
            room = Client.Get<RoomResponse>(String.Format("/room/{0}.json", room.Id)).Room;
            var chat = Session.GetChat(room.Name, ChatType.Group, this) as GroupChatModel;
            if (chat == null)
                chat = Session.CreateChat<GroupChatModel>(room.Id.ToString(), room.Name, this);

            var bld = CreateMessageBuilder();
            bld.AppendMessage(room.Topic);
            chat.Topic = bld.ToMessage();

            Session.AddChat(chat);

            /* Fill what we know about the users, this is only the currently-connected ones */
            lock (Users) {
                foreach (User user in room.Users) {
                    if (!Users.ContainsKey(user.Id))
                        Users[user.Id] = CreatePerson(user);
                    Session.AddPersonToGroupChat(chat, Users[user.Id]);
                }
            }

            /* Show the recent messages, then go live. FIXME: race condition */
            var recent = Client.Get<MessagesResponse>(String.Format("/room/{0}/recent.json", chat.ID)).Messages;
            foreach (Message message in recent)
                ShowMessage(this, new MessageReceivedEventArgs(chat, message));

            Session.SyncChat(chat);
            chat.IsSynced = true; // Let the part and join messages take affect

            var stream = new CampfireEventStream(chat, BaseUri, new NetworkCredential(Key, "X"));
            lock (EventStreams)
                EventStreams.Add(chat, stream);

            stream.MessageReceived += ShowMessage;
            stream.ErrorReceived += ShowError;
            stream.Start();
        }