Skip to content

Commit

Permalink
Merge pull request #26 from Softeq/feature/intergation
Browse files Browse the repository at this point in the history
Feature/integration with latest NetChat
  • Loading branch information
vadimpylsky authored Dec 18, 2018
2 parents b9744c9 + a232330 commit ca7c4c5
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 32 deletions.
16 changes: 9 additions & 7 deletions Softeq.XToolkit.Chat.Droid/Views/ChatDetailsActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ protected override void DoAttachBindings()
Bindings.Add(this.SetBinding(() => ViewModel.MembersCountText, () => _chatMembersCountTextView.Text));
Bindings.Add(this.SetBinding(() => ViewModel.Summary.AvatarUrl).WhenSourceChanges(() =>
{
_chatPhotoImageView.LoadImageWithTextPlaceholder(
ViewModel.Summary.AvatarUrl,
ViewModel.Summary.Name,
StyleHelper.Style.ChatAvatarStyles,
x => x.Transform(new CircleTransformation()));
Execute.BeginOnUIThread(() =>
{
_chatPhotoImageView.LoadImageWithTextPlaceholder(
ViewModel.Summary.AvatarUrl,
ViewModel.Summary.Name,
StyleHelper.Style.ChatAvatarStyles,
x => x.Transform(new CircleTransformation()));
});
}));
Bindings.Add(this.SetBinding(() => _imagePicker.ViewModel.ImageCacheKey)
.WhenSourceChanges(() =>
Expand All @@ -117,7 +120,6 @@ protected override void DoAttachBindings()
.DownSampleInDip(95, 95)
.Transform(new CircleTransformation())
.IntoAsync(_chatEditedPhotoImageView);
InvalidateOptionsMenu();
});
}));
}
Expand All @@ -134,7 +136,7 @@ private void InitializeMembersRecyclerView()
var swipeItemCallback = new SwipeCallback(this, _membersRecyclerView, ConfigureSwipeForViewHolder);
var swipeItemTouchHelper = new ItemTouchHelper(swipeItemCallback);
swipeItemTouchHelper.AttachToRecyclerView(_membersRecyclerView);

_membersRecyclerView.HasFixedSize = true;
_membersRecyclerView.SetLayoutManager(new GuardedLinearLayoutManager(this));
_membersRecyclerView.AddItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.Vertical));
Expand Down
7 changes: 4 additions & 3 deletions Softeq.XToolkit.Chat.Droid/Views/ChatMessagesActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ protected override void OnDestroy()
{
_conversationsRecyclerView.GetAdapter().Dispose();
_conversationsRecyclerView.ClearOnScrollListeners();
// TODO: remove onTouchListener

base.OnDestroy();
}
Expand Down Expand Up @@ -200,7 +201,7 @@ protected override void DoAttachBindings()
_isAdapterSourceInitialized = true;
}));

Bindings.Add(this.SetBinding(() => _imagePicker.ViewModel.ImageCacheKey).WhenSourceChanges(() =>
Bindings.Add(this.SetBinding(() => _imagePicker.ViewModel.ImageCacheKey).WhenSourceChanges(() =>
{
if (_imagePicker.ViewModel.ImageCacheKey == null)
{
Expand Down Expand Up @@ -312,8 +313,8 @@ private void RemoveAttachment()

private void Send()
{
var args = _imagePicker.ViewModel.ImageCacheKey == null
? null
var args = _imagePicker.ViewModel.ImageCacheKey == null
? null
: new GenericEventArgs<Func<(Task<Stream>, string)>>(_imagePicker.GetStreamFunc());
ViewModel.SendCommand.Execute(args);
CloseEditImageContainer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,34 @@

using System;
using Softeq.XToolkit.RemoteData.HttpClient;
using Softeq.XToolkit.RemoteData;

namespace Softeq.XToolkit.Chat.HttpClient.Requests
{
internal abstract class GetMessagesPagingRequest : BaseRestRequest
{
private readonly string _messageFromId;
private readonly DateTimeOffset? _messageFromDateTime;
private readonly int? _pageSize;

public GetMessagesPagingRequest(string channelId,
string messageFromId = null,
DateTimeOffset? messageFromDateTime = null,
int? pageSize = null)
private readonly string _queryParams;

public GetMessagesPagingRequest(
string channelId,
string messageFromId = null,
DateTimeOffset? messageFromDateTime = null,
int? pageSize = null)
{
ChannelId = channelId;
_messageFromId = messageFromId;
_messageFromDateTime = messageFromDateTime;
_pageSize = pageSize;

var messageCreated = messageFromDateTime.Value.ToString("u");

_queryParams = new QueryStringBuilder()
.AddParam("messageId", messageFromId)
.AddParam("messageCreated", messageCreated)
.AddParam("pageSize", pageSize)
.Build();
}

protected string ChannelId { get; }

public sealed override string EndpointUrl
{
get
{
var urlParams = _messageFromId != null ? $"messageId={_messageFromId}&" : string.Empty;
urlParams += _messageFromDateTime.HasValue ? $"messageCreated={_messageFromDateTime.Value}&" : string.Empty;
urlParams += _pageSize.HasValue ? $"pageSize={_pageSize.Value}" : string.Empty;
return string.IsNullOrEmpty(urlParams) ? MainEndpointUrl : $"{MainEndpointUrl}?{urlParams.Trim('&')}";
}
}
public sealed override string EndpointUrl => MainEndpointUrl + _queryParams;

public override bool UseOriginalEndpoint => true;

Expand Down
2 changes: 2 additions & 0 deletions Softeq.XToolkit.Chat.SignalRClient/ClientEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ internal static class ClientEvents
public const string AccessTokenExpired = "AccessTokenExpired";
public const string ExceptionOccurred = "ExceptionOccurred";
public const string RequestSuccess = "RequestSuccess";

public const string RequestValidationFailed = "RequestValidationFailed";
}
}
3 changes: 2 additions & 1 deletion Softeq.XToolkit.Chat.SignalRClient/SignalRAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public SignalRAdapter(IAccountService accountService,

internetConnectionManager.NetworkConnectionChanged += OnNetworkConnectionChanged;

ConnectIfNotConnectedAsync().SafeTaskWrapper();
// TODO YP: need investigate auto-connect (when init before login)
//ConnectIfNotConnectedAsync().SafeTaskWrapper();
}

public IObservable<ChatMessageModel> MessageReceived => _messageReceived;
Expand Down
9 changes: 9 additions & 0 deletions Softeq.XToolkit.Chat.SignalRClient/SignalRClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ public async Task SendAndHandleExceptionsAsync(string methodName, BaseRequest re
tcs.SetResult(true);
}
});
IDisposable validationFailedSubscription = null;
validationFailedSubscription = _connection.On<Exception, string>(ClientEvents.RequestValidationFailed, (ex, id) =>
{
if (id == requestId)
{
validationFailedSubscription.Dispose();
tcs.SetException(ex);
}
});
request.RequestId = requestId;
await _connection.InvokeAsync(methodName, request).ConfigureAwait(false);
await tcs.Task.ConfigureAwait(false);
Expand Down

0 comments on commit ca7c4c5

Please sign in to comment.