Пример #1
0
        public async Task InviteAsync(object userIdObj)
        {
            try {
                var userIds = new List <string>();
                var userId  = userIdObj as string;
                if (userId != null)
                {
                    userIds.Add(userId);
                }
                else
                {
                    userIds = userIdObj as List <string>;
                }

                if (userId != null)
                {
                    var memberIds = new List <string> {
                        _sessionService.User.Id
                    };
                    foreach (var id in userIds)
                    {
                        var userResponse = await _codeStreamAgent.GetUserAsync(id);

                        memberIds.Add(userResponse.User.Id);
                    }

                    CsStream stream = null;
                    var      fetchStreamsResponse = await _codeStreamAgent.FetchStreamsAsync(new FetchStreamsRequest {
                        Types = new List <StreamType> {
                            StreamType.direct
                        },
                        MemberIds = memberIds
                    });

                    if (fetchStreamsResponse != null)
                    {
                        stream = fetchStreamsResponse.Streams.FirstOrDefault();
                    }

                    if (stream == null)
                    {
                        stream = await _codeStreamAgent.CreateDirectStreamAsync(memberIds);
                    }

                    if (_sessionService.LiveShareUrl.IsNullOrWhiteSpace())
                    {
                        // user clicked invite before starting a Live Share -- create one now!
                        await StartAsync(stream.Id, null);
                    }
                    else
                    {
                        var postResponse = await _codeStreamAgent.CreatePostAsync(stream.Id, null,
                                                                                  $"Join my Live Share session: {_sessionService.LiveShareUrl}");

                        if (postResponse != null)
                        {
                            // view thread
#pragma warning disable VSTHRD103 // Call async methods when in an async method
                            _browserService.Notify(new ShowStreamNotificationType {
                                Params = new ShowStreamNotification {
                                    StreamId = stream.Id
                                }
                            });
#pragma warning restore VSTHRD103 // Call async methods when in an async method
                        }
                    }
                }
            }
            catch (Exception ex) {
                Log.Error(ex, "Error inviting to Live Share");
            }
        }