Beispiel #1
0
 public MsgItemSelector(ChatDetail p_owner)
 {
     _myMsg     = (DataTemplate)p_owner.GetResource("MyMsgTemplate");
     _myFile    = (DataTemplate)p_owner.GetResource("MyFileTemplate");
     _myLink    = (DataTemplate)p_owner.GetResource("MyLinkTemplate");
     _otherMsg  = (DataTemplate)p_owner.GetResource("OtherMsgTemplate");
     _otherFile = (DataTemplate)p_owner.GetResource("OtherFileTemplate");
     _otherLink = (DataTemplate)p_owner.GetResource("OtherLinkTemplate");
 }
Beispiel #2
0
        public async Task ShowDlg(ChatDetail p_detail)
        {
            _detail      = p_detail;
            _tbInfo.Text = $"准备呼叫 [{p_detail.Other.Name}]...";

            if (Kit.IsPhoneUI)
            {
                HideTitleBar = true;
            }
            else
            {
                IsPinned = true;
                SetSize(600, -60);
            }
            var task = ShowAsync();

            // 确认设备权限
            if (!await ExistMediaDevice())
            {
                Close(true);
                Kit.Warn("打开摄像头或麦克风出错!");
                return;
            }

            // 确认在线
            int retry = 1;

            while (true)
            {
                bool suc = await AtMsg.RequestRtcConnection(Kit.UserID, p_detail.OtherID);

                if (suc)
                {
                    break;
                }

                // 不在线重试
                if (retry++ > 4)
                {
                    Close(true);
                    Kit.Warn($"等待已超时,[{p_detail.Other.Name}] 未接受邀请!");
                    return;
                }

                await Task.Delay(TimeSpan.FromSeconds(5));

                _tbInfo.Text = $"正在第 {retry} 次呼叫 [{p_detail.Other.Name}]...";
            }

            _tbInfo.Text = $"正在等待 [{p_detail.Other.Name}] 接受邀请...";
            await task;
        }
Beispiel #3
0
        /// <summary>
        /// 显示聊天对话框
        /// </summary>
        /// <param name="p_otherID">对方ID</param>
        /// <param name="p_otherName">null时自动查询</param>
        public static void ShowDlg(long p_otherID, string p_otherName = null)
        {
            if (string.IsNullOrEmpty(p_otherName))
            {
                p_otherName = AtState.GetScalar <string>($"select name from ChatMember where id={p_otherID}");
                if (string.IsNullOrEmpty(p_otherName))
                {
                    p_otherName = p_otherID.ToString();
                }
            }

            Dlg dlg;

            if (Kit.IsPhoneUI)
            {
                dlg = new Dlg {
                    Title = p_otherName,
                };
            }
            else
            {
                dlg = new Dlg()
                {
                    IsPinned = true,
                    Height   = 500,
                    Width    = 400,
                    Title    = p_otherName,
                };
            }

            ChatDetail chat = new ChatDetail();

            chat.OtherID = p_otherID;
            dlg.Content  = chat;
            dlg.Show();
        }
Beispiel #4
0
        /// <summary>
        /// 显示未读提示
        /// </summary>
        /// <param name="p_letter"></param>
        static void ShowUnreadNotify(Letter p_letter)
        {
            // 避免过多
            if (SysVisual.NotifyList.Count > 5)
            {
                return;
            }

            var notify = new NotifyInfo();

            // 不自动关闭
            notify.DelaySeconds = 0;
            notify.Link         = "查看内容";
            notify.LinkCallback = (e) =>
            {
                Letter l = (Letter)e.Tag;
                // 关闭所有对方为同一人的提示
                foreach (var ni in SysVisual.NotifyList)
                {
                    if (ni.Tag is Letter letter && letter.OtherID == l.OtherID)
                    {
                        Kit.CloseNotify(ni);
                    }
                }
                Kit.RunAsync(() => ChatDetail.ShowDlg(l.OtherID, l.OtherName));
            };

            switch (p_letter.LetterType)
            {
            case LetterType.Text:
                string msg;
                if (p_letter.Content.Length > 9)
                {
                    msg = p_letter.Content.Substring(0, 9) + "…";
                }
                else
                {
                    msg = p_letter.Content;
                }
                notify.Message = string.Format("💡 {0}\r\n{1}", p_letter.OtherName, msg);
                break;

            case LetterType.File:
                notify.Message = string.Format("🏬 {0}发来文件", p_letter.OtherName);
                break;

            case LetterType.Image:
                notify.Message = string.Format("🌄 {0}发来图片", p_letter.OtherName);
                break;

            case LetterType.Video:
                notify.Message = string.Format("🌉 {0}发来视频", p_letter.OtherName);
                break;

            case LetterType.Voice:
                notify.Message = string.Format("📢 {0}发来语音", p_letter.OtherName);
                break;

            case LetterType.Link:
                notify.Message = string.Format("💨 {0}发来链接", p_letter.OtherName);
                break;

            default:
                break;
            }
            notify.Tag = p_letter;
            SysVisual.NotifyList.Add(notify);
            //await SysVisual.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => SysVisual.NotifyList.Add(notify)));
        }