移动端聊天实现
This commit is contained in:
18
hs-im-app-server/logs/mylog.log.2023-10-06.log
Normal file
18
hs-im-app-server/logs/mylog.log.2023-10-06.log
Normal file
@@ -0,0 +1,18 @@
|
||||
2023-10-06 11:20:31 -Shutting down ExecutorService 'applicationTaskExecutor'
|
||||
2023-10-06 11:59:33 -Starting AppServiceApplication on luojie with PID 10500 (E:\workplace\huashi_project\im-system\hs-im-app-server\target\classes started by coolp in E:\workplace\huashi_project\im-system\hs-im-app-server)
|
||||
2023-10-06 11:59:33 -The following profiles are active: dev
|
||||
2023-10-06 11:59:34 -Tomcat initialized with port(s): 8989 (http)
|
||||
2023-10-06 11:59:34 -Initializing ProtocolHandler ["http-nio-8989"]
|
||||
2023-10-06 11:59:34 -Starting service [Tomcat]
|
||||
2023-10-06 11:59:34 -Starting Servlet engine: [Apache Tomcat/9.0.37]
|
||||
2023-10-06 11:59:34 -Initializing Spring embedded WebApplicationContext
|
||||
2023-10-06 11:59:34 -Root WebApplicationContext: initialization completed in 554 ms
|
||||
2023-10-06 11:59:35 -Initializing ExecutorService 'applicationTaskExecutor'
|
||||
2023-10-06 11:59:35 -Starting ProtocolHandler ["http-nio-8989"]
|
||||
2023-10-06 11:59:35 -Tomcat started on port(s): 8989 (http) with context path ''
|
||||
2023-10-06 11:59:35 -Started AppServiceApplication in 2.549 seconds (JVM running for 3.426)
|
||||
2023-10-06 12:00:10 -Initializing Spring DispatcherServlet 'dispatcherServlet'
|
||||
2023-10-06 12:00:10 -Initializing Servlet 'dispatcherServlet'
|
||||
2023-10-06 12:00:10 -Completed initialization in 2 ms
|
||||
2023-10-06 12:00:10 -HikariPool-1 - Starting...
|
||||
2023-10-06 12:00:11 -HikariPool-1 - Start completed.
|
||||
@@ -32,7 +32,7 @@ mybatis:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
appConfig:
|
||||
imUrl: http://127.0.0.1:28000
|
||||
imUrl: http://192.168.1.117:28000
|
||||
imVersion: v1
|
||||
appId: 10000
|
||||
adminId: admin
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>common</artifactId>
|
||||
<artifactId>im-common</artifactId>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
|
||||
@@ -14,6 +14,7 @@ public class SyncReq extends RequestBase {
|
||||
private Long lastSequence;
|
||||
//一次拉取多少
|
||||
private Integer maxLimit;
|
||||
private Integer appId;
|
||||
|
||||
private String operater;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<artifactId>service</artifactId>
|
||||
<artifactId>im-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- rabbitmq -->
|
||||
@@ -84,15 +84,10 @@
|
||||
<!-- common -->
|
||||
<dependency>
|
||||
<groupId>com.lld</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<artifactId>im-common</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lld</groupId>
|
||||
<artifactId>im-system</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ConversationController {
|
||||
|
||||
@RequestMapping("/syncConversationList")
|
||||
public ResponseVO syncFriendShipList(@RequestBody @Validated SyncReq req,Integer appId) {
|
||||
req.setAppId(appId);
|
||||
// req.setAppId(appId);
|
||||
return conversationService.syncConversationSet(req);
|
||||
}
|
||||
|
||||
|
||||
@@ -181,9 +181,11 @@ public class ConversationService {
|
||||
queryWrapper.last(" limit " + req.getMaxLimit());
|
||||
queryWrapper.orderByAsc("sequence");
|
||||
|
||||
|
||||
log.info("============================= syncConversationSet ========================");
|
||||
log.info("============================= syncConversationSet ========================");
|
||||
log.info("============================= syncConversationSet ========================");
|
||||
|
||||
log.info(req.toString());
|
||||
|
||||
List<ImConversationSetEntity> list = imConversationSetMapper
|
||||
|
||||
@@ -75,6 +75,9 @@ public class ChatOperateReceiver {
|
||||
//消息接收确认
|
||||
MessageReadedContent messageContent
|
||||
= jsonObject.toJavaObject(MessageReadedContent.class);
|
||||
|
||||
logger.error("==============服务端接收到1106的信号:{}",messageContent);
|
||||
|
||||
messageSyncService.readMark(messageContent);
|
||||
}else if (Objects.equals(command, MessageCommand.MSG_RECALL.getCommand())) {
|
||||
// 撤回消息
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: lld
|
||||
* @author: rowger
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Service
|
||||
@@ -155,7 +155,7 @@ public class MessageStoreService {
|
||||
* @description: 存储单人离线消息
|
||||
* @param
|
||||
* @return void
|
||||
* @author lld
|
||||
* @author lld
|
||||
*/
|
||||
public void storeOfflineMessage(OfflineMessageContent offlineMessage){
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>tcp</artifactId>
|
||||
<artifactId>im-tcp</artifactId>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<mybatis-plus.version>3.3.0</mybatis-plus.version>
|
||||
|
||||
@@ -150,7 +150,6 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<Message> {
|
||||
|| command == GroupEventCommand.MSG_GROUP.getCommand()){
|
||||
logger.info("***********************收到单聊或者群聊消息:{}", msg);
|
||||
|
||||
|
||||
try {
|
||||
String toId = "";
|
||||
CheckSendMessageReq req = new CheckSendMessageReq();
|
||||
|
||||
@@ -88,12 +88,6 @@
|
||||
<groupId>com.github.sgroschupf</groupId>
|
||||
<artifactId>zkclient</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lld</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.feign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
|
||||
@@ -23,20 +23,10 @@
|
||||
// todo 下列两行
|
||||
uni.setStorageSync('device', 'H5');
|
||||
uni.setStorageSync('version', versionName);
|
||||
this.$http.request({
|
||||
url: '/common/getVersion',
|
||||
success: (res) => {
|
||||
if(res.data.data.upgrade=='Y'){
|
||||
console.log(
|
||||
`%c 有新版本 `+res.data.data.version,
|
||||
'background:#007aff ;padding: 1px; border-radius: 0 3px 3px 0; color: #fff; font-weight: bold;'
|
||||
)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// #endif
|
||||
console.log('App Launch')
|
||||
let token= uni.getStorageSync('Authorization');
|
||||
let token= uni.getStorageSync('imUserSign');
|
||||
if (!token) {
|
||||
//不存在则跳转至登录页
|
||||
// #ifdef APP-PLUS
|
||||
@@ -104,29 +94,7 @@
|
||||
})
|
||||
}
|
||||
// #ifdef APP-PLUS
|
||||
//升级检测
|
||||
uni.getSystemInfo({
|
||||
success: (res)=> {
|
||||
uni.setStorageSync('device', res.platform);
|
||||
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo)=> {
|
||||
uni.setStorageSync('version', widgetInfo.version);
|
||||
this.$http.request({
|
||||
url: '/common/getVersion',
|
||||
success: (res) => {
|
||||
if(res.data.data.upgrade=='Y'){
|
||||
appUpgrade.init({
|
||||
titleText: '版本更新'+res.data.data.version,
|
||||
packageUrl:res.data.data.url,
|
||||
content: res.data.data.content,
|
||||
forceUpgrade:res.data.data.forceUpgrade=='Y' ? true : false
|
||||
});
|
||||
appUpgrade.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
uni.onNetworkStatusChange( (res)=> {
|
||||
if(res.isConnected){
|
||||
this.$store.dispatch('get_UserInfo')
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -2,6 +2,9 @@ import http from '@/common/request'
|
||||
import browser from '@/common/browser'
|
||||
import store from '../store'
|
||||
import pinyin from '@/common/pinyin.js';
|
||||
|
||||
import * as dayjs from 'dayjs'
|
||||
|
||||
export default {
|
||||
// 获取字典
|
||||
getdict(dict) {
|
||||
@@ -464,6 +467,12 @@ export default {
|
||||
store.dispatch('getChatList');
|
||||
var chatWindowData = store.state.chatDatalist[userId].list
|
||||
var chatListInfo = store.state.chatlist[userId]
|
||||
|
||||
var data2 = this.getKeyObjectStorage(store.state.userInfo.userId + '_' +
|
||||
'chatlistData')
|
||||
// var _num=data2[userId].num||
|
||||
console.log("===========data2:",JSON.stringify(data2[userId]))
|
||||
|
||||
// 找到数组中对象属性值一样的对象并返回
|
||||
function arrfindobject({
|
||||
arr,
|
||||
@@ -508,11 +517,11 @@ export default {
|
||||
nickName: fromInfo.nickName,
|
||||
portrait: fromInfo.portrait,
|
||||
content: msgTypeLabel,
|
||||
time: time,
|
||||
time: dayjs(time).format("YYYY/MM/DD HH:mm:ss"),
|
||||
num: disturb == 'Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num + 1 : 1),
|
||||
windowType: windowType,
|
||||
disturb: disturb, //是否静默消息
|
||||
top: top, //是否置顶
|
||||
disturb: "N", //是否静默消息
|
||||
top: "N", //是否置顶
|
||||
userType: fromInfo.userType
|
||||
}
|
||||
}
|
||||
@@ -526,7 +535,7 @@ export default {
|
||||
time: time,
|
||||
num: disturb == 'Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num + 1 : 1),
|
||||
windowType: windowType,
|
||||
disturb: disturb, //是否静默消息
|
||||
disturb: "N", //是否静默消息
|
||||
top: top, //是否置顶
|
||||
userType: 'GROUP'
|
||||
}
|
||||
@@ -990,6 +999,31 @@ export default {
|
||||
});
|
||||
// #endif
|
||||
},
|
||||
formatMessage(msg){
|
||||
msg.pushType="MSG"
|
||||
const _data=JSON.parse(msg.messageBody)
|
||||
msg.msgContent={
|
||||
msgType:"TEXT",
|
||||
content:_data.content,
|
||||
disturb:false,
|
||||
top:false,
|
||||
}
|
||||
|
||||
msg.windowType="SINGLE"
|
||||
msg.createTime=msg.messageTime;
|
||||
msg.userId=msg.fromId;
|
||||
msg.fromInfo={
|
||||
userId:msg.fromId,
|
||||
userType:1,
|
||||
nickName:msg.fromId,
|
||||
portrait:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png"
|
||||
};
|
||||
msg.groupInfo={};
|
||||
msg.msgId=msg.messageKey;
|
||||
|
||||
return msg
|
||||
|
||||
},
|
||||
debounce(func, wait = 1000, immediate = true) {
|
||||
/**
|
||||
* @desc 函数防抖
|
||||
|
||||
@@ -4,9 +4,10 @@ let retimer = null
|
||||
import store from '../store'
|
||||
|
||||
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
||||
|
||||
import lim from "@/common/imSdk/sdk-bridge.js";
|
||||
|
||||
import publicFc from '@/common/publicFc';
|
||||
|
||||
export default {
|
||||
socketTask: null,
|
||||
// 连接WebSocket
|
||||
@@ -28,42 +29,40 @@ export default {
|
||||
onSocketReConnectSuccessEvent: () => {
|
||||
console.log("重连成功");
|
||||
},
|
||||
onOfflineMessage:(e)=>{
|
||||
onOfflineMessage: (e) => {
|
||||
console.log("====================拉取到离线消息")
|
||||
console.log(e)
|
||||
setTimeout(function() {
|
||||
if (e.length > 0) {
|
||||
e.map((msg) => {
|
||||
console.log(msg)
|
||||
setTimeout(()=>{
|
||||
const _data = publicFc.formatMessage(msg)
|
||||
uni.$emit('onP2PMessage', _data);
|
||||
store.dispatch('onP2PMessage', _data)
|
||||
},500)
|
||||
})
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
},
|
||||
onTestMessage: (e) => {
|
||||
console.log("onTestMessage :" + e);
|
||||
store.dispatch('onP2PMessage',e)
|
||||
console.log("onTestMessage :");
|
||||
store.dispatch('onP2PMessage', e)
|
||||
},
|
||||
onP2PMessage: (e) => {
|
||||
console.log("onP2PMessage :" + e);
|
||||
console.log("onP2PMessag e :::");
|
||||
console.log(JSON.parse(e))
|
||||
e = JSON.parse(e)
|
||||
e.data.pushType="MSG"
|
||||
const _data=JSON.parse(e.data.messageBody)
|
||||
e.data.msgContent={
|
||||
msgType:"TEXT",
|
||||
content:_data.content,
|
||||
disturb:false,
|
||||
top:false,
|
||||
}
|
||||
|
||||
e.data.windowType="SINGLE"
|
||||
e.data.createTime=e.data.messageTime;
|
||||
e.data.userId=e.data.fromId;
|
||||
e.data.fromInfo={
|
||||
userId:e.data.fromId
|
||||
};
|
||||
e.data.groupInfo={};
|
||||
e.data.msgId=e.data.messageId;
|
||||
|
||||
uni.$emit('onP2PMessage', e.data);
|
||||
store.dispatch('onP2PMessage',e.data)
|
||||
|
||||
const _data = publicFc.formatMessage(e.data)
|
||||
|
||||
uni.$emit('onP2PMessage', _data);
|
||||
store.dispatch('onP2PMessage', _data)
|
||||
|
||||
},
|
||||
onLogin: (uid) => {
|
||||
console.log("用户" + uid + "登陆sdk成功");
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -79,7 +78,7 @@ export default {
|
||||
|
||||
console.log(lim)
|
||||
|
||||
// 防止多次建立ws链接,貌似还没有生效,需要检查
|
||||
// 防止多次建立ws链接,貌似还没有生效,需要检查
|
||||
if (this.socketTask != null) {
|
||||
return false
|
||||
}
|
||||
@@ -92,12 +91,12 @@ export default {
|
||||
console.log(this.socketTask)
|
||||
|
||||
console.log('sdk 成功连接的回调, 可以使用 sdk 请求数据了.');
|
||||
sdk.getAllFriend().then(res => {
|
||||
console.warn(res)
|
||||
})
|
||||
sdk.getUserSequence().then(res => {
|
||||
console.warn(res)
|
||||
})
|
||||
// sdk.getAllFriend().then(res => {
|
||||
// console.warn(res)
|
||||
// })
|
||||
// sdk.getUserSequence().then(res => {
|
||||
// console.warn(res)
|
||||
// })
|
||||
|
||||
sdk.getUserConversationList(0).then(res => {
|
||||
console.warn(res)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"author": "zmm2113@qq.com",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dayjs": "^1.11.10",
|
||||
"localforage": "^1.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,283 +1,343 @@
|
||||
import http from '@/common/request';
|
||||
import publicFc from '@/common/publicFc';
|
||||
|
||||
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
||||
import lim from "@/common/imSdk/sdk-bridge.js";
|
||||
|
||||
const _im = lim.lim.im
|
||||
|
||||
function sortBy(field) {
|
||||
//根据传过来的字段进行排序
|
||||
return (x, y) => {
|
||||
return x[field] - y[field]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #ifndef VUE3
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
Vue.use(Vuex)
|
||||
const store = new Vuex.Store({
|
||||
// #endif
|
||||
// #endif
|
||||
|
||||
|
||||
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
||||
import lim from "@/common/imSdk/sdk-bridge.js";
|
||||
|
||||
const _im=lim.lim.im
|
||||
|
||||
// #ifdef VUE3
|
||||
import { createStore } from 'vuex'
|
||||
const store = createStore({
|
||||
// #endif
|
||||
state: {
|
||||
watermark:'HS-IM',
|
||||
userInfo:'',
|
||||
chatlist:[],
|
||||
chatDatalist:[],
|
||||
chatListNum:0,
|
||||
chatDataState:1,
|
||||
chatDataUserId:'',
|
||||
topicReply:{},
|
||||
topicRed:{},
|
||||
friendApply:{}
|
||||
},
|
||||
mutations: {
|
||||
update_UserInfo(state, data) {//个人信息
|
||||
state.userInfo = JSON.parse(data)
|
||||
},
|
||||
update_ChatList(state, data) {
|
||||
state.chatlist = data
|
||||
},
|
||||
update_chatDatalist(state, data) {
|
||||
state.chatDatalist = data
|
||||
},
|
||||
update_topicReply(state, data) {
|
||||
state.topicReply = data
|
||||
uni.setStorageSync('topicReply', JSON.stringify(data));
|
||||
},
|
||||
update_topicRed(state, data) {
|
||||
state.topicRed = data
|
||||
uni.setStorageSync('topicRed', JSON.stringify(data));
|
||||
},
|
||||
update_friendApply(state, data) {
|
||||
state.friendApply = data
|
||||
uni.setStorageSync('friendApply', JSON.stringify(data));
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
onP2PMessage(context,data){
|
||||
console.log("========================store 收到信息")
|
||||
console.log("========================store 收到信息")
|
||||
console.log("========================store 收到信息")
|
||||
console.error(data)
|
||||
publicFc.getPush(data)
|
||||
|
||||
},
|
||||
sendMsg(context,data){
|
||||
console.log("========================")
|
||||
console.log("========================")
|
||||
console.log("========================")
|
||||
console.error(data)
|
||||
_im.sendP2PMessage(_im.createP2PTextMessage(data.userId,data.data.content))
|
||||
},
|
||||
updateChatDataState(context,data){
|
||||
context.state.chatDataState++
|
||||
context.state.chatDataUserId=data
|
||||
},
|
||||
tabBarpull(context){
|
||||
context.dispatch('get_UserInfo').then(res=>{
|
||||
context.dispatch('getChatList')
|
||||
// 朋友圈新消息
|
||||
var topicReply=publicFc.getKeyObjectStorage('topicReply')
|
||||
context.state.topicReply=topicReply
|
||||
// 新朋友圈
|
||||
var topicRed=publicFc.getKeyObjectStorage('topicRed')
|
||||
context.state.topicRed=topicRed
|
||||
// 新朋友
|
||||
var friendApply=publicFc.getKeyObjectStorage('friendApply')
|
||||
context.state.friendApply=friendApply
|
||||
var chatListNum=context.state.chatListNum ? context.state.chatListNum : 0
|
||||
var topicReplyCount=topicReply.count ? topicReply.count : 0
|
||||
var friendApplyCount=friendApply.count ? friendApply.count : 0
|
||||
var sumCount=chatListNum+topicReplyCount+friendApplyCount
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.setBadgeNumber(sumCount);
|
||||
// #ifdef VUE3
|
||||
import {
|
||||
createStore
|
||||
} from 'vuex'
|
||||
const store = createStore({
|
||||
// #endif
|
||||
})
|
||||
},
|
||||
get_UserInfo (context) {
|
||||
// TODO 改用SDK的更新用户数据
|
||||
return new Promise((resolve, reject) => {
|
||||
const userId = uni.getStorageSync("userId")
|
||||
|
||||
lim.lim.im.getSingleUserInfo(userId).then((res)=>{
|
||||
if(res.code==200){
|
||||
context.commit('update_UserInfo',JSON.stringify(res.data))
|
||||
resolve(res.data)
|
||||
}else{
|
||||
reject(res.data)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
getchatDatalist(context) {//获取聊天数据列表
|
||||
var data=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatData')
|
||||
context.commit('update_chatDatalist',data)
|
||||
},
|
||||
updateChatById(context,data) {//更新聊天数据
|
||||
var getKey=data.userId
|
||||
var retdata=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatData')
|
||||
retdata[getKey]['list']=data.data
|
||||
uni.setStorageSync(context.state.userInfo.userId+'_'+'chatData', JSON.stringify(retdata));
|
||||
},
|
||||
updateChatObjById(context,data) {//更新聊天数据对象
|
||||
var getKey=data.userId
|
||||
var retdata=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatData')
|
||||
retdata[getKey]=data.data
|
||||
uni.setStorageSync(context.state.userInfo.userId+'_'+'chatData', JSON.stringify(retdata));
|
||||
},
|
||||
getChatList(context) {//获取聊天记录列表
|
||||
var data=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatlistData')
|
||||
var sum=0
|
||||
for(var key in data){
|
||||
sum+=data[key].num
|
||||
}
|
||||
context.state.chatListNum=sum
|
||||
context.commit('update_ChatList',data)
|
||||
},
|
||||
updateChatListInfoById(context,data) {//修改聊天记录
|
||||
console.log("修改聊天记录 2")
|
||||
var getKey=data.userId
|
||||
var retdata=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatlistData')
|
||||
retdata[getKey]=data.data
|
||||
uni.setStorageSync(context.state.userInfo.userId+'_'+'chatlistData', JSON.stringify(retdata));
|
||||
},
|
||||
createChatObj(context,data){
|
||||
console.log("修改聊天记录 3")
|
||||
console.log("context.state.userInfo.userId:",context.state.userInfo.userId)
|
||||
console.log("data.userId:",data.userId)
|
||||
var userId=data.userId
|
||||
var windowType=data.windowType
|
||||
state: {
|
||||
watermark: 'HS-IM',
|
||||
userInfo: '',
|
||||
chatlist: [],
|
||||
chatDatalist: [],
|
||||
chatListNum: 0,
|
||||
chatDataState: 1,
|
||||
chatDataUserId: '',
|
||||
topicReply: {},
|
||||
topicRed: {},
|
||||
friendApply: {}
|
||||
},
|
||||
mutations: {
|
||||
update_UserInfo(state, data) { //个人信息
|
||||
state.userInfo = JSON.parse(data)
|
||||
},
|
||||
update_ChatList(state, data) {
|
||||
state.chatlist = data
|
||||
},
|
||||
update_chatDatalist(state, data) {
|
||||
state.chatDatalist = data
|
||||
},
|
||||
update_topicReply(state, data) {
|
||||
state.topicReply = data
|
||||
uni.setStorageSync('topicReply', JSON.stringify(data));
|
||||
},
|
||||
update_topicRed(state, data) {
|
||||
state.topicRed = data
|
||||
uni.setStorageSync('topicRed', JSON.stringify(data));
|
||||
},
|
||||
update_friendApply(state, data) {
|
||||
state.friendApply = data
|
||||
uni.setStorageSync('friendApply', JSON.stringify(data));
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
onP2PMessage(context, data) {
|
||||
console.log("========================store 收到信息")
|
||||
console.log(data)
|
||||
publicFc.getPush(data)
|
||||
|
||||
//初始化聊天记录
|
||||
var data2=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatlistData')
|
||||
if(!data2[userId]){
|
||||
data2[userId]=new Object()
|
||||
}
|
||||
uni.setStorageSync(context.state.userInfo.userId+'_'+'chatlistData', JSON.stringify(data2));
|
||||
// 初始化聊天数据
|
||||
var data1=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatData')
|
||||
return new Promise((resolve, reject)=>{
|
||||
if(!data1[userId]){
|
||||
console.log('初始化聊天')
|
||||
switch (windowType){
|
||||
case 'SINGLE':
|
||||
|
||||
// lim.lim.im.getSingleUserInfo(userId).then(res=>{
|
||||
// console.warn(res)
|
||||
// })
|
||||
|
||||
_im.getSingleUserInfo(userId).then((res)=>{
|
||||
console.log(res.data)
|
||||
console.log(res.data)
|
||||
console.log(res.data)
|
||||
console.log(res.data)
|
||||
},
|
||||
sendMsg(context, data) {
|
||||
console.log("========================")
|
||||
// console.log("========================")
|
||||
// console.log("========================")
|
||||
// console.error(data)
|
||||
_im.sendP2PMessage(_im.createP2PTextMessage(data.userId, data.data.content))
|
||||
},
|
||||
sendP2PMessageReciveAck(context, data) {
|
||||
_im.sendP2PMessageReciveAck(data)
|
||||
},
|
||||
sendMsgReadedReceipt(context, data) {
|
||||
_im.sendP2PMessageReadedReceipt(data)
|
||||
},
|
||||
updateChatDataState(context, data) {
|
||||
context.state.chatDataState++
|
||||
context.state.chatDataUserId = data
|
||||
},
|
||||
tabBarpull(context) {
|
||||
context.dispatch('get_UserInfo').then(res => {
|
||||
context.dispatch('getChatList')
|
||||
// 朋友圈新消息
|
||||
var topicReply = publicFc.getKeyObjectStorage('topicReply')
|
||||
context.state.topicReply = topicReply
|
||||
// 新朋友圈
|
||||
var topicRed = publicFc.getKeyObjectStorage('topicRed')
|
||||
context.state.topicRed = topicRed
|
||||
// 新朋友
|
||||
var friendApply = publicFc.getKeyObjectStorage('friendApply')
|
||||
context.state.friendApply = friendApply
|
||||
var chatListNum = context.state.chatListNum ? context.state.chatListNum : 0
|
||||
var topicReplyCount = topicReply.count ? topicReply.count : 0
|
||||
var friendApplyCount = friendApply.count ? friendApply.count : 0
|
||||
var sumCount = chatListNum + topicReplyCount + friendApplyCount
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.setBadgeNumber(sumCount);
|
||||
// #endif
|
||||
})
|
||||
},
|
||||
get_UserInfo(context) {
|
||||
// TODO 改用SDK的更新用户数据
|
||||
return new Promise((resolve, reject) => {
|
||||
const userId = uni.getStorageSync("userId")
|
||||
|
||||
lim.lim.im.getSingleUserInfo(userId).then((res) => {
|
||||
if (res.code == 200) {
|
||||
var detail=res.data
|
||||
data1[userId]={
|
||||
fromInfo:{
|
||||
nickName: detail.nickName,
|
||||
portrait: detail.photo,
|
||||
userId: detail.userId,
|
||||
userType:detail.userType
|
||||
},
|
||||
groupInfo:{},
|
||||
list:[]
|
||||
}
|
||||
|
||||
uni.setStorageSync(context.state.userInfo.userId+'_'+'chatData', JSON.stringify(data1));
|
||||
// 创建记录
|
||||
var msgList = {
|
||||
userId: detail.userId,
|
||||
personId: context.state.userInfo.userId,
|
||||
nickName: detail.nickName,
|
||||
portrait: detail.photo,
|
||||
content: '',
|
||||
time: publicFc.getNewDate('format',true),
|
||||
num: 0,
|
||||
windowType: 'SINGLE',
|
||||
disturb:'N',//是否静默消息
|
||||
top:'N',//是否置顶
|
||||
userType:'SINGLE'
|
||||
}
|
||||
context.dispatch('updateChatListInfoById', {
|
||||
userId: detail.userId,
|
||||
data: msgList
|
||||
});
|
||||
resolve({
|
||||
msg:'创建成功',
|
||||
data:data1[userId]
|
||||
})
|
||||
}else{
|
||||
reject({
|
||||
msg:'创建失败'
|
||||
});
|
||||
context.commit('update_UserInfo', JSON.stringify(res.data))
|
||||
resolve(res.data)
|
||||
} else {
|
||||
reject(res.data)
|
||||
}
|
||||
}
|
||||
);
|
||||
break;
|
||||
case 'GROUP':
|
||||
http.request({
|
||||
url: '/group/getInfo/'+userId,
|
||||
complete:(res)=>{
|
||||
if (res.data.code == 200) {
|
||||
var detail=res.data.data
|
||||
var portraits=[]
|
||||
for (var i = 0; i < detail.user.length; i++) {
|
||||
portraits.push(detail.user[i].portrait)
|
||||
}
|
||||
data1[userId]={
|
||||
fromInfo:{},
|
||||
groupInfo:{
|
||||
nickName: detail.group.name,
|
||||
portrait: JSON.stringify(portraits),
|
||||
userId: detail.group.groupId,
|
||||
},
|
||||
list:[]
|
||||
}
|
||||
uni.setStorageSync(context.state.userInfo.userId+'_'+'chatData', JSON.stringify(data1));
|
||||
// 创建记录
|
||||
var msgList = {
|
||||
userId: detail.group.groupId,
|
||||
personId: context.state.userInfo.userId,
|
||||
nickName: detail.group.name,
|
||||
portrait: JSON.stringify(portraits),
|
||||
content: '',
|
||||
time: publicFc.getNewDate('format',true),
|
||||
num: 0,
|
||||
windowType: 'GROUP',
|
||||
disturb:'N',//是否静默消息
|
||||
top:'N',//是否置顶
|
||||
userType:'GROUP'
|
||||
}
|
||||
context.dispatch('updateChatListInfoById', {
|
||||
userId: detail.group.groupId,
|
||||
data: msgList
|
||||
});
|
||||
resolve({
|
||||
msg:'创建成功',
|
||||
data:data1[userId]
|
||||
})
|
||||
}else{
|
||||
reject({
|
||||
msg:'创建失败'
|
||||
});
|
||||
})
|
||||
})
|
||||
},
|
||||
getchatDatalist(context) { //获取聊天数据列表
|
||||
var data = publicFc.getKeyObjectStorage(context.state.userInfo.userId + '_' +
|
||||
'chatData')
|
||||
context.commit('update_chatDatalist', data)
|
||||
},
|
||||
updateChatById(context, data) { //更新聊天数据
|
||||
var getKey = data.userId
|
||||
var retdata = publicFc.getKeyObjectStorage(context.state.userInfo.userId + '_' +
|
||||
'chatData')
|
||||
|
||||
//TODO 排序方法可以优化
|
||||
data.data = data.data.sort(sortBy('time'))
|
||||
|
||||
retdata[getKey]['list'] = data.data
|
||||
uni.setStorageSync(context.state.userInfo.userId + '_' + 'chatData', JSON.stringify(
|
||||
retdata));
|
||||
},
|
||||
updateChatObjById(context, data) { //更新聊天数据对象
|
||||
var getKey = data.userId
|
||||
var retdata = publicFc.getKeyObjectStorage(context.state.userInfo.userId + '_' +
|
||||
'chatData')
|
||||
|
||||
//TODO 排序方法可以优化
|
||||
data.data = data.data.sort(sortBy('time'))
|
||||
retdata[getKey] = data.data
|
||||
uni.setStorageSync(context.state.userInfo.userId + '_' + 'chatData', JSON.stringify(
|
||||
retdata));
|
||||
},
|
||||
getChatList(context) { //获取聊天记录列表
|
||||
var data = publicFc.getKeyObjectStorage(context.state.userInfo.userId + '_' +
|
||||
'chatlistData')
|
||||
var sum = 0
|
||||
for (var key in data) {
|
||||
sum += data[key].num
|
||||
}
|
||||
context.state.chatListNum = sum
|
||||
context.commit('update_ChatList', data)
|
||||
},
|
||||
updateChatListInfoById(context, data) { //修改聊天记录
|
||||
console.log("*********************** 修改聊天记录 2 ********************")
|
||||
console.log("*********************** 修改聊天记录 2 ********************")
|
||||
console.log("*********************** 修改聊天记录 2 ********************")
|
||||
console.log(data)
|
||||
var getKey = data.userId
|
||||
var retdata = publicFc.getKeyObjectStorage(context.state.userInfo.userId + '_' +
|
||||
'chatlistData')
|
||||
console.log(retdata[getKey])
|
||||
retdata[getKey] = data.data
|
||||
uni.setStorageSync(context.state.userInfo.userId + '_' + 'chatlistData', JSON.stringify(
|
||||
retdata));
|
||||
},
|
||||
createChatObj(context, data) {
|
||||
console.log("初始化聊天记录")
|
||||
// console.log("context.state.userInfo.userId:", context.state.userInfo.userId)
|
||||
// console.log("data.userId:", data.userId)
|
||||
var userId = data.userId
|
||||
var windowType = data.windowType
|
||||
|
||||
//初始化聊天记录
|
||||
var data2 = publicFc.getKeyObjectStorage(context.state.userInfo.userId + '_' +
|
||||
'chatlistData')
|
||||
|
||||
// console.log("===========data2:",JSON.stringify(data2[userId]))
|
||||
|
||||
var _num=0
|
||||
console.error(data2[userId])
|
||||
if (!data2[userId]) {
|
||||
data2[userId] = new Object()
|
||||
}else{
|
||||
console.warn(data2[userId].num)
|
||||
// _num=data2[userId].num+1
|
||||
}
|
||||
uni.setStorageSync(context.state.userInfo.userId + '_' + 'chatlistData', JSON.stringify(
|
||||
data2));
|
||||
// 初始化聊天数据
|
||||
var data1 = publicFc.getKeyObjectStorage(context.state.userInfo.userId + '_' +
|
||||
'chatData')
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!data1[userId]) {
|
||||
console.log('初始化聊天')
|
||||
switch (windowType) {
|
||||
case 'SINGLE':
|
||||
|
||||
// lim.lim.im.getSingleUserInfo(userId).then(res=>{
|
||||
// console.warn(res)
|
||||
// })
|
||||
|
||||
_im.getSingleUserInfo(userId).then((res) => {
|
||||
// console.log(res.data)
|
||||
|
||||
if (res.code == 200) {
|
||||
var detail = res.data
|
||||
data1[userId] = {
|
||||
fromInfo: {
|
||||
nickName: detail.nickName,
|
||||
portrait: detail.photo,
|
||||
userId: detail.userId,
|
||||
userType: detail.userType
|
||||
},
|
||||
groupInfo: {},
|
||||
list: []
|
||||
}
|
||||
|
||||
uni.setStorageSync(context.state.userInfo
|
||||
.userId + '_' + 'chatData', JSON
|
||||
.stringify(data1));
|
||||
// 创建记录
|
||||
console.log("============= 创建记录 ")
|
||||
|
||||
|
||||
|
||||
var msgList = {
|
||||
userId: detail.userId,
|
||||
personId: context.state.userInfo.userId,
|
||||
nickName: detail.nickName,
|
||||
portrait: detail.photo,
|
||||
content: '',
|
||||
time: publicFc.getNewDate('format',
|
||||
true),
|
||||
num: 0,
|
||||
windowType: 'SINGLE',
|
||||
disturb: 'N', //是否静默消息
|
||||
top: 'N', //是否置顶
|
||||
userType: 'SINGLE'
|
||||
}
|
||||
context.dispatch('updateChatListInfoById', {
|
||||
userId: detail.userId,
|
||||
data: msgList
|
||||
});
|
||||
resolve({
|
||||
msg: '创建成功',
|
||||
data: data1[userId]
|
||||
})
|
||||
} else {
|
||||
reject({
|
||||
msg: '创建失败'
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'GROUP':
|
||||
http.request({
|
||||
url: '/group/getInfo/' + userId,
|
||||
complete: (res) => {
|
||||
if (res.data.code == 200) {
|
||||
var detail = res.data.data
|
||||
var portraits = []
|
||||
for (var i = 0; i < detail.user
|
||||
.length; i++) {
|
||||
portraits.push(detail.user[i]
|
||||
.portrait)
|
||||
}
|
||||
data1[userId] = {
|
||||
fromInfo: {},
|
||||
groupInfo: {
|
||||
nickName: detail.group.name,
|
||||
portrait: JSON.stringify(
|
||||
portraits),
|
||||
userId: detail.group
|
||||
.groupId,
|
||||
},
|
||||
list: []
|
||||
}
|
||||
uni.setStorageSync(context.state
|
||||
.userInfo.userId + '_' +
|
||||
'chatData', JSON.stringify(
|
||||
data1));
|
||||
// 创建记录
|
||||
var msgList = {
|
||||
userId: detail.group.groupId,
|
||||
personId: context.state.userInfo
|
||||
.userId,
|
||||
nickName: detail.group.name,
|
||||
portrait: JSON.stringify(
|
||||
portraits),
|
||||
content: '',
|
||||
time: publicFc.getNewDate(
|
||||
'format', true),
|
||||
num: 0,
|
||||
windowType: 'GROUP',
|
||||
disturb: 'N', //是否静默消息
|
||||
top: 'N', //是否置顶
|
||||
userType: 'GROUP'
|
||||
}
|
||||
context.dispatch(
|
||||
'updateChatListInfoById', {
|
||||
userId: detail.group
|
||||
.groupId,
|
||||
data: msgList
|
||||
});
|
||||
resolve({
|
||||
msg: '创建成功',
|
||||
data: data1[userId]
|
||||
})
|
||||
} else {
|
||||
reject({
|
||||
msg: '创建失败'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
resolve({
|
||||
msg: '已存在',
|
||||
data: data1[userId]
|
||||
})
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
},
|
||||
createChat(context, data) {
|
||||
|
||||
}
|
||||
}else{
|
||||
resolve({
|
||||
msg:'已存在',
|
||||
data:data1[userId]
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
createChat(context,data){
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
export default store
|
||||
})
|
||||
export default store
|
||||
@@ -174,7 +174,7 @@
|
||||
onLoad(e) {
|
||||
|
||||
// // 监听接收聊天信息
|
||||
// uni.$on('onP2PMessage', this.onMessage)
|
||||
uni.$on('onP2PMessage', this.onMessage)
|
||||
|
||||
this.talkTo = e;
|
||||
console.log(this.talkTo)
|
||||
@@ -232,8 +232,6 @@
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
onPageScroll() {
|
||||
this.clickToSubmitSure();
|
||||
@@ -267,7 +265,19 @@
|
||||
},
|
||||
methods: {
|
||||
onMessage(message) {
|
||||
|
||||
//判断当前是单聊还是群聊
|
||||
if (this.talkTo.windowType != 'SINGLE') {
|
||||
return;
|
||||
}
|
||||
//如果是单聊,则判断当前消息发送人是不是当前窗口的聊天对象
|
||||
if(this.talkTo.userId!=message.fromId){
|
||||
return;
|
||||
}
|
||||
console.log("message 聊天页收到回调")
|
||||
console.log(message)
|
||||
//如果当前消息发送人和当前窗口的聊天对象一致,则发送已读回执
|
||||
console.log("########### 此时需要发送已读回执 ###########")
|
||||
this.$store.dispatch('sendP2PMessageReciveAck',message)
|
||||
},
|
||||
addMsg(e) {
|
||||
this.msg += e;
|
||||
|
||||
@@ -158,12 +158,7 @@
|
||||
this.$store.dispatch('tabBarpull');
|
||||
},
|
||||
mounted() {
|
||||
|
||||
|
||||
this.$socketTask.connectSocket()
|
||||
|
||||
|
||||
|
||||
},
|
||||
methods: {
|
||||
longpressItem(e, i, v) {
|
||||
|
||||
@@ -24,7 +24,10 @@ enum MessageCommand {
|
||||
|
||||
// //消息已读通知 1053
|
||||
MSG_READED_NOTIFY = 0x41D,
|
||||
|
||||
|
||||
// 消息已读回执,给原消息发送方 1054
|
||||
MSG_READED_RECEIPT=0x41E,
|
||||
|
||||
}
|
||||
|
||||
enum FriendShipCommand{
|
||||
|
||||
@@ -20,7 +20,7 @@ export default class HttpApi {
|
||||
let reqUrl = this.url + url;
|
||||
if(params != null){
|
||||
let paramStr = this.setQueryConfig(params)
|
||||
console.log(paramStr);
|
||||
// console.log(paramStr);
|
||||
reqUrl += paramStr;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export default class HttpApi {
|
||||
}).then(res =>{
|
||||
log.info(`==> [${request.method}] ${url} back:` + Beans.json(res));
|
||||
const resp = this.response2ApiResponse(res);
|
||||
console.log(res)
|
||||
// console.log(res)
|
||||
if(resp.isFailed()){
|
||||
return Promise.reject(resp);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ export default class HttpApi {
|
||||
/*IFTRUE_UNIAPP*/
|
||||
let rnfetch1 = Fetch.getFetchToolkit();
|
||||
return rnfetch1(url as string, request).then(response =>{
|
||||
console.log(response)
|
||||
// console.log(response)
|
||||
return response.json();
|
||||
}).then(res =>{
|
||||
log.info(`==> [${request.method}] ${url} back:` + Beans.json(res));
|
||||
|
||||
@@ -54,7 +54,7 @@ export interface IListener {
|
||||
onSocketCloseEvent(): void;//连接关闭事件
|
||||
onP2PMessage(e: any): void;//收到单聊消息事件
|
||||
onTestMessage(e: any): void;//收到消息事件 测试用
|
||||
// onOfflineMessage(data):void; // 拉取到离线消息事件
|
||||
onOfflineMessage(data):void; // 拉取到离线消息事件
|
||||
}
|
||||
|
||||
export class ImClient {
|
||||
@@ -188,6 +188,10 @@ export class ImClient {
|
||||
|
||||
public buildMessagePack(command: number, messagePack: any) {
|
||||
var jsonData = JSON.stringify(messagePack);
|
||||
|
||||
// console.log("=============buildMessagePack=========")
|
||||
// log.info(jsonData);
|
||||
|
||||
let bodyLen = getLen(jsonData);
|
||||
|
||||
let pack = new ByteBuffer(null, 0);
|
||||
@@ -331,6 +335,48 @@ export class ImClient {
|
||||
this.conn.send(p2pPack.pack(false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 消息接收ack
|
||||
public sendP2PMessageReciveAck (rAck: any) {
|
||||
console.log("=============== sendP2PMessageReciveAck")
|
||||
console.log(rAck)
|
||||
rAck.toId = rAck.fromId;
|
||||
rAck.fromId = this.userId;
|
||||
|
||||
console.log(rAck)
|
||||
|
||||
let p2pPack_1107 = imClient.buildMessagePack(MessageCommand.MSG_RECIVE_ACK, rAck);
|
||||
rAck.conversationType=0
|
||||
let p2pPack_1106 = imClient.buildMessagePack(MessageCommand.MSG_READED, rAck);
|
||||
let p2pPack_1054 = imClient.buildMessagePack(MessageCommand.MSG_READED_RECEIPT, rAck);
|
||||
|
||||
|
||||
if (this.conn) {
|
||||
// console.log("=============== sendP2PMessageReciveAck 正式开始消息接收ack")
|
||||
|
||||
this.conn.send(p2pPack_1107.pack(false));
|
||||
this.conn.send(p2pPack_1106.pack(false));
|
||||
this.conn.send(p2pPack_1054.pack(false));
|
||||
}
|
||||
}
|
||||
|
||||
// 消息已读回执,给原消息发送方 1054
|
||||
public sendP2PMessageReadedReceipt (rAck: any) {
|
||||
console.log("=============== sendP2PMessageReadedRECEIPT")
|
||||
console.log(rAck)
|
||||
rAck.toId = rAck.fromId;
|
||||
rAck.fromId = this.userId;
|
||||
|
||||
console.log(rAck)
|
||||
|
||||
let p2pPack = imClient.buildMessagePack(MessageCommand.MSG_READED_RECEIPT, rAck);
|
||||
if (this.conn) {
|
||||
console.log("=============== sendP2PMessageReadedRECEIPT 正式开始发送已读回执")
|
||||
this.conn.send(p2pPack.pack(false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public getUserId() {
|
||||
return this.userId;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export default class Logger {
|
||||
static debug = true;
|
||||
static debug = false;
|
||||
|
||||
static info(message?: any, ...optionalParams: any[]): void {
|
||||
if(Logger.debug){
|
||||
|
||||
Reference in New Issue
Block a user