Пример #1
0
        /// <summary>
        /// Add relation ship to Panel
        /// </summary>
        private async Task AddRelationshipToUI(Gateway.GatewayEventArgs <Friend> e)
        {
            // Run on UI thread
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                      async() =>
            {
                // Create SimpleFriend Object
                SimpleFriend sfriend = await NewSF(e.EventData);

                // Add to appropiate list(s)
                if (sfriend.RelationshipStatus == 1)
                {
                    AllView.Items.Add(sfriend);
                }
                else if (sfriend.RelationshipStatus == 2)
                {
                    BlockedView.Items.Add(sfriend);
                }
                else if (sfriend.RelationshipStatus == 3 || sfriend.RelationshipStatus == 4)
                {
                    if (sfriend.RelationshipStatus == 3)
                    {
                        FriendNotification(sfriend.User);
                    }
                    App.FriendNotifications += 1;
                    App.UpdateUnreadIndicators();
                    PendingCounter.Text = App.FriendNotifications.ToString();
                    PendingView.Items.Add(sfriend);
                }
            });
        }
Пример #2
0
 private static void Gateway_GuildUpdated(object sender, Gateway.GatewayEventArgs <SharedModels.Guild> e)
 {
     if (LocalState.Guilds.ContainsKey(e.EventData.Id))
     {
         App.GuildUpdated(e.EventData);
     }
 }
Пример #3
0
        /// <summary>
        /// Remove user from Panel
        /// </summary>
        private async Task RemoveRelationshipFromUI(Gateway.GatewayEventArgs <Friend> e)
        {
            // Run on UI thread
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                      () =>
            {
                // Item from All View
                var insideAllView = AllView.Items.FirstOrDefault(x => (x as SimpleFriend).User.Id == e.EventData.Id);
                if (insideAllView != null)
                {
                    AllView.Items.Remove(insideAllView);
                }

                // Remove from Pending View
                var insidePendingView = PendingView.Items.FirstOrDefault(x => (x as SimpleFriend).User.Id == e.EventData.Id);
                if (insidePendingView != null)
                {
                    PendingView.Items.Remove(insidePendingView);
                    App.FriendNotifications -= 1;
                    PendingCounter.Text      = App.FriendNotifications.ToString();
                }

                // Remove from Blocked View
                var insideBlockedView = BlockedView.Items.FirstOrDefault(x => (x as SimpleFriend).User.Id == e.EventData.Id);
                if (insideBlockedView != null)
                {
                    BlockedView.Items.Remove(insideBlockedView);
                }
            });
        }
Пример #4
0
 private static void Gateway_RelationShipUpdated(object sender, Gateway.GatewayEventArgs <SharedModels.Friend> e)
 {
     if (LocalState.Friends.ContainsKey(e.EventData.Id))
     {
         LocalState.Friends[e.EventData.Id] = e.EventData;
     }
 }
Пример #5
0
 private static void Gateway_SessionReplaced(object sender, Gateway.GatewayEventArgs <Gateway.DownstreamEvents.SessionReplace> e)
 {
     if (e.EventData != null)
     {
         session = e.EventData.SessionId;
     }
 }
Пример #6
0
 private async void Gateway_GuildMemberUpdated(object sender, Gateway.GatewayEventArgs <GuildMemberUpdate> e)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                   () =>
     {
         try
         {
             if (DisplayedMember != null)
             {
                 if (e.EventData.User.Id == DisplayedMember.Raw.User.Id)
                 {
                     DisplayedMember.Raw.Roles = e.EventData.Roles;
                     DisplayedMember.Raw.Nick  = e.EventData.Nick;
                     rectangle.Fill            = (SolidColorBrush)App.Current.Resources[DisplayedMember.status.Status];
                 }
             }
             else
             {
                 App.PresenceUpdatedHandler -= App_PresenceUpdatedHandler;
                 GatewayManager.Gateway.GuildMemberUpdated -= Gateway_GuildMemberUpdated;
             }
         }
         catch
         {
         }
     });
 }
 private async void Gateway_PresenceUpdated(object sender, Gateway.GatewayEventArgs <Presence> e)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                   () =>
     {
         try
         {
             if (e.EventData.User.Id == DisplayedMember.User.Id)
             {
                 if (e.EventData.Game.HasValue)
                 {
                     PlayingHeader.Visibility = Visibility.Visible;
                     var game = e.EventData.Game.Value;
                     richPresence.GameContent = game;
                     richPresence.Visibility  = Visibility.Visible;
                 }
                 else
                 {
                     PlayingHeader.Visibility = Visibility.Collapsed;
                     richPresence.Visibility  = Visibility.Collapsed;
                 }
             }
         }
         catch { }
     });
 }
Пример #8
0
 private void Gateway_GuildMemberChunk(object sender, Gateway.GatewayEventArgs <SharedModels.GuildMemberChunk> e)
 {
     foreach (var member in e.EventData.Members)
     {
         SearchResults.Items.Add(member.User.Username);
     }
 }
Пример #9
0
 private async Task AddRelationshipToUI(Gateway.GatewayEventArgs <Friend> e)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                   () =>
     {
         SimpleFriend sfriend = NewSF(e.EventData);
         if (sfriend.RelationshipStatus == 1)
         {
             AllView.Items.Add(sfriend);
         }
         else if (sfriend.RelationshipStatus == 2)
         {
             BlockedView.Items.Add(sfriend);
         }
         else if (sfriend.RelationshipStatus == 3 || sfriend.RelationshipStatus == 4)
         {
             if (sfriend.RelationshipStatus == 3)
             {
                 FriendNotification(sfriend.User);
             }
             App.FriendNotifications += 1;
             App.UpdateUnreadIndicators();
             PendingCounter.Text = App.FriendNotifications.ToString();
             PendingView.Items.Add(NewSF(e.EventData));
         }
     });
 }
Пример #10
0
 private static void Gateway_VoiceStateUpdated(object sender, Gateway.GatewayEventArgs <SharedModels.VoiceState> e)
 {
     try
     {
         if (e.EventData.UserId == LocalState.CurrentUser.Id)
         {
             LocalState.VoiceState = e.EventData;
             if (String.IsNullOrEmpty(e.EventData.ChannelId))
             {
                 AudioManager.PlaySoundEffect("voicedc");
             }
         }
         else if (e.EventData.ChannelId == LocalState.VoiceState.ChannelId)
         {
             AudioManager.PlaySoundEffect("userjoin");
         }
         else if (LocalState.VoiceDict.ContainsKey(e.EventData.UserId) && LocalState.VoiceDict[e.EventData.UserId].ChannelId == LocalState.VoiceState.ChannelId)
         {
             AudioManager.PlaySoundEffect("userleave");
         }
         if (LocalState.VoiceDict.ContainsKey(e.EventData.UserId))
         {
             LocalState.VoiceDict[e.EventData.UserId] = e.EventData;
         }
         else
         {
             LocalState.VoiceDict.Add(e.EventData.UserId, e.EventData);
         }
     }
     catch
     {
         //Huh, Weird
     }
 }
Пример #11
0
 /// <summary>
 /// Voice State changed
 /// </summary>
 private async void Gateway_VoiceStateUpdated(object sender, Gateway.GatewayEventArgs <VoiceState> e)
 {
     // Run on UI thread
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                               () =>
     {
         if (e.EventData.ChannelId == Id)
         {
             // Add updated voice user to this list
             if (!VoiceMembers.ContainsKey(e.EventData.UserId))
             {
                 VoiceMembers.Add(e.EventData.UserId, new VoiceMemberContainer()
                 {
                     VoiceState = e.EventData
                 });
                 MemberList.Items.Add(VoiceMembers[e.EventData.UserId]);
                 if (VoiceMembers.Count > 0)
                 {
                     MemberList.Visibility = Visibility.Visible;
                 }
             }
         }
         else if (VoiceMembers.ContainsKey(e.EventData.UserId))
         {
             // Remove updated voice user from this list
             MemberList.Items.Remove(VoiceMembers[e.EventData.UserId]);
             VoiceMembers.Remove(e.EventData.UserId);
             if (VoiceMembers.Count == 0)
             {
                 MemberList.Visibility = Visibility.Collapsed;
             }
         }
     });
 }
Пример #12
0
 /// <summary>
 /// Add RelationShip when added
 /// </summary>
 private async void Gateway_RelationShipAdded(object sender, Gateway.GatewayEventArgs <Friend> e)
 {
     if (e.EventData.Type == 1)
     {
         await RemoveRelationshipFromUI(e);
     }
     await AddRelationshipToUI(e);
 }
Пример #13
0
 private static void Gateway_GuildDeleted(object sender, Gateway.GatewayEventArgs <Gateway.DownstreamEvents.GuildDelete> e)
 {
     //TODO: Deal with guild outages
     if (LocalState.Guilds.ContainsKey(e.EventData.GuildId))
     {
         App.GuildDeleted(e.EventData.GuildId);
     }
 }
Пример #14
0
        private static void Gateway_GuildChannelCreated(object sender, Gateway.GatewayEventArgs <SharedModels.GuildChannel> e)
        {
            LocalState.Guilds[e.EventData.GuildId].channels.TryAdd(e.EventData.Id, new LocalModels.GuildChannel(e.EventData));

            if (e.EventData.GuildId == App.CurrentGuildId)
            {
                App.GuildChannelCreated(e.EventData);
            }
        }
Пример #15
0
        private static void Gateway_UserSettingsUpdated(object sender, Gateway.GatewayEventArgs <SharedModels.UserSettings> e)
        {
            var temp = LocalState.CurrentUserPresence;

            temp.Status = e.EventData.Status;
            LocalState.PresenceDict[LocalState.CurrentUser.Id] = temp;
            App.UserStatusChanged(e.EventData);
            LocalState.Settings = e.EventData;
        }
Пример #16
0
 private async void Gateway_GuildDeleted(object sender, Gateway.GatewayEventArgs <Gateway.DownstreamEvents.GuildDelete> e)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         if (e.EventData.GuildId == DisplayedInvite.Guild.Id)
         {
             LoadInvite(false);
         }
     });
 }
Пример #17
0
 private static void Gateway_GuildChannelDeleted(object sender, Gateway.GatewayEventArgs <SharedModels.GuildChannel> e)
 {
     LocalModels.GuildChannel channel;
     LocalState.Guilds[e.EventData.GuildId].channels.TryRemove(e.EventData.Id, out channel);
     channel = null;
     if (e.EventData.GuildId == App.CurrentGuildId)
     {
         App.GuildChannelDeleted(e.EventData.GuildId, e.EventData.Id);
     }
 }
Пример #18
0
 private static void Gateway_GuildMemberUpdated(object sender, Gateway.GatewayEventArgs <SharedModels.GuildMemberUpdate> e)
 {
     if (LocalState.Guilds[e.EventData.guildId].members.ContainsKey(e.EventData.User.Id))
     {
         var member = LocalState.Guilds[e.EventData.guildId].members[e.EventData.User.Id];
         member.Nick  = e.EventData.Nick;
         member.Roles = e.EventData.Roles;
         LocalState.Guilds[e.EventData.guildId].members[e.EventData.User.Id] = member;
     }
 }
 private async void Gateway_UserNoteUpdated(object sender, Gateway.GatewayEventArgs <Gateway.DownstreamEvents.UserNote> e)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                   () =>
     {
         if (e.EventData.UserId == DisplayedMember.User.Id)
         {
             Note.Text = e.EventData.Note;
         }
     });
 }
Пример #20
0
 private static void Gateway_MessageDeleted(object sender, Gateway.GatewayEventArgs <Gateway.DownstreamEvents.MessageDelete> e)
 {
     App.MessageDeleted(e.EventData.MessageId, e.EventData.ChannelId);
     if (App.CurrentChannelId == e.EventData.ChannelId)
     {
     }
     else
     {
         //TODO: Notifications (maybe)
     }
 }
Пример #21
0
 private static void Gateway_MessageUpdated(object sender, Gateway.GatewayEventArgs <SharedModels.Message> e)
 {
     App.MessageEdited(e.EventData);
     if (App.CurrentChannelId == e.EventData.ChannelId)
     {
     }
     else
     {
         //TODO: Notifications (I'm actually really happy with this idea)
     }
 }
Пример #22
0
 private static void Gateway_PresenceUpdated(object sender, Gateway.GatewayEventArgs <SharedModels.Presence> e)
 {
     if (LocalState.PresenceDict.ContainsKey(e.EventData.User.Id))
     {
         LocalState.PresenceDict[e.EventData.User.Id] = e.EventData;
     }
     else
     {
         LocalState.PresenceDict.Add(e.EventData.User.Id, e.EventData);
     }
     App.PresenceUpdated(e.EventData.User.Id, e.EventData);
 }
Пример #23
0
 private async void Gateway_VoiceStateUpdated(object sender, Gateway.GatewayEventArgs <VoiceState> e)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                   () =>
     {
         if (e.EventData.UserId == DisplayedUser.UserId)
         {
             DisplayedUser = e.EventData;
             OnPropertyChanged(null, DisplayedUserProperty);
         }
     });
 }
Пример #24
0
        private static void Gateway_GuildChannelUpdated(object sender, Gateway.GatewayEventArgs <SharedModels.GuildChannel> e)
        {
            if (LocalState.Guilds[e.EventData.GuildId].channels.ContainsKey(e.EventData.Id))
            {
                LocalState.Guilds[e.EventData.GuildId].channels[e.EventData.Id] = new LocalModels.GuildChannel(e.EventData);
            }

            if (e.EventData.GuildId == App.CurrentGuildId)
            {
                App.GuildChannelUpdated(e.EventData);
            }
        }
Пример #25
0
        private static void Gateway_DirectMessageChannelDeleted(object sender, Gateway.GatewayEventArgs <SharedModels.DirectMessageChannel> e)
        {
            if (LocalState.DMs.ContainsKey(e.EventData.Id))
            {
                LocalState.DMs.Remove(e.EventData.Id);
            }

            if (App.CurrentGuildIsDM)
            {
                App.DMDeleted(e.EventData.Id);
            }
        }
Пример #26
0
 private async void Gateway_GuildCreated(object sender, Gateway.GatewayEventArgs <SharedModels.Guild> e)
 {
     // If the guild is this guild
     if (DisplayedInvite?.Guild != null && e.EventData.Id == DisplayedInvite.Guild.Id)
     {
         // Run on UI thread
         await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             // Update the info to say it's already joined
             LoadInvite(false);
         });
     }
 }
Пример #27
0
        private async void Gateway_RelationShipAdded(object sender, Gateway.GatewayEventArgs <Friend> e)
        {
            try
            {
                await RemoveRelationshipFromUI(e);
            }
            catch (Exception exception)
            {
                App.NavigateToBugReport(exception);
            }

            await AddRelationshipToUI(e);
        }
Пример #28
0
 private async void Gateway_GuildDeleted(object sender, Gateway.GatewayEventArgs <Gateway.DownstreamEvents.GuildDelete> e)
 {
     // If the guild is this guild
     if (DisplayedInvite?.Guild != null && e.EventData.GuildId == DisplayedInvite.Guild.Id)
     {
         // Run on UI thread
         await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             // Display the invite
             LoadInvite(false);
         });
     }
 }
Пример #29
0
 private static void Gateway_RelationShipAdded(object sender, Gateway.GatewayEventArgs <SharedModels.Friend> e)
 {
     if (!LocalState.Friends.ContainsKey(e.EventData.Id))
     {
         LocalState.Friends.Add(e.EventData.Id, e.EventData);
     }
     else
     {
         LocalState.Friends[e.EventData.Id] = e.EventData;
     }
     if (e.EventData.Type == 3)
     {
         Storage.UpdateNotificationState("r" + e.EventData.user.Id, e.EventData.Id);
     }
 }
Пример #30
0
        private static void Gateway_GuildCreated(object sender, Gateway.GatewayEventArgs <SharedModels.Guild> e)
        {
            if (!LocalState.Guilds.ContainsKey(e.EventData.Id))
            {
                LocalState.Guilds.Add(e.EventData.Id, new LocalModels.Guild(e.EventData));
                foreach (var member in e.EventData.Members)
                {
                    LocalState.Guilds[e.EventData.Id].members.TryAdd(member.User.Id, member);
                }

                foreach (var role in e.EventData.Roles)
                {
                    LocalState.Guilds[e.EventData.Id].roles.TryAdd(role.Id, role);
                }


                foreach (var channel in e.EventData.Channels)
                {
                    LocalState.Guilds[e.EventData.Id].channels.TryAdd(channel.Id, new LocalModels.GuildChannel(channel, e.EventData.Id));
                }

                foreach (var presence in e.EventData.Presences)
                {
                    //TODO Optimize this, ContainsKey is running twice
                    if (LocalState.PresenceDict.ContainsKey(presence.User.Id))
                    {
                        LocalState.PresenceDict[presence.User.Id] = presence;
                    }
                    else
                    {
                        LocalState.PresenceDict.Add(presence.User.Id, presence);
                    }
                }
                foreach (var voiceState in e.EventData.VoiceStates)
                {
                    //TODO Optimize this, ContainsKey is running twice
                    if (LocalState.VoiceDict.ContainsKey(voiceState.UserId))
                    {
                        LocalState.VoiceDict[voiceState.UserId] = voiceState;
                    }
                    else
                    {
                        LocalState.VoiceDict.Add(voiceState.UserId, voiceState);
                    }
                }
                App.GuildCreated(e.EventData);
            }
        }