コード例 #1
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);
        }
コード例 #2
0
        public async Task <MessageSentEvent> SendMessage(Chat chat, string text)
        {
            var index         = chat.Index;
            var submitAccount = ServiceNode.GetSubmitAccount <MessageSubmitAccount>(chat.KeyIndex, index);

            if (submitAccount == null)
            {
                submitAccount = GenerateSubmitAccount(index);
            }

            await GenerateSecretExchangeKey(submitAccount, chat.FriendAccountId, chat.FriendKeyIndex);

            var result = await SetSubmitAccount(submitAccount, true);

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

            if (string.IsNullOrWhiteSpace(text))
            {
                result = new HeleusClientResponse(HeleusClientResultTypes.Ok, (long)ServiceUserCodes.InvalidAttachement);
                goto end;
            }

            var secretKey = submitAccount.DefaultSecretKey;
            var record    = await EncrytpedRecord <MessageRecord> .EncryptRecord(secretKey, new MessageRecord(text));

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

            transaction.EnableFeature <PreviousAccountTransaction>(PreviousAccountTransaction.FeatureId);

            var sharedAccountIndex = transaction.EnableFeature <SharedAccountIndex>(SharedAccountIndex.FeatureId);

            sharedAccountIndex.Index = index;

            var data = transaction.EnableFeature <Data>(Data.FeatureId);

            data.AddBinary(MessageServiceInfo.MessageDataIndex, record.ToByteArray());

            var receiver = transaction.EnableFeature <Receiver>(Receiver.FeatureId);

            receiver.AddReceiver(submitAccount.FriendAccountId);

            transaction.EnableFeature(EnforceReceiverFriend.FeatureId);

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

            if (result.TransactionResult == TransactionResultTypes.Ok)
            {
                if (!_chats.ContainsKey(chat.Index))
                {
                    _chats[chat.Index] = chat;
                    await SaveAsync();
                }

                UIApp.Run(() => chat.DownloadMessages(false));
            }

end:

            var @event = new MessageSentEvent(text, index, this, result);
            await UIApp.PubSub.PublishAsync(@event);

            return(@event);
        }