Esempio n. 1
0
        public async Task <AcceptInvitationEvent> AcceptFriendInvitation(long friendId)
        {
            var submitAccount = ServiceNode.GetSubmitAccounts <SubmitAccount>(MessageServiceInfo.SubmitAccountIndex).FirstOrDefault();
            var result        = await SetSubmitAccount(submitAccount);

            if (result != null)
            {
                goto end;
            }

            var transaction = NewFriendTransaction(AccountId, ChainId, FriendRequestMode.AcceptInvitation, friendId);

            result = await _client.SendDataTransaction(transaction, true);

            if (result.TransactionResult == TransactionResultTypes.Ok)
            {
                UIApp.Run(() => DownloadFriends(false));
            }

end:

            var @event = new AcceptInvitationEvent(friendId, this, result);
            await UIApp.PubSub.PublishAsync(@event);

            return(@event);
        }
Esempio n. 2
0
        async Task GenerateDefaultExchangeKeys()
        {
            var submitAccounts = ServiceNode.GetSubmitAccounts <MessageSubmitAccount>();

            foreach (var submitAccount in submitAccounts)
            {
                var index            = submitAccount.Index;
                var serviceAccount   = submitAccount.ServiceAccount as ServiceAccountKeyStore;
                var secretKeyManager = submitAccount.SecretKeyManager;

                if (!secretKeyManager.HasSecretKeyType(index, SecretKeyInfoTypes.KeyExchange))
                {
                    (var friendAccountId, var friendKeyIndex, _, _) = GetFriendAccountId(index);
                    await GenerateSecretExchangeKey(submitAccount, friendAccountId, friendKeyIndex);
                }
            }
        }
Esempio n. 3
0
        protected override async Task Run()
        {
            var submitAccount = ServiceNode.GetSubmitAccounts <SubmitAccount>().First();

            var files = new List <VerifyFileJson>();

            for (var i = 0; i < this.files.Length; i++)
            {
                var file = this.files[i];
                try
                {
                    using (var stream = File.OpenRead(file))
                    {
                        var(hash, length) = VerifyFileJson.GenerateHash(stream);

                        var fileJson = new VerifyFileJson {
                            name = Path.GetFileName(file), hashtype = hash.HashType.ToString().ToLower(), hash = Hex.ToString(hash.RawData), length = length, link = GetLink(i)
                        };

                        files.Add(fileJson);
                    }
                }
                catch (Exception ex)
                {
                    Log.IgnoreException(ex);
                    return;
                }
            }

            var verifyJson = new VerifyJson {
                description = description, link = link, files = files
            };
            var result = await VerifyApp.Current.UploadVerification(submitAccount, verifyJson);

            if (result.TransactionResult == TransactionResultTypes.Ok)
            {
                SetSuccess(VerifyApp.Current.GetRequestCode(ServiceNode, VerifyServiceInfo.ChainIndex, ViewVerificationSchemeAction.ActionName, result.Transaction.OperationId));
            }
            else
            {
                SetError(result.GetErrorMessage());
            }
        }
        public override async Task InitAsync()
        {
            if (!IsBusy)
            {
                return;
            }

            var name = TodoApp.GetTodoListName(null);

            var nameId = await Group.DownloadIndexLastTransactionInfo(_serviceNode.Client, Chain.ChainType.Data, _serviceNode.ChainId, TodoServiceInfo.TodoDataChainIndex, _invitation.ListId, TodoServiceInfo.TodoListNameIndex);

            if (nameId?.Item?.TransactionId != Operation.InvalidTransactionId)
            {
                var nameTransaction = (await _serviceNode.Client.DownloadDataTransactionItem(_serviceNode.ChainId, TodoServiceInfo.TodoDataChainIndex, nameId.Item.TransactionId)).Data?.Transaction;
                if (nameTransaction != null)
                {
                    var encryptedRecord = TodoList.GetEncrytpedTodoRedord <TodoListNameRecord>(nameTransaction);
                    var record          = await encryptedRecord.GetRecord(_invitation.SecretKey);

                    if (record != null)
                    {
                        name = record.Name;
                    }
                }
            }

            IsBusy = false;

            AddViewRow(new InvitationView(name, _invitation.SenderAccountId));
            AddButtonRow("Profile", Profile);

            AddSubmitRow("Submit", Submit);

            AddHeaderRow("Common.SubmitAccount");
            _submitAccount = AddRow(new SubmitAccountButtonRow(this, () => _serviceNode.GetSubmitAccounts <SubmitAccount>(TodoServiceInfo.TodoSubmitIndex)));
            AddInfoRow("Common.SubmitAccountInfo");
            AddFooterRow();
        }
Esempio n. 5
0
        public async Task <InboxRenameEvent> RenameInbox(short keyIndex, string title)
        {
            var submitAccount = ServiceNode.GetSubmitAccounts <SubmitAccount>(MessageServiceInfo.SubmitAccountIndex).FirstOrDefault();
            var result        = await SetSubmitAccount(submitAccount);

            if (result != null)
            {
                goto end;
            }

            if (string.IsNullOrEmpty(title) || title.Length > MessageServiceInfo.MaxInboxNameLength)
            {
                result = new HeleusClientResponse(HeleusClientResultTypes.Ok, (long)ServiceUserCodes.InboxNameInvalid);
                goto end;
            }

            var info = new DataTransaction(AccountId, ChainId, MessageServiceInfo.MessageDataChainIndex);

            info.PrivacyType = DataTransactionPrivacyType.PublicData;

            info.EnableFeature <AccountIndex>(AccountIndex.FeatureId).Index = MessageServiceInfo.GetInboxIndex(keyIndex);
            info.EnableFeature <Data>(Data.FeatureId).AddBinary(MessageServiceInfo.MessageDataIndex, new InboxNameRecord(true, title).ToByteArray());

            result = await _client.SendDataTransaction(info, true);

            if (result.TransactionResult == TransactionResultTypes.Ok)
            {
                UIApp.Run(() => DownloadInboxRecords(AccountId));
            }

end:

            var @event = new InboxRenameEvent(title, keyIndex, this, result);
            await UIApp.PubSub.PublishAsync(@event);

            return(@event);
        }
Esempio n. 6
0
        public async Task <UnfriendEvent> Unfriend(long friendId)
        {
            var submitAccount = ServiceNode.GetSubmitAccounts <SubmitAccount>(MessageServiceInfo.SubmitAccountIndex).FirstOrDefault();
            var result        = await SetSubmitAccount(submitAccount);

            if (result != null)
            {
                goto end;
            }

            var transaction = NewFriendTransaction(AccountId, ChainId, FriendRequestMode.Remove, friendId);

            result = await _client.SendDataTransaction(transaction, true);

            if (result.TransactionResult == TransactionResultTypes.Ok)
            {
                UIApp.Run(() => DownloadFriends(false));

                var chats = GetChats(friendId);
                foreach (var chat in chats)
                {
                    _chats.Remove(chat.Index);
                }

                await SaveAsync();

                await UIApp.PubSub.PublishAsync(new MessageNodeRefreshEvent(this));
            }

end:

            var @event = new UnfriendEvent(friendId, this, result);
            await UIApp.PubSub.PublishAsync(@event);

            return(@event);
        }