Ejemplo n.º 1
0
        public void AddChannel(ChannelType type, string id, string name)
        {
            Log((id != name && !string.IsNullOrEmpty(name))
                ? $"Making {type} Channel {id} \"{name}\""
                : $"Making {type} Channel {id}");

            if (type == ChannelType.PrivateMessage)
            {
                var character = characters.Find(id);

                character.GetAvatar(); // make sure we have their picture

                // model doesn't have a reference to PrivateMessage channels, build it manually
                var temp = new PmChannelModel(character);
                container.RegisterInstance(temp.Id, temp);
                container.Resolve <PmChannelViewModel>(new ParameterOverride("name", temp.Id));

                Dispatcher.Invoke(() => cm.CurrentPms.Add(temp));
                // then add it to the model's data

                ApplicationSettings.RecentCharacters.BacklogWithUpdate(id, MaxRecentTabs);
                SettingsService.SaveApplicationSettingsToXml(cm.CurrentCharacter.Name);
            }
            else
            {
                GeneralChannelModel temp;
                if (type == ChannelType.Utility)
                {
                    // our model won't have a reference to home, so we build it manually
                    temp = new GeneralChannelModel(id, ChannelType.Utility);
                    container.RegisterInstance(id, temp);
                    container.Resolve <HomeChannelViewModel>(new ParameterOverride("name", id));
                }
                else
                {
                    // our model should have a reference to other channels though
                    temp = cm.AllChannels.FirstOrDefault(param => param.Id == id);

                    if (temp == null)
                    {
                        temp = new GeneralChannelModel(id, name,
                                                       id == name ? ChannelType.Public : ChannelType.Private);
                        Dispatcher.Invoke(() => cm.AllChannels.Add(temp));
                    }

                    Dispatcher.Invoke(() => cm.CurrentChannels.Add(temp));

                    container.Resolve <GeneralChannelViewModel>(new ParameterOverride("name", id));

                    ApplicationSettings.RecentChannels.BacklogWithUpdate(id, MaxRecentTabs);
                    SettingsService.SaveApplicationSettingsToXml(cm.CurrentCharacter.Name);
                }

                if (!cm.CurrentChannels.Contains(temp))
                {
                    Dispatcher.Invoke(() => cm.CurrentChannels.Add(temp));
                }
            }
        }
Ejemplo n.º 2
0
        public void CanFindCharacter()
        {
            SignOnAllTestCharacters();

            var result = characters.Find(interestedCharacter.Name);

            Assert.IsTrue(result.NameEquals(interestedCharacter.Name));
            Assert.IsTrue(result.Status == StatusType.Looking);
            Assert.IsTrue(result.StatusMessage.Equals("Looking for you!"));

            result = characters.Find("Someone not online");
            Assert.IsTrue(result.NameEquals("Someone not online"));
            Assert.IsFalse(result.Status == StatusType.Online);
            Assert.IsFalse(result.StatusMessage.Any());
        }
Ejemplo n.º 3
0
        public bool IsDuplicateAd(string name, string message)
        {
            if (!ApplicationSettings.AllowAdDedup)
            {
                return(false);
            }

            var character = characters.Find(name);

            if (character.LastAd != null && (ApplicationSettings.AllowAggressiveAdDedup || character.LastAd == message))
            {
                Logging.Log("Duplicate ad from " + name);
                return(true);
            }

            character.LastAd = message;
            return(false);
        }
Ejemplo n.º 4
0
        private void GetNotesAsyncHandler(object s, DoWorkEventArgs e)
        {
            var characterName = (string)e.Argument;

            var notes = new List <IMessage>();

            var resp = browser.GetResponse(Constants.UrlConstants.ViewHistory + characterName, true);

            var htmlDoc = new HtmlDocument
            {
                OptionCheckSyntax = false
            };

            HtmlNode.ElementsFlags.Remove("option");
            htmlDoc.LoadHtml(resp);

            if (htmlDoc.DocumentNode == null)
            {
                return;
            }

            var title = string.Empty;
            {
                var titleInput = htmlDoc.DocumentNode.SelectSingleNode(NoteTitleXpath);

                if (titleInput != null)
                {
                    var value = titleInput.Attributes
                                .Where(x => x.Name == "value")
                                .Select(x => x.Value)
                                .FirstOrDefault();

                    title = value ?? title;

                    // our title will get escaped each time it is sent with entities in it
                    // so try and decode it until there's none left
                    bool hasEscaped;
                    do
                    {
                        var escaped = HttpUtility.HtmlDecode(title);
                        hasEscaped = escaped != title;
                        title      = escaped;
                    } while (hasEscaped);
                    Log($"note subject to {characterName} is {title}");
                }
            }

            var sourceId = string.Empty;
            {
                var sourceIdInput =
                    htmlDoc.DocumentNode.SelectSingleNode(string.Format(NoteIdXpath, cm.CurrentCharacter.Name));

                if (sourceIdInput != null)
                {
                    var value = sourceIdInput.Attributes
                                .Where(x => x.Name.Equals("value"))
                                .Select(x => x.Value)
                                .FirstOrDefault();

                    sourceId = value ?? sourceId;
                    Log($"ID for sending notes to {characterName} is {sourceId}");
                }
            }


            var result = htmlDoc.DocumentNode.SelectNodes(NoteXpath);
            {
                if (result != null && result.Count > 0)
                {
                    Log($"parsing note history for {characterName}, {result.Count} items");
                    result.Select(x =>
                    {
                        Log(x.InnerText);
                        var isFuzzyTime = true;
                        var split       = x.InnerText.Split(new[] { "sent,", "ago:" }, 3,
                                                            StringSplitOptions.RemoveEmptyEntries);
                        if (split.Length < 3)
                        {
                            split    = amPmRegex.Split(x.InnerText, 3).ToArray();
                            split[1] = split[1] + split[2];
                            split[2] = split[3];
                            split[3] = null;

                            isFuzzyTime = false;
                        }

                        return(new MessageModel(
                                   characters.Find(split[0].Trim()),
                                   HttpUtility.HtmlDecode(split[2]),
                                   isFuzzyTime ? FromFuzzyString(split[1].Trim()) : FromExactString(split[1].Trim())));
                    })
                    .Each(notes.Add);
                }

                noteCache.Add(characterName,
                              new Conversation
                {
                    Messages = notes,
                    Subject  = title,
                    SourceId = sourceId
                });

                try
                {
                    var model = container.Resolve <PmChannelModel>(characterName);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        model.Notes.Clear();
                        model.Notes.AddRange(notes);
                        model.NoteSubject = title;
                    });
                }
                catch
                {
                }
            }
        }