コード例 #1
0
        public override Result QueryFeature(FeatureQuery query)
        {
            if (query.GetLong(0, out var groupId))
            {
                var groupInfo = _handler.GetGroupInfo(groupId);
                if (groupInfo == null)
                {
                    return(Result.DataNotFound);
                }

                var action = query.Action;

                if (action == LastTransactionInfoAction)
                {
                    return(new PackableResult(groupInfo.LastTransactionInfo));
                }
                else if (action == IndexLastTransactionInfoAction)
                {
                    if (query.GetString(1, out var indexHex))
                    {
                        var index = new Chain.Index(indexHex);
                        return(new PackableResult(groupInfo.GetLastGroupIndexTransactionInfo(index, true)));
                    }
                }
            }

            return(Result.InvalidQuery);
        }
コード例 #2
0
        MessageSubmitAccount GenerateSubmitAccount(Chain.Index index)
        {
            (var friendAccountId, var friendKeyIndex, var accountId, var keyIndex) = GetFriendAccountId(index);

            if (accountId != AccountId)
            {
                return(null);
            }

            var submitAccount = ServiceNode.GetSubmitAccount <MessageSubmitAccount>(keyIndex, index);

            if (submitAccount != null)
            {
                return(submitAccount);
            }

            foreach (var account in ServiceNode.ServiceAccounts.Values)
            {
                if (!account.IsDecrypted)
                {
                    continue;
                }

                if (account.AccountId == accountId && account.KeyIndex == keyIndex)
                {
                    submitAccount = new MessageSubmitAccount(account, this, friendAccountId, friendKeyIndex, keyIndex, index, true);
                    ServiceNode.AddSubmitAccount(submitAccount);

                    return(submitAccount);
                }
            }

            return(null);
        }
コード例 #3
0
        public StatusAccountPage(ProfileDataResult profileData, ServiceNode serviceNode, long accountId, StatusAccountProfileType profileType, long transactionId) : base("StatusAccountPage")
        {
            Subscribe <SubscriptionEvent>(Subscription);
            Subscribe <ProfileDataResultEvent>(ProfileData);

            StackLayout.Suspended = true;

            _transactionId = transactionId;
            _profileType   = profileType;
            _serviceNode   = serviceNode;
            _status        = StatusApp.Current.GetStatus(serviceNode);
            _accountId     = accountId;
            _accountIndex  = Chain.Index.New().Add(_accountId).Build();

            _messagesDownload = new AccountIndexTransactionDownload(accountId, StatusServiceInfo.MessageIndex, serviceNode.GetTransactionDownloadManager(StatusServiceInfo.StatusDataChainIndex))
            {
                Count = 10
            };

            AddTitleRow("Title");

            if (profileType == StatusAccountProfileType.Small || transactionId > 0)
            {
                var row = new StatusProfileButtonRow(serviceNode, _accountId, profileData?.ProfileInfo, profileData, async(button) =>
                {
                    await Navigation.PushAsync(new StatusAccountPage(profileData, serviceNode, accountId, StatusAccountProfileType.Big, transactionId));
                }, false);

                AddRow(row);
            }

            if (profileType == StatusAccountProfileType.Big && transactionId <= 0)
            {
                if (_status != null)
                {
                    AddHeaderRow("Subscription");

                    _subscribe = AddSwitchRow("Subscribe");
                    _subscribe.Switch.IsToggled    = _status.IsSubscribed(_accountId);
                    _subscribe.Switch.ToggledAsync = Subscribe_Toggled;
                    _subscribe.SetDetailViewIcon(Icons.Check);

                    _notification = AddSwitchRow("Notification");
                    _notification.Switch.IsToggled    = UIApp.Current.IsPushChannelSubscribed(_accountIndex);
                    _notification.Switch.ToggledAsync = Notification_Toggled;
                    _notification.SetDetailViewIcon(Icons.Bell);

                    AddFooterRow();
                }

                if (profileData == null || profileType == StatusAccountProfileType.Big)
                {
                    UIApp.Run(() => ProfileManager.Current.GetProfileData(_accountId, ProfileDownloadType.ForceDownload, true));
                }
            }

            IsBusy = true;
        }
コード例 #4
0
        public override void UnpackTransactionData(Unpacker unpacker, ushort size)
        {
            base.UnpackTransactionData(unpacker, size);
            GroupId = unpacker.UnpackLong();

            if (unpacker.UnpackBool())
            {
                GroupIndex = new Index(unpacker);
            }
        }
コード例 #5
0
ファイル: TodoList.cs プロジェクト: HeleusCore/Heleus.Todo
        public TodoList(long listId, long transactionId, Todo todo, ServiceNode serviceNode)
        {
            ListId = listId;
            LastProcessedTransactionId = transactionId;
            Todo = todo;

            if (LastProcessedTransactionId != Operation.InvalidTransactionId)
            {
                _historyTransactionIds.Add(transactionId);
            }

            ServiceNode = serviceNode;
            Index       = BuildIndex(listId);
        }
コード例 #6
0
        public (long, short, long, short) GetFriendAccountId(Chain.Index index)
        {
            var a1 = index.GetLong(1);
            var k1 = index.GetShort(2);
            var a2 = index.GetLong(3);
            var k2 = index.GetShort(4);

            if (a1 != AccountId)
            {
                return(a1, k1, a2, k2);
            }

            return(a2, k2, a1, k2);
        }
コード例 #7
0
        public Chat GetChat(Chain.Index index, bool createIfMissing)
        {
            if (_chats.TryGetValue(index, out var chat))
            {
                return(chat);
            }

            if (createIfMissing)
            {
                return(new Chat(index, this));
            }

            return(null);
        }
コード例 #8
0
ファイル: TodoList.cs プロジェクト: HeleusCore/Heleus.Todo
 public TodoList(Unpacker unpacker, Todo todo, ServiceNode serviceNode)
 {
     unpacker.Unpack(out byte dataVersion);
     unpacker.Unpack(out ListId);
     LastProcessedTransactionId = unpacker.UnpackLong();
     if (unpacker.UnpackBool())
     {
         LastUsedSecretKeyInfo = SecretKeyInfo.Restore(unpacker);
     }
     unpacker.Unpack(_items, (u) => new TodoTask(u));
     unpacker.Unpack(_historyTransactionIds);
     if (unpacker.UnpackBool())
     {
         CurrentListNameRecord = new TodoRecordStorage <TodoListNameRecord>(unpacker);
     }
     Index       = BuildIndex(ListId);
     ServiceNode = serviceNode;
     Todo        = todo;
 }
コード例 #9
0
 public PushSubscription(PushSubscriptionAction action, long accountId, Chain.Index channel)
 {
     Action    = action;
     AccountId = accountId;
     Channel   = channel;
 }
コード例 #10
0
 public static async Task <PackableResult <LastTransactionCountInfo> > DownloadIndexLastTransactionInfo(ClientBase client, ChainType chainType, int chainId, uint chainIndex, long groupId, Chain.Index index)
 {
     return((await client.DownloadPackableResult(GetIndexLastTransactionInfoQueryPath(chainType, chainId, chainIndex, groupId, index), (u) => new LastTransactionCountInfo(u))).Data);
 }
コード例 #11
0
 public static string GetIndexLastTransactionInfoQueryPath(ChainType chainType, int chainId, uint chainIndex, long groupId, Chain.Index index)
 {
     return(GetQuery(chainType, chainId, chainIndex, FeatureId, GroupQueryHandler.IndexLastTransactionInfoAction, $"{groupId.ToString()}/{index.HexString}"));
 }
コード例 #12
0
 public static string GetLastTransactionInfoBatchQueryPath(ChainType chainType, int chainId, uint chainIndex, IReadOnlyList <long> accountIds, Chain.Index index)
 {
     return(GetQuery(chainType, chainId, chainIndex, FeatureId, AccountIndexQueryHandlerBase.LastTransactionInfoBatchAction, $"{HexPacker.ToHex((p) => p.Pack(accountIds))}/{index.HexString}"));
 }
コード例 #13
0
        public override Result QueryFeature(FeatureQuery query)
        {
            if (query.Action == LastTransactionInfoAction)
            {
                if (query.GetString(1, out var indexHex))
                {
                    var index = new Chain.Index(indexHex);
                    return(GetAccountData <AccountIndexContainerBase>(query, 0, (container) =>
                    {
                        return new PackableResult(container?.GetLastTransactionInfo(index) ?? LastTransactionCountInfo.Empty);
                    }));
                }
            }
            else if (query.Action == LastTransactionInfoBatchAction)
            {
                if (query.GetString(1, out var indexHex))
                {
                    var index = new Chain.Index(indexHex);

                    return(GetBatchData <long>(query, 0, (u, l) => u.Unpack(l), (accountIds) =>
                    {
                        var batchResult = new LastTransactionCountInfoBatch();

                        foreach (var accountId in accountIds)
                        {
                            var account = CurrentChain.GetFeatureAccount(accountId);
                            var info = account?.GetFeatureContainer <AccountIndexContainerBase>(FeatureId)?.GetLastTransactionInfo(index) ?? LastTransactionCountInfo.Empty;

                            batchResult.Add(info != null, accountId, info);
                        }

                        return new PackableResult(batchResult);
                    }));
                }
            }
            else if (query.Action == LastTransactionInfoIndicesBatchAction)
            {
                if (query.GetLong(0, out var accountId) && query.GetString(1, out var indicesHex))
                {
                    return(GetBatchData <Chain.Index>(query, 1, (unpacker, list) => unpacker.Unpack(list, (u) => new Chain.Index(u)), (indices) =>
                    {
                        var account = CurrentChain.GetFeatureAccount(accountId);
                        var container = account?.GetFeatureContainer <AccountIndexContainerBase>(FeatureId);

                        if (account != null)
                        {
                            var batchResult = new LastTransactionCountInfoBatch();

                            foreach (var index in indices)
                            {
                                var info = container?.GetLastTransactionInfo(index);
                                batchResult.Add(info != null, accountId, info);
                            }

                            return new PackableResult(batchResult);
                        }

                        return Result.AccountNotFound;
                    }));
                }
            }

            return(Result.InvalidQuery);
        }
コード例 #14
0
 public ViewChatSchemeAction(SchemeData schemeData) : base(schemeData)
 {
     Index = new Chain.Index(GetString(StartIndex));
 }
コード例 #15
0
 public MessageSentEvent(string text, Chain.Index index, MessageNode node, HeleusClientResponse heleusClientResponse) : base(node, heleusClientResponse)
 {
     Text  = text;
     Index = index;
 }
コード例 #16
0
 public PushSubscription(Unpacker unpacker)
 {
     Action = (PushSubscriptionAction)unpacker.UnpackByte();
     unpacker.Unpack(out AccountId);
     Channel = new Chain.Index(unpacker);
 }
コード例 #17
0
 public static string GetLastTransactionInfoQueryPath(ChainType chainType, int chainId, uint chainIndex, long accountId, Chain.Index index)
 {
     return(GetQuery(chainType, chainId, chainIndex, FeatureId, AccountIndexQueryHandlerBase.LastTransactionInfoAction, $"{accountId}/{index.HexString}"));
 }
コード例 #18
0
 public bool IsNodeChat(Chain.Index index)
 {
     return(_chats.ContainsKey(index));
 }
コード例 #19
0
 public static async Task <PackableResult <LastTransactionCountInfoBatch> > DownloadLastTransactionInfoBatch(ClientBase client, ChainType chainType, int chainId, uint chainIndex, IReadOnlyList <long> accountIds, Chain.Index index)
 {
     return((await client.DownloadPackableResult(GetLastTransactionInfoBatchQueryPath(chainType, chainId, chainIndex, accountIds, index), (u) => new LastTransactionCountInfoBatch(u))).Data);
 }
コード例 #20
0
 public MessageSubmitAccount(KeyStore account, MessageNode node, long receiverAccountId, short receiverKeyIndex, short keyIndex, Chain.Index index, bool requiresSecretKey) : base(node.ServiceNode, keyIndex, index, requiresSecretKey)
 {
     Account         = account;
     FriendAccountId = receiverAccountId;
     FriendKeyIndex  = receiverKeyIndex;
     Node            = node;
 }