Exemple #1
0
        public static async Task InsertOrUpdateItem(CustomServicePackage package)
        {
            var item = await SDKProperty.SQLiteConn.FindAsync <DB.ContactDB>(package.from.ToInt());

            if (item != null && item.UserId != 0)
            {
                item.HeadImgMD5 = package.data.photo;
                item.Mobile     = package.data.mobile;
                await SDKProperty.SQLiteConn.UpdateAsync(item);
            }
            else
            {
                item = new DB.ContactDB();


                item.HeadImgMD5 = package.data.photo;
                item.Mobile     = package.data.mobile;
                item.UserId     = package.from.ToInt();
                try
                {
                    await SDKProperty.SQLiteConn.InsertAsync(item);
                }
                catch (Exception ex)
                {
                    SDKClient.logger.Error($"消息处理异常:error:{ex.Message},stack:{ex.StackTrace};\r\n");
                }
            }
        }
Exemple #2
0
        internal void CustomService(CustomServicePackage package)
        {
            int            id     = package.from.ToInt();
            TempCustomItem chatVM = this.Items.FirstOrDefault(t => t.ID == id);

            if (chatVM != null)
            {
                App.Current.Dispatcher.Invoke(new Action(() =>
                {
                    this.Items.Remove(chatVM);
                }));
            }
        }
Exemple #3
0
        public void SetSession(CustomServicePackage package)
        {
            if (package.data.type == 3)
            {
                return;
            }


            if (package.data.type == (int)SDKClient.SDKProperty.customOption.over)//结束
            {
                ChatViewModel chatVM = this.Items.FirstOrDefault(info => info.ID == package.data.originTo.ToInt());
                //没有条目
                if (chatVM == null)
                {
                    return;
                }
                else
                {
                    if (((chatVM.Model as ChatModel).Chat as UserModel).HeadImg.Equals(ImagePathHelper.DefaultUserHead))
                    {
                        ((chatVM.Model as ChatModel).Chat as UserModel).HeadImg = package.data.photo ?? ImagePathHelper.DefaultUserHead;
                    }

                    if (chatVM.Chat.LastMsg != null)
                    {
                        chatVM.Chat.LastMsg.SendTime = package.time.Value;
                    }
                }

                chatVM.AddMessageTip("结束聊天");
                chatVM.IsSessionEnd = true;
                chatVM.SessionId    = string.Empty;
                chatVM.StartOrStopSession(false);
                chatVM.sessionType = 0;
                App.Current.Dispatcher.Invoke(() =>
                {
                    AppData.MainMV.ChatListVM.ResetSort();
                });
            }
            else if (package.data.type == (int)SDKClient.SDKProperty.customOption.conn)//接入
            {
                ChatViewModel chatVM = this.Items.FirstOrDefault(info => info.ID == package.from.ToInt());
                if (package.data.originTo == SDKClient.SDKClient.Instance.property.CurrentAccount.userID.ToString())//发送给我的接入
                {
                    //没有条目
                    if (chatVM == null)
                    {
                        IChat chat = new UserModel()
                        {
                            ID = package.from.ToInt(),

                            DisplayName = package.data.shopName ?? package.data.mobile,
                            HeadImg     = package.data.photo ?? ImagePathHelper.DefaultUserHead
                        };


                        ChatModel chatModel = AppData.Current.GetChatViewModel(chat);

                        chatModel.LastMsg = new MessageModel()
                        {
                            SendTime = package.time.Value,
                        };
                        chatVM = new ChatViewModel(chatModel);

                        App.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            this.Items.Add(chatVM);
                        }));
                    }
                    else
                    {
                        if (((chatVM.Model as ChatModel).Chat as UserModel).HeadImg.Equals(ImagePathHelper.DefaultUserHead))
                        {
                            ((chatVM.Model as ChatModel).Chat as UserModel).HeadImg = package.data.photo ?? ImagePathHelper.DefaultUserHead;
                        }

                        if (chatVM.Chat.LastMsg != null)
                        {
                            chatVM.Chat.LastMsg.SendTime = package.time.Value;
                        }
                    }
                    CustomUserModel customUserModel = new CustomUserModel()
                    {
                        AppType     = package.data.appType,
                        DeviceName  = package.data.deviceName,
                        DeviceType  = package.data.deviceType,
                        ShopBackUrl = package.data.shopBackUrl,
                        ShopId      = package.data.shopId,
                        ShopName    = package.data.shopName ?? package.data.mobile,
                        //Mobile = package.data.mobile
                    };
                    chatVM.CustomUserModel = customUserModel;
                    chatVM.SessionId       = package.data.sessionId;
                    if (!string.IsNullOrEmpty(package.data.address))
                    {
                        Task.Run(async() =>
                        {
                            chatVM.CustomUserModel.Address = await SDKClient.SDKClient.Instance.GetAddressByIP(package.data.address).ConfigureAwait(false);
                        });
                    }

                    chatVM.IsDisplayStartSession = true;
                    chatVM.sessionType           = 1;
                    //if((chatVM.Model as ChatModel).LastMsg?.Content!= "您好!欢迎光临满金店,请问有什么可以帮到您?")
                    //    chatVM.SendTextMsgToServer("您好!欢迎光临满金店,请问有什么可以帮到您?");
                    chatVM.StartOrStopSession(true);
                    FlashIcon(chatVM, false);
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        AppData.MainMV.ChatListVM.ResetSort();
                    });
                }
                else
                {
                    if (chatVM == null)
                    {
                        return;
                    }
                    else
                    {
                        if (((chatVM.Model as ChatModel).Chat as UserModel).HeadImg.Equals(ImagePathHelper.DefaultUserHead))
                        {
                            ((chatVM.Model as ChatModel).Chat as UserModel).HeadImg = package.data.photo ?? ImagePathHelper.DefaultUserHead;
                        }

                        if (chatVM.Chat.LastMsg != null)
                        {
                            chatVM.Chat.LastMsg.SendTime = package.time.Value;
                        }
                    }
                    CustomUserModel customUserModel = new CustomUserModel()
                    {
                        // Address = package.data.address,
                        DeviceName  = package.data.deviceName,
                        DeviceType  = package.data.deviceType,
                        ShopBackUrl = package.data.shopBackUrl,
                        //Mobile = package.data.mobile,
                        ShopId   = package.data.shopId,
                        ShopName = package.data.shopName ?? package.data.mobile,
                    };
                    chatVM.CustomUserModel = customUserModel;
                    chatVM.SessionId       = package.data.sessionId;
                    if (!string.IsNullOrEmpty(package.data.address))
                    {
                        Task.Run(async() =>
                        {
                            chatVM.CustomUserModel.Address = await SDKClient.SDKClient.Instance.GetAddressByIP(package.data.address).ConfigureAwait(false);
                        });
                    }

                    chatVM.IsDisplayStartSession = false;
                    chatVM.sessionType           = 2;
                    //  chatVM.AddMessageTip("当前用户正在和其他客服进行沟通中", isSetLastMsg: false);
                    chatVM.StartOrStopSession(false);

                    App.Current.Dispatcher.Invoke(() =>
                    {
                        AppData.MainMV.ChatListVM.ResetSort();
                    });
                }
            }
        }