コード例 #1
0
        public static void Delete(BubbleGroup group)
        {
            lock (BubbleGroupDatabase.OperationLock)
            {
                var unifiedGroup = @group as UnifiedBubbleGroup;
                if (unifiedGroup != null)
                {
                    DeleteUnified(unifiedGroup);
                    return;
                }

                var file = BubbleGroupDatabase.GetLocation(@group);

                if (File.Exists(file))
                {
                    File.Delete(file);
                }

                BubbleGroupSync.RemoveFromSync(@group);

                BubbleGroupSync.DeleteBubbleGroupIfHasAgent(@group);

                BubbleGroupManager.BubbleGroupsRemove(@group);
            }
        }
コード例 #2
0
 public Task CanAddPartyParticipant(BubbleGroup group, Action<bool> result)
 {
     return Task.Factory.StartNew(() =>
     {
         var fullChat = FetchFullChat(group.Address, group.IsExtendedParty);
         var partyParticipants = GetPartyParticipants(fullChat);
         if (!IsPartOfParty(partyParticipants))
         {
             result(false);
             return;
         }
         if (ChatAdminsEnabled(group.Address))
         {
             if (group.IsExtendedParty && IsDemocracyEnabled(group))
             {
                 //if democracy is enabled in a spergroup anyone can add members
                 result(true);
                 return;
             }
             if (!IsAdmin(group.Address, group.IsExtendedParty))
             {
                 result(false);
                 return;
             }
         }
         result(true);
     });
 }
コード例 #3
0
        public static UnifiedBubbleGroup CreateUnified(List<BubbleGroup> groups, BubbleGroup primaryGroup)
        {
            lock (BubbleGroupDatabase.OperationLock)
            {
                var unifiedGroupsToKill = new HashSet<UnifiedBubbleGroup>();
                foreach (var group in groups)
                {
                    if (group.IsUnified)
                    {
                        unifiedGroupsToKill.Add(group.Unified);
                        @group.DeregisterUnified();
                    }
                }
                foreach (var unifiedGroup in unifiedGroupsToKill)
                {
                    BubbleGroupManager.BubbleGroupsRemove(unifiedGroup);
                }
                UnifiedBubbleGroupsDatabase.Remove(unifiedGroupsToKill);

                var unified = CreateUnifiedInternal(groups, primaryGroup);
                UnifiedBubbleGroupsDatabase.Add(unified,
                    new DisaUnifiedBubbleGroupEntry(unified.ID,
                        unified.Groups.Select(innerGroup => innerGroup.ID)
                        .ToArray(), primaryGroup.ID, primaryGroup.ID));
                BubbleGroupManager.BubbleGroupsAdd(unified);
                return unified;
            }
        }
コード例 #4
0
 public Task UnblockPartyParticipant(BubbleGroup group, DisaParticipant participant, Action<bool> result)
 {
     return Task.Factory.StartNew(() =>
     {
         using (var client = new FullClientDisposable(this))
         {
             try
             {
                 var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsKickFromChannelAsync(new ChannelsKickFromChannelArgs
                 {
                     Channel = new InputChannel
                     {
                         ChannelId = uint.Parse(group.Address),
                         AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                     },
                     Kicked = false,
                     UserId = new InputUser
                     {
                         UserId = uint.Parse(participant.Address),
                         AccessHash = GetUserAccessHashIfForeign(participant.Address)
                     }
                 }));
                 result(true);
             }
             catch (Exception e)
             {
                 DebugPrint("#### Exception " + e);
                 result(false);
             }
         }
     });
 }
コード例 #5
0
 internal static void RaiseSyncReset(BubbleGroup group)
 {
     if (_syncReset != null)
     {
         _syncReset(group);
     }
 }
コード例 #6
0
 public Task GetPartyBlockedParticipantPicture(BubbleGroup group, string address, Action<DisaThumbnail> result)
 {
     return Task.Factory.StartNew(() =>
     {
         result(GetThumbnail(address, false, true));
     });
 }
コード例 #7
0
        internal static void UpdateGroupLegibleID(BubbleGroup bubbleGroup, Action finished = null)
        {
            var service = bubbleGroup.Service;

            if (!ServiceManager.IsRunning(service)) return;

            try
            {
                service.GetBubbleGroupLegibleId(bubbleGroup, legibleID =>
                {
                    bubbleGroup.LegibleId = legibleID;
                    if (finished == null)
                    {
                        BubbleGroupEvents.RaiseRefreshed(bubbleGroup);
                    }
                    else
                    {
                        finished();
                    }
                });
            }
            catch (Exception ex)
            {
                Utils.DebugPrint("Error updating bubble group legible ID: " + service.Information.ServiceName + ": " +
                                         ex.Message);
                if (finished != null)
                {
                    finished();
                }
            }
        }
コード例 #8
0
 private static void InsertDefaultIfNull(BubbleGroup group)
 {
     lock (_lock)
     {
         if (group.Settings == null)
         {
             using (var db = new SqlDatabase<BubbleGroupSettings>(GetPath()))
             {
                 var settings = new BubbleGroupSettings
                 {
                     Mute = false,
                     Unread = true,
                     Guid = group.ID,
                     LastUnreadSetTime = 0,
                     ReadTimes = null,
                     ParticipantNicknames = null,
                     NotificationLed = DefaultNotificationLedColor,
                     VibrateOption = null,
                     VibrateOptionCustomPattern = null,
                     Ringtone = null,
                 };
                 db.Add(settings);
                 group.Settings = settings;
             }
         }
     }
 }        
コード例 #9
0
ファイル: SyncAgent.cs プロジェクト: harper10/DisaOpenSource
        private List<VisualBubble> LoadBubblesForBubbleGroup(BubbleGroup @group, long fromTime, int max)
        {
            var response = GetMessageHistory(group, fromTime, max);
            var messages = response as MessagesMessages;
            var messagesSlice = response as MessagesMessagesSlice;
            var messagesChannels = response as MessagesChannelMessages;
            if (messages != null)
            {
                _dialogs.AddChats(messages.Chats);
                _dialogs.AddUsers(messages.Users);
                //DebugPrint("Messages are as follows " + ObjectDumper.Dump(messages.Messages));
                messages.Messages.Reverse();
                return ConvertMessageToBubbles(messages.Messages);

            }
            if (messagesSlice != null)
            {
                _dialogs.AddChats(messagesSlice.Chats);
                _dialogs.AddUsers(messagesSlice.Users);
                //DebugPrint("Messages are as follows " + ObjectDumper.Dump(messagesSlice.Messages));
                messagesSlice.Messages.Reverse();
                return ConvertMessageToBubbles(messagesSlice.Messages);
            }
            if (messagesChannels != null)
            {
                _dialogs.AddChats(messagesChannels.Chats);
                _dialogs.AddUsers(messagesChannels.Users);
                messagesChannels.Messages.Reverse();
                var bubbles = ConvertMessageToBubbles(messagesChannels.Messages);
                SetExtendedFlag(bubbles);
                return bubbles;
            }
            return new List<VisualBubble>();
        }
コード例 #10
0
        public static UnifiedBubbleGroup CreateUnified(List<BubbleGroup> groups, BubbleGroup primaryGroup)
        {
            lock (BubbleGroupDatabase.OperationLock)
            {
                var unifiedGroupsToKill = new HashSet<UnifiedBubbleGroup>();
                foreach (var group in groups)
                {
                    if (group.IsUnified)
                    {
                        unifiedGroupsToKill.Add(group.Unified);
                        @group.DeregisterUnified();
                    }
                }
                foreach (var unifiedGroup in unifiedGroupsToKill)
                {
                    BubbleGroupManager.BubbleGroupsRemove(unifiedGroup);
                }
                BubbleGroupIndex.RemoveUnified(unifiedGroupsToKill.Select(x => x.ID).ToArray());

                var unified = CreateUnifiedInternal(groups, primaryGroup);
                BubbleGroupIndex.AddUnified(unified);
                BubbleGroupManager.BubbleGroupsAdd(unified);
                return unified;
            }
        }
コード例 #11
0
ファイル: SyncAgent.cs プロジェクト: Xanagandr/DisaOpenSource
 public Task<List<VisualBubble>> LoadBubbles(BubbleGroup @group, long fromTime, int max = 100)
 {
     return Task<List<VisualBubble>>.Factory.StartNew(() =>
     {
         return LoadBubblesForBubbleGroup(group, fromTime, max);
     });
 }
コード例 #12
0
        internal static void UpdateName(BubbleGroup bubbleGroup, Action finished = null)
        {
            var service = bubbleGroup.Service;

            if (!ServiceManager.IsRunning(service)) return;

            try
            {
                service.GetBubbleGroupName(bubbleGroup, title =>
                {
                    bubbleGroup.IsTitleSetFromService = true;
                    bubbleGroup.Title = title;
                    if (finished == null)
                    {
                        BubbleGroupEvents.RaiseRefreshed(bubbleGroup);
                        BubbleGroupEvents.RaiseInformationUpdated(bubbleGroup);
                    }
                    else
                    {
                        finished();
                    }
                });
            }
            catch (Exception ex)
            {
                Utils.DebugPrint("Error updating bubble group name: " + service.Information.ServiceName + ": " +
                                         ex.Message);
                if (finished != null)
                {
                    finished();
                }
            }
        }
コード例 #13
0
        public BubbleGroupFinderResult Find()
        {
            var groups = new List<BubbleGroup>();

            // If a group is still valid for this grid, we don't need to search for it again
            // Turns out this is a bad optimisation - needs profiling
            //groups.AddRange(_parentGroups.Where(x => x.IsValidFor(_grid)));

            for (int y = 0; y < _grid.Height; y++)
            {
                for (int x = 0; x < _grid.Width; x++)
                {
                    if(!_stats.ContainsKey(_grid[x,y])) _stats.Add(_grid[x,y], 1);
                    else _stats[_grid[x, y]]++;

                    if (!groups.Any(group => group.Locations.Contains(new Point(x, y))))
                    {
                        _currentGroup = new BubbleGroup();
                        FindBubbleGroup(x, y);
                        if (_currentGroup.Locations.Count > 1 && _currentGroup.Colour != Bubble.None)
                        {
                            groups.Add(_currentGroup);
                        }
                    }
                }
            }
            return new BubbleGroupFinderResult(groups, _stats);
        }
コード例 #14
0
 public Task GetPartyBlockedParticipants(BubbleGroup group, Action<DisaParticipant[]> result)
 {
     return Task.Factory.StartNew(() =>
     {
         var returnList = new List<DisaParticipant>();
         var fullChat = FetchFullChat(group.Address, group.IsExtendedParty);
         var iChatFull = fullChat.FullChat;
         var channelFull = iChatFull as ChannelFull;
         if (channelFull != null)
         {
             var kickedParticipants =  GetChannelParticipants(channelFull, new ChannelParticipantsKicked());
             foreach (var participant in kickedParticipants) 
             {
                 if (participant is ChannelParticipantKicked)
                 {
                     var id = TelegramUtils.GetUserIdFromChannelParticipant(participant);
                     if (id != null)
                     {
                         var user = _dialogs.GetUser(uint.Parse(id));
                         var name = TelegramUtils.GetUserName(user);
                         returnList.Add(new DisaParticipant(name, id));
                     }
                 }
             }
         }
         result(returnList.ToArray());
     });
 }
コード例 #15
0
        public static string GetLocation(BubbleGroup theGroup)
        {
            var tableLocation = GetServiceLocation(theGroup.Service.Information);
            var groupLocation = Path.Combine(tableLocation,
                theGroup.Service.Information.ServiceName + "^" + theGroup.ID + ".group");

            return groupLocation;
        }
コード例 #16
0
 public UnifiedBubbleGroup(List<BubbleGroup> groups, BubbleGroup primaryGroup,
     VisualBubble initialBubble, string id = null)
     : base(initialBubble, id, false)
 {
     _unifiedService = initialBubble.Service;
     Groups = groups;
     PrimaryGroup = primaryGroup;
     SendingGroup = primaryGroup;
 }
コード例 #17
0
        public static bool UpdatePhoto(BubbleGroup bubbleGroup, Action<DisaThumbnail> finished)
        {
            var service = bubbleGroup.Service;

            if (!ServiceManager.IsRunning(service))
                return false;

            if (bubbleGroup.Service.Information.UsesInternet && !Platform.HasInternetConnection())
                return false;

            try
            {
                service.GetBubbleGroupPhoto(bubbleGroup, photo =>
                {
                    if (photo != null && photo.Failed)
                    {
                        if (finished != null)
                        {
                            finished(bubbleGroup.Photo);
                        }
                        return;
                    }

                    Action<DisaThumbnail> callbackFinished = thePhoto =>
                    {
                        bubbleGroup.Photo = thePhoto;
                        bubbleGroup.IsPhotoSetFromService = true;
                        if (finished != null)
                        {
                            finished(bubbleGroup.Photo);
                        }
                    };

                    if (photo == null && bubbleGroup.IsParty)
                    {
                        BubbleGroupUtils.StitchPartyPhoto(bubbleGroup, callbackFinished);
                    }
                    else
                    {
                        callbackFinished(photo);
                    }
                });
            }
            catch (Exception ex)
            {
                Utils.DebugPrint("Error updating bubble group photo: " + 
                                         service.Information.ServiceName + ": " + ex.Message);
                if (finished != null)
                {
                    finished(null);
                }
            }

            return true;
        }
コード例 #18
0
 public static void BubbleGroupsAdd(BubbleGroup group, bool initialLoad = false)
 {
     lock (BubbleGroupsLock)
     {
         BubbleGroups.Add(group);
         if (!initialLoad && !(group is UnifiedBubbleGroup))
         {
             BubbleGroupIndex.Add(group);
         }
     }
 }
コード例 #19
0
 private static BubbleGroupCache Generate(BubbleGroup group, string guid)
 {
     var bubbleGroupCache = new BubbleGroupCache
     {
         Name = group.Title,
         Photo = group.Photo,
         Participants = group.Participants.ToList(),
         Guid = guid,
     };
     return bubbleGroupCache;
 }
コード例 #20
0
 private static void Bind(BubbleGroup associatedGroup, BubbleGroupCache item)
 {
     associatedGroup.Title = item.Name;
     associatedGroup.Photo = item.Photo;
     associatedGroup.IsPhotoSetInitiallyFromCache = true;
     if (item.Participants != null)
     {
         associatedGroup.Participants = new ThreadSafeList<DisaParticipant>(item.Participants);
         foreach (var participant in associatedGroup.Participants)
         {
             participant.IsPhotoSetInitiallyFromCache = true;
         }
     }
 }
コード例 #21
0
 public Task CanConvertToExtendedParty(BubbleGroup group, Action<bool> result)
 {
     return Task.Factory.StartNew(() =>
     {
         if (!group.IsExtendedParty && IsCreator(group.Address, group.IsExtendedParty))
         {
             result(true);
         }
         else
         {
             result(false);
         }
     });
 }
コード例 #22
0
 public Task CanSetPartyAllMembersAdministratorsRestriction(BubbleGroup group, Action<bool> result)
 {
     return Task.Factory.StartNew(() =>
     {
         if (!group.IsExtendedParty && IsCreator(group.Address, group.IsExtendedParty))
         {
             result(true);
         }
         else
         {
             result(false);
         }
     });
 }
コード例 #23
0
 public Task HasPartyDescription(BubbleGroup group, Action<bool> result)
 {
     return Task.Factory.StartNew(() =>
     {
         var channel = _dialogs.GetChat(uint.Parse(group.Address)) as Channel;
         if (channel != null)
         {
             result(true);
         }
         else
         {
             result(false);
         }
     });
 }
コード例 #24
0
 public static string GetUnreadIndicatorGuid(BubbleGroup group)
 {
     InsertDefaultIfNull(group);
     var guid = group.Settings.UnreadIndicatorGuid;
     if (!string.IsNullOrWhiteSpace(guid))
     {
         var indexOf = guid.IndexOf('|');
         if (indexOf > -1)
         {
             var editedGuid = guid.Substring(0, indexOf);
             return editedGuid;
         }
     }
     return guid;
 }
コード例 #25
0
 public Task GetPartyDescription(BubbleGroup group, Action<string> result)
 {
     return Task.Factory.StartNew(() =>
     {
         var fullChat = FetchFullChat(group.Address, true);
         var fullChannel = fullChat?.FullChat as ChannelFull;
         if (fullChannel != null)
         {
             result(fullChannel.About);
         }
         else
         {
             result(null);
         }
     });
 }
コード例 #26
0
        protected internal void OnBubbleUpdated(VisualBubble bubble, BubbleGroup group)
        {
            if (Bubbles.Count > BubblesCapSize)
            {
                Bubbles.RemoveAt(0);
            }

            var addedToEnd = false;

            for (int i = Bubbles.Count - 1; i >= 0; i--)
            {
                var nBubble = Bubbles[i];
                if (nBubble.Time <= bubble.Time)
                {
                    // adding it to the end, we can do a simple contract
                    if (i == Bubbles.Count - 1)
                    {
                        addedToEnd = true;
                        Bubbles.Add(bubble);
                        if (bubble.Direction == Bubble.BubbleDirection.Incoming)
                        {
                            BubbleGroupSettingsManager.SetUnread(this, true);
                        }
                    }
                    // inserting, do a full contract
                    else
                    {
                        Bubbles.Insert(i + 1, bubble);
                    }
                    break;
                }

                // could not find a valid place to insert, then skip insertion.
                if (i == 0)
                {
                    return;
                }
            }

            if (SendingGroup != group && addedToEnd)
            {
                SendingGroup = group;
                BubbleGroupEvents.RaiseSendingServiceChange(this);
            }

            RaiseBubbleInserted(bubble);
        }
コード例 #27
0
 private static bool HasNotQueued(BubbleGroup group)
 {
     lock (_dbLock)
     {
         var groupId = group.ID;
         using (var db = new SqlDatabase<NotQueuedEntry>(NotQueuedLocation))
         {
             // don't add a duplicate group into the queue
             foreach (var possibleGroup in db.Store.Where(x => 
                 x.BubbleGroupGuid == groupId))
             {
                 return true;
             }
         }
         return false;
     }
 }
コード例 #28
0
        internal static void RollBackTo(BubbleGroup group, long index)
        {
            if (index <= 0)
            {
                throw new ArgumentException("Index can't be <= 0!");
            }

            var groupDatabaseLocation = GetLocation(@group);

            using (var stream = File.Open(groupDatabaseLocation, FileMode.Open, FileAccess.ReadWrite))
            {
                if (index > stream.Length)
                {
                    throw new Exception("File length can't be greater than index.");
                }
                stream.SetLength(index);
            }
        }
コード例 #29
0
ファイル: SyncAgent.cs プロジェクト: Xanagandr/DisaOpenSource
        public Task<BubbleGroupSync.Result> Sync(BubbleGroup @group, string actionId)
        {
            return Task<BubbleGroupSync.Result>.Factory.StartNew(() =>
            {
                const int limit = 100;
                var actionIdLong = actionId == null ? 0 : long.Parse(actionId);

                if (actionIdLong == 0)
                {
                   var bubbles = LoadBubblesForBubbleGroup(group, Time.GetNowUnixTimestamp(), limit);
                    if (bubbles.LastOrDefault() != null)
                    {
                        var lastActionId = bubbles.LastOrDefault().IdService;
                        return new BubbleGroupSync.Result(BubbleGroupSync.Result.Type.Purge,lastActionId,null,bubbles.ToArray());
                    }
                }
                return new BubbleGroupSync.Result();
            });
        }
コード例 #30
0
        internal static async void UpdateName(BubbleGroup bubbleGroup, Action finished = null)
        {
            var service = bubbleGroup.Service;

            if (!ServiceManager.IsRunning(service)) return;

            try
            {
                await service.GetBubbleGroupName(bubbleGroup, title =>
                {
                    bubbleGroup.IsTitleSetFromService = true;
                    if (string.IsNullOrWhiteSpace(title))
                    {
                        Utils.DebugPrint("Update name title is null (rejecting): " + service.Information.ServiceName + 
                            " - " + bubbleGroup.Address);
                    }
                    else
                    {
                        bubbleGroup.Title = title;
                    }
                    if (finished == null)
                    {
                        BubbleGroupEvents.RaiseRefreshed(bubbleGroup);
                        BubbleGroupEvents.RaiseInformationUpdated(bubbleGroup);
                    }
                    else
                    {
                        finished();
                    }
                });
            }
            catch (Exception ex)
            {
                Utils.DebugPrint("Error updating bubble group name: " + service.Information.ServiceName + 
                    " - " + bubbleGroup.Address + ": " + ex);
                if (finished != null)
                {
                    finished();
                }
            }
        }
コード例 #31
0
 public override bool SwitchCurrentBubbleGroupOnUI(BubbleGroup group)
 {
     throw new NotImplementedException();
 }
コード例 #32
0
        public Task InviteToChannel(BubbleGroup group, Tuple <Contact, Contact.ID>[] contacts, Action <bool> result)
        {
            var addPartyResult = AddPartyResult.Success;

            return(Task.Factory.StartNew(() =>
            {
                if (contacts.Length > 0)
                {
                    var inputUsers = new List <IInputUser>();
                    var names = new List <string>();
                    foreach (var contact in contacts)
                    {
                        names.Add(contact.Item1.FullName);
                        IUser user = null;
                        if (contact.Item1 is TelegramContact)
                        {
                            user = (contact.Item1 as TelegramContact).User;
                        }
                        else if (contact.Item1 is TelegramBotContact)
                        {
                            user = (contact.Item1 as TelegramBotContact).User;
                        }
                        var inputUser = TelegramUtils.CastUserToInputUser(user);
                        if (inputUser != null)
                        {
                            inputUsers.Add(inputUser);
                        }
                    }

                    if (inputUsers.Any())
                    {
                        using (var client = new FullClientDisposable(this))
                        {
                            try
                            {
                                var update = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsInviteToChannelAsync(new ChannelsInviteToChannelArgs
                                {
                                    Channel = new InputChannel
                                    {
                                        ChannelId = uint.Parse(group.Address),
                                        AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                                    },
                                    Users = inputUsers
                                }));
                                SendToResponseDispatcher(update, client.Client);
                            }
                            catch (Exception ex)
                            {
                                Utils.DebugPrint("Failed Telegram ChannelsInviteToChannelAsync: " + ex);

                                if (ex.Message.Contains("PEER_FLOOD"))
                                {
                                    _addPartyResult = AddPartyResult.Flood;
                                }
                                else
                                {
                                    _addPartyResult = AddPartyResult.Error;
                                }
                                return;
                            }
                        }
                    }
                }
            }));
        }