123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- Namespace.register("U.MD.F.H"); //好友聊天和群聊天消息命名空间
- //#region 好友和群聊天记录
- //#region 聊天记录
- /**
- * 好友或者群消息
- * @param {element} 聊天框
- * @param {object} 好友或者群信息
- * @param {int} 第几页
- * @param {string} 变化的样式
- */
- U.MD.F.H.viewFriendsChatRecords = function (el, friendandgroupinfo, page, isgroup) {
- //如果聊天记录在显示,那么隐藏聊天记录
- if (el.style.display == "block") {
- el.style.display = "none";
- U.MD.F.W.chatBoxSize($(el).Parent(3), $(el).Parent()); //调整大小
- }
- //如果聊天记录没有打开,那么打开聊天记录
- else {
- $(el).Child()[1].innerHTML = ""; //清空聊天记录
- U.MD.F.H.chatRecord(el, friendandgroupinfo, page, isgroup);
- el.style.display = "block"; //显示聊天记录框
- }
- U.MD.F.W.chatBoxSize($(el).Parent(8), $(el).Parent()); //调整大小
- }
- //
- /**
- * 聊天记录分页
- * @param {element} 聊天框
- * @param {object} 好友或者群信息
- * @param {int} 第几页
- * @param {string} 变化的样式
- */
- U.MD.F.H.chatRecord = function (el, friendandgroupinfo, page, isgroup) {
- var _end = page * 20, //分页的结束位置
- _start = _end - 20; //分页的开始位置
- //群的获取聊天记录
- if (isgroup) {
- U.A.Request(US.CD, [US.DB, "UseStudio_Friends", "GetGroupChatHistory",
- friendandgroupinfo.GroupManageID, _start, _end], U.MD.F.H.asynChatRecord, ["", el, friendandgroupinfo, page, isgroup]);
- }
- //好友的获取聊天记录
- else {
- U.A.Request(US.CD, [US.DB, "UseStudio_Friends", "GetFriendChatHistory",
- US.userInfo.userid, friendandgroupinfo.UserId, _start, _end], U.MD.F.H.asynChatRecord, ["", el, friendandgroupinfo, page, isgroup]);
- }
- }
- //获取聊天记录异步
- U.MD.F.H.asynChatRecord = function (r) {
- var _context = r.context,
- _recentcontactsel = _context[1], //聊天记录元素
- _friendandgroupinfo = _context[2], //好友或者群的信息
- _page = _context[3], //页数
- _isgroup = _context[4], //是否群聊天记录
- _childs = $(_recentcontactsel).Child(); //0 聊天记录查看区域 1 分页区域
- r = r.value;
- _childs[0].innerText = ""; //清空聊天记录
- if (r.length) {
- //打印聊天记录
- U.MD.F.H.printChatRecord(_childs[0], r, _friendandgroupinfo);
- //聊天记录到底部
- _childs[0].scrollTop = _childs[0].scrollHeight;
- //如果没有加载分页控件,则加载
- // if (!$("div", _childs[1]).length) {
- // //调用分页接口打印分页
- // new U.UF.P.page(_childs[1], r[0].AllC, 50, _page,
- // function (_page) { U.MD.F.H.chatRecord(_recentcontactsel, _friendandgroupinfo, _page, _isgroup); }, 1);
- // }
- //如果没有加载日历控件,则加载
- if (!$("div", _childs[1]).length) {
- var _calendar = $$("div", { "id": "U_MD_F_H_calendar", "style": { "width": "16px", "height": "17px", "background-image": "url('/img/YS2017.png')", "display": "inline-block", "background-repeat": "no-repeat", "background-position": "-855px -481px", "margin": "5px 0 5px 13px"} }, _childs[1]),
- _firstPage = $$("div", { "id": "U_MD_F_H_firstPage", "style": { "width": "13px", "height": "18px", "background-image": "url('/img/YS2017.png')", "display": "inline-block", "background-repeat": "no-repeat", "background-position": "-891px -481px", "margin": "5px 20px 4px 127px"} }, _childs[1]),
- _previousPage = $$("div", { "id": "U_MD_F_H_previousPage", "style": { "width": "11px", "height": "18px", "background-image": "url('/img/YS2017.png')", "display": "inline-block", "background-repeat": "no-repeat", "background-position": "-924px -481px", "margin": "5px 20px 4px 0px"} }, _childs[1]),
- _nextPage = $$("div", { "id": "U_MD_F_H_nextPage", "style": { "width": "10px", "height": "17px", "background-image": "url('/img/YS2017.png')", "display": "inline-block", "background-repeat": "no-repeat", "background-position": "-957px -481px", "margin": "5px 20px 4px 0px"} }, _childs[1]),
- _lastPage = $$("div", { "id": "U_MD_F_H_lastPage", "style": { "width": "13px", "height": "18px", "background-image": "url('/img/YS2017.png')", "display": "inline-block", "background-repeat": "no-repeat", "background-position": "-987px -481px", "margin": "5px 13px 4px 0px"} }, _childs[1]),
- _calendarPlace = $$('div', { "style": { cssText: "position:absolute; margin-bottom: 297px;"} }, _calendar)
- $("#U_MD_F_H_firstPage")[0].onclick = function () {
- _page = 1;
- U.MD.F.H.chatRecord(_recentcontactsel, _friendandgroupinfo, _page, _isgroup);
- }
- $("#U_MD_F_H_previousPage")[0].onclick = function () {
- _page--;
- U.MD.F.H.chatRecord(_recentcontactsel, _friendandgroupinfo, _page, _isgroup);
- }
- $("#U_MD_F_H_nextPage")[0].onclick = function () {
- _page++;
- U.MD.F.H.chatRecord(_recentcontactsel, _friendandgroupinfo, _page, _isgroup);
- }
- $("#U_MD_F_H_lastPage")[0].onclick = function () {
- _page = Math.ceil(r[0].AllC / 20);
- U.MD.F.H.chatRecord(_recentcontactsel, _friendandgroupinfo, _page, _isgroup);
- }
- // $("#U_MD_F_H_calendar")[0].onclick = function () { U.MD.UI.calendar(this, _calendarPlace); }
- }
- }
- else {
- U.alert("服务器繁忙,请稍后获取聊天记录");
- }
- }
- /**
- * 聊天记录分页
- * @param {element} 聊天框
- * @param {object} 聊天信息
- * @param {object} 好友信息
- */
- U.MD.F.H.printChatRecord = function (el, recordinfo, friendandgroupinfo) {
- var _tempel,
- _temponeel,
- _temptwoel,
- i = recordinfo.length,
- _frag = $$("frag");
- //循环打印群聊天记录
- while (i--) {
- //U.MD.F.W.printFileContent
- if (recordinfo[i].MessageContent? recordinfo[i].MessageContent.indexOf("fileName") != -1 : recordinfo[i].GroupMessageContent.indexOf("fileName") != -1) {
- _tempel = $$("div", { "className": "U_MD_F_LO" }, _frag);
- _temponeel = $$("div", { "className": "U_MD_F_LOT" }, _tempel);
- $$("div", { "className": "U_MD_F_LOTN", "innerHTML": recordinfo[i].MessageDescript || recordinfo[i].GroupMessageSendUsername || friendandgroupinfo.FriendsDescript || friendandgroupinfo.GroupManageName }, _temponeel);
- $$("div", { "className": "U_MD_F_LOTT", "innerHTML": U.UF.D.getDateInterval(recordinfo[i].MessageSendTime || recordinfo[i].GroupMessageSendTime) }, _temponeel);
- var _data = JSON.parse(recordinfo[i].MessageContent);
- if (_data.fileType == "jpg" || _data.fileType == "png" || _data.fileType == "mp4") { //判断文件格式是否为图片或者视频 , 不是的话加边框
- var _content = $$("div", { "style": { "cssText": "padding:8px 8px 8px 8px;background:#fff;border-radius:2px;margin-top:12px;position:relative"} }, _tempel);
- }else{
- var _content = $$("div", { "style": { "cssText": "padding:8px 8px 8px 8px;background:#fff;border-radius:2px;margin-top:12px;border:1px #d3d3d3 solid;background:#f9f9f9;"} }, _tempel);
- }
- U.MD.F.W.printFileContent(_data, _content);
- } else {
- _tempel = $$("div", { "className": "U_MD_F_LO" }, _frag);
- _temponeel = $$("div", { "className": "U_MD_F_LOT" }, _tempel);
- $$("div", { "className": "U_MD_F_LOTN", "innerHTML": recordinfo[i].MessageDescript || recordinfo[i].GroupMessageSendUsername || friendandgroupinfo.FriendsDescript || friendandgroupinfo.GroupManageName }, _temponeel);
- $$("div", { "className": "U_MD_F_LOTT", "innerHTML": U.UF.D.getDateInterval(recordinfo[i].MessageSendTime || recordinfo[i].GroupMessageSendTime) }, _temponeel);
- $$("div", { "className": "U_MD_F_LOD", "innerHTML": recordinfo[i].MessageContent || recordinfo[i].GroupMessageContent }, _tempel);
- }
- }
- el.appendChild(_frag);
- }
- //#endregion
- /**
- * 发送消息统一调用函数
- * @param {object} 统一发送好友信息id
- ----------好友id
- ----------群id
- ----------群发id
- * @param {element} 发送信息原
- * @param {element} 打印区域函数
- * @param {boolean} 判断消息
- ---------- true 获取群消息 或者发送 群消息
- ---------- false 获取好友消息或者 获取好友消息
- * @param {boolean} 是否清空发送
- */
- U.MD.F.H.sendFriendOrGroupChatMessage = function (friendandgroupinfo, chateditel, chatcontentnewsel, isgroup, isupload) {
- var _newsinfo, //发送消息的打印的变量
- _chatcontent = chateditel.innerHTML, //发送的内容
- _friendid = friendandgroupinfo.UserId || friendandgroupinfo.GroupManageID; //发送给好友或者群的id
- //不为空允许发送内容
- if (_chatcontent.isHtmlNull()) {
- U.MD.F.H.sendChatMessageToDb(_friendid, _chatcontent, null, isgroup); //调用发送数据库的函数
- //发送消息的信息
- _newsinfo = [{
- "UserId": US.userInfo.userid,
- "Time": new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds(),
- "Content": _chatcontent,
- "IMG": US.userInfo.UserThumbnailImageHead,
- "Name": US.userInfo.UserNickName
- }]
- //内容显示在聊天区域
- if (isgroup) {
- U.MD.F.W.printGroupChatMessage(chatcontentnewsel, _newsinfo, true); //打印在群聊天
- }
- else {
- U.MD.F.W.printFriendChatMessage(chatcontentnewsel, _newsinfo, true); //打印在好友聊天
- }
- //判断是否是上传文件,如果是上传文件,那么不清空输入区域的内容直接显示到聊天区域。
- if (!isupload) {
- chateditel.innerText = ""
- }
- }
- }
- /**
- * 查看聊天 好友或者群
- * @param {element} 发送好友的id
- * @param {string} 发送的内容
- ----------如果这里为空 那么就是获取好友信息
- * @param {function} 发送成功回调函数
- * @param {boolean} 判断消息
- ---------- true 获取群消息 或者发送 群消息
- ---------- flase 获取好友消息或者 获取好友消息
- */
- U.MD.F.H.sendChatMessageToDb = function (friendid, message, cb, isgroup) {
- var _friendorgroupinfo, //好友或者群信息
- _userinfo = US.userInfo; //用户的信息
- //发送群消息到数据库
- if (isgroup) {
- U.A.Request(US.CD, [US.DB, "UseStudio_Friends", "SendMessageToGroup", friendid, Guid.newGuid(), _userinfo.UserId, message, _userinfo.UserNickName], function () { }, [""]);
- }
- //发送好友消息到数据库
- else {
- U.A.Request(US.CD, [US.DB, "UseStudio_Friends", "SentMessageToFriend", _userinfo.UserId, friendid, _userinfo.UserNickName, message, 0, false], function () { }, [""]);
- }
- //发送消息后根据id得到发送的消息的群或者用户id得到详细信息,然后把这个群或者用户的信息变成第一个最近联系人的第一个
- //如果是群,则获取群用户信息
- if (isgroup) {
- _friendorgroupinfo = U.Json.select(US.friend.group, { "GroupManageID": friendid })[0];
- }
- //如果是聊天好友,则获取群用户信息
- else {
- //从最近聊天里面获取信息
- _friendorgroupinfo = U.Json.select(US.friend.recentcontacts, { "UserId": friendid })[0];
- //如果最近聊天里面没有获取用户的信息,那么就从好友里面获取
- if (_friendorgroupinfo) {
- //获取好友群消息
- _friendorgroupinfo = U.Json.select(US.friend.friends, { "UserId": friendid })[0];
- }
- }
- //如果判断发送的好友或者是群确实在用户好友里,则把该用户设置为最近联系人
- if (_friendorgroupinfo) {
- U.MD.F.H.recentContacts(_friendorgroupinfo); //设置最近联系人
- }
- }
- /**
- * 查看聊天 好友或者群
- * @param {element} 发送好友的id
- * @param {string} 发送的内容
- ----------如果这里为空 那么就是获取好友信息
- * @param {function} 发送成功回调函数
- * @param {boolean} 判断消息
- ---------- true 获取群消息 或者发送 群消息
- ---------- flase 获取好友消息或者 获取好友消息
- */
- U.MD.F.H.getFriendOrGroupNews = function (friendid, cb, isgroup) {
- var _userinfo = US.userInfo; //获取用户的资料
- //如果是群信息获取
- if (isgroup) {
- U.A.Request(US.CD, [US.DB, "UseStudio_Friends", "GetGroupUnreadMessage", _userinfo.UserId, friendid], cb, ["", friendid, isgroup]);
- }
- //如果是好友信息的获取
- else {
- U.A.Request(US.CD, [US.DB, "UseStudio_Friends", "GetFriendUnreadMessage", _userinfo.UserId, friendid], cb, ["", friendid, isgroup]);
- }
- }
- /**
- * 生成最近联系人
- * @param {object} 用户信息
- */
- U.MD.F.H.recentContacts = function (userinfo) {
- var _recentcontactsel,
- _num,
- _recentcontactsinfo,
- _contentel = $("#U_MD_F_H_ZLZ")[0];
- if (US.friend.recentcontacts) {
- //判断联系人是否已经在最近联系人中
- _num = US.friend.recentcontacts.objIndexOf({ "UserId": userInfo.userid || userinfo.GroupManageID });
- //如果存在最近联系人,那么直接从最近联系人中找到
- if (_num > -1) {
- _recentcontactsinfo = US.friend.recentcontacts.splice(_num, 1)[0];
- }
- //否则生成一个新的最近联系人
- else {
- //生成一个新的最近联系人
- _recentcontactsinfo = new U.MD.F.T.recentContactsEntity(userinfo.GroupManageID || userInfo.userid,
- userinfo.GroupManageName || userinfo.UserName, userinfo.UserImageHead || "", userinfo.UserNickName || "",
- userinfo.UserThumbnailImageHead || "", userinfo.maxMessageSendTime || new Date(),
- userinfo.GroupManageDescript || userinfo.FriendsDescript, userinfo.GroupManageRemark || userinfo.UserIndividualitysignature || "",
- userinfo.IsLogin || 3, userinfo.GroupManageID ? 1 : 0);
- }
- //如果存在就直接置顶 不存在添加新的
- US.friend.recentcontacts.unshift(_recentcontactsinfo);
- //找到最近联系人按钮
- _recentcontactsel = $("#U_MD_F_H_ZLTA").childs()[2];
- _recentcontactsel = $(_recentcontactsel).Child()[0];
- //如果当前显示的不是好友、群而是最近联系人,那么则重新打印
- if (_recentcontactsel.className.indexOf("U_MD_F_H_ZLTSO") > -1) {
- _recentcontactsel = $("div@TID=" + (userinfo.GroupManageID || userInfo.userid), $("#U_MD_F_H_ZLZ")[0])[0]; //获取最近联系人
- //如果最近联系人原本就存在,则直接追加到最前面
- if (_recentcontactsel) {
- ($(_recentcontactsel).appendTo(_contentel, 0, _contentel.firstChild)); //追加到第一个
- }
- //否则打印最近联系人
- else {
- U.MD.F.printFriendOrGroup(_contentel, US.friend.recentcontacts[0], true); //插入最新联系人在最前面
- }
- }
- }
- }
- //#endregion
|