4
This commit is contained in:
@@ -1,29 +1,16 @@
|
||||
<script>
|
||||
import {
|
||||
mapGetters,
|
||||
mapActions
|
||||
} from "vuex";
|
||||
import IMSDK, {
|
||||
IMMethods,
|
||||
MessageType,
|
||||
SessionType,
|
||||
} from "openim-uniapp-polyfill";
|
||||
import {mapGetters,mapActions} from "vuex";
|
||||
import IMSDK, {IMMethods,MessageType,SessionType,} from "openim-uniapp-polyfill";
|
||||
import config from "./common/config";
|
||||
import {
|
||||
getDbDir,
|
||||
toastWithCallback
|
||||
} from "@/util/common.js";
|
||||
import {
|
||||
conversationSort
|
||||
} from "@/util/imCommon";
|
||||
import {
|
||||
PageEvents,
|
||||
UpdateMessageTypes
|
||||
} from "@/constant";
|
||||
import {getDbDir,toastWithCallback} from "@/util/common.js";
|
||||
import {conversationSort} from "@/util/imCommon";
|
||||
import {checkUpgrade} from "@/api/login.js"
|
||||
import {PageEvents,UpdateMessageTypes} from "@/constant";
|
||||
|
||||
export default {
|
||||
onLaunch: function() {
|
||||
console.log("App Launch");
|
||||
this.checkUpdate();
|
||||
this.setGlobalIMlistener();
|
||||
this.tryLogin();
|
||||
// #ifdef H5
|
||||
@@ -101,15 +88,11 @@
|
||||
});
|
||||
|
||||
// sync
|
||||
const syncStartHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const syncStartHandler = ({data}) => {
|
||||
this.$store.commit("user/SET_IS_SYNCING", true);
|
||||
this.$store.commit("user/SET_REINSTALL", data);
|
||||
};
|
||||
const syncProgressHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const syncProgressHandler = ({data}) => {
|
||||
this.$store.commit("user/SET_PROGRESS", data);
|
||||
};
|
||||
const syncFinishHandler = () => {
|
||||
@@ -133,9 +116,7 @@
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnSyncServerProgress, syncProgressHandler);
|
||||
|
||||
// self
|
||||
const selfInfoUpdateHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const selfInfoUpdateHandler = ({data}) => {
|
||||
this.$store.commit("user/SET_SELF_INFO", {
|
||||
...this.storeSelfInfo,
|
||||
...data,
|
||||
@@ -145,9 +126,7 @@
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnSelfInfoUpdated, selfInfoUpdateHandler);
|
||||
|
||||
// message
|
||||
const newMessagesHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const newMessagesHandler = ({data}) => {
|
||||
if (this.storeIsSyncing) {
|
||||
return;
|
||||
}
|
||||
@@ -157,9 +136,7 @@
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnRecvNewMessages, newMessagesHandler);
|
||||
|
||||
// friend
|
||||
const friendInfoChangeHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const friendInfoChangeHandler = ({data}) => {
|
||||
uni.$emit(IMSDK.IMEvents.OnFriendInfoChanged, {
|
||||
data
|
||||
});
|
||||
@@ -167,36 +144,25 @@
|
||||
friendInfo: data,
|
||||
});
|
||||
};
|
||||
const friendAddedHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const friendAddedHandler = ({data}) => {
|
||||
this.pushNewFriend(data);
|
||||
};
|
||||
const friendDeletedHander = ({
|
||||
data
|
||||
}) => {
|
||||
const friendDeletedHander = ({data}) => {
|
||||
this.updateFriendInfo({
|
||||
friendInfo: data,
|
||||
isRemove: true,
|
||||
});
|
||||
};
|
||||
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnFriendInfoChanged,
|
||||
friendInfoChangeHandler
|
||||
);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnFriendInfoChanged,friendInfoChangeHandler);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnFriendAdded, friendAddedHandler);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnFriendDeleted, friendDeletedHander);
|
||||
|
||||
// blacklist
|
||||
const blackAddedHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const blackAddedHandler = ({data}) => {
|
||||
this.pushNewBlack(data);
|
||||
};
|
||||
const blackDeletedHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const blackDeletedHandler = ({data}) => {
|
||||
this.updateBlackInfo({
|
||||
blackInfo: data,
|
||||
isRemove: true,
|
||||
@@ -207,58 +173,34 @@
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnBlackDeleted, blackDeletedHandler);
|
||||
|
||||
// group
|
||||
const joinedGroupAddedHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const joinedGroupAddedHandler = ({data}) => {
|
||||
this.pushNewGroup(data);
|
||||
};
|
||||
const joinedGroupDeletedHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const joinedGroupDeletedHandler = ({data}) => {
|
||||
this.updateGroupInfo({
|
||||
groupInfo: data,
|
||||
isRemove: true,
|
||||
});
|
||||
};
|
||||
const groupInfoChangedHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const groupInfoChangedHandler = ({data}) => {
|
||||
this.updateGroupInfo({
|
||||
groupInfo: data,
|
||||
});
|
||||
};
|
||||
const groupMemberInfoChangedHandler = ({
|
||||
data
|
||||
}) => {
|
||||
uni.$emit(IMSDK.IMEvents.OnGroupMemberInfoChanged, {
|
||||
data
|
||||
});
|
||||
const groupMemberInfoChangedHandler = ({data}) => {
|
||||
uni.$emit(IMSDK.IMEvents.OnGroupMemberInfoChanged, {data});
|
||||
if (data.groupID === this.storeCurrentConversation?.groupID) {
|
||||
this.updateCurrentMemberInGroup(data);
|
||||
}
|
||||
};
|
||||
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnJoinedGroupAdded,
|
||||
joinedGroupAddedHandler
|
||||
);
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnJoinedGroupDeleted,
|
||||
joinedGroupDeletedHandler
|
||||
);
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnGroupInfoChanged,
|
||||
groupInfoChangedHandler
|
||||
);
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnGroupMemberInfoChanged,
|
||||
groupMemberInfoChangedHandler
|
||||
);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnJoinedGroupAdded,joinedGroupAddedHandler);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnJoinedGroupDeleted,joinedGroupDeletedHandler);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnGroupInfoChanged,groupInfoChangedHandler);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnGroupMemberInfoChanged,groupMemberInfoChangedHandler);
|
||||
|
||||
// application
|
||||
const friendApplicationNumHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const friendApplicationNumHandler = ({data}) => {
|
||||
const isRecv = data.toUserID === this.storeCurrentUserID;
|
||||
if (isRecv) {
|
||||
this.pushNewRecvFriendApplition(data);
|
||||
@@ -266,9 +208,7 @@
|
||||
this.pushNewSentFriendApplition(data);
|
||||
}
|
||||
};
|
||||
const friendApplicationAccessHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const friendApplicationAccessHandler = ({data}) => {
|
||||
const isRecv = data.toUserID === this.storeCurrentUserID;
|
||||
if (isRecv) {
|
||||
this.updateRecvFriendApplition({
|
||||
@@ -280,9 +220,7 @@
|
||||
});
|
||||
}
|
||||
};
|
||||
const groupApplicationNumHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const groupApplicationNumHandler = ({data}) => {
|
||||
const isRecv = data.userID !== this.storeCurrentUserID;
|
||||
if (isRecv) {
|
||||
this.pushNewRecvGroupApplition(data);
|
||||
@@ -290,9 +228,7 @@
|
||||
this.pushNewSentGroupApplition(data);
|
||||
}
|
||||
};
|
||||
const groupApplicationAccessHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const groupApplicationAccessHandler = ({data}) => {
|
||||
const isRecv = data.userID !== this.storeCurrentUserID;
|
||||
if (isRecv) {
|
||||
this.updateRecvGroupApplition({
|
||||
@@ -305,43 +241,21 @@
|
||||
}
|
||||
};
|
||||
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnFriendApplicationAdded,
|
||||
friendApplicationNumHandler
|
||||
);
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnFriendApplicationAccepted,
|
||||
friendApplicationAccessHandler
|
||||
);
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnFriendApplicationRejected,
|
||||
friendApplicationAccessHandler
|
||||
);
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnGroupApplicationAdded,
|
||||
groupApplicationNumHandler
|
||||
);
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnGroupApplicationAccepted,
|
||||
groupApplicationAccessHandler
|
||||
);
|
||||
IMSDK.subscribe(
|
||||
IMSDK.IMEvents.OnGroupApplicationRejected,
|
||||
groupApplicationAccessHandler
|
||||
);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnFriendApplicationAdded,friendApplicationNumHandler);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnFriendApplicationAccepted,friendApplicationAccessHandler);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnFriendApplicationRejected,friendApplicationAccessHandler);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnGroupApplicationAdded,groupApplicationNumHandler);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnGroupApplicationAccepted,groupApplicationAccessHandler);
|
||||
IMSDK.subscribe(IMSDK.IMEvents.OnGroupApplicationRejected,groupApplicationAccessHandler);
|
||||
|
||||
// conversation
|
||||
const totalUnreadCountChangedHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const totalUnreadCountChangedHandler = ({data}) => {
|
||||
if (this.storeIsSyncing) {
|
||||
return;
|
||||
}
|
||||
this.$store.commit("conversation/SET_UNREAD_COUNT", data);
|
||||
};
|
||||
const newConversationHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const newConversationHandler = ({data}) => {
|
||||
if (this.storeIsSyncing) {
|
||||
return;
|
||||
}
|
||||
@@ -351,9 +265,7 @@
|
||||
conversationSort(result)
|
||||
);
|
||||
};
|
||||
const conversationChangedHandler = ({
|
||||
data
|
||||
}) => {
|
||||
const conversationChangedHandler = ({data}) => {
|
||||
if (this.storeIsSyncing) {
|
||||
return;
|
||||
}
|
||||
@@ -421,17 +333,14 @@
|
||||
uni.$u.toast("初始化IMSDK失败!");
|
||||
return;
|
||||
}
|
||||
const status = await IMSDK.asyncApi(
|
||||
IMSDK.IMMethods.GetLoginStatus,
|
||||
IMSDK.uuid()
|
||||
);
|
||||
const status = await IMSDK.asyncApi(IMSDK.IMMethods.GetLoginStatus,IMSDK.uuid());
|
||||
if (status === 3) {
|
||||
initStore();
|
||||
return;
|
||||
}
|
||||
|
||||
const IMToken = uni.getStorageSync("IMToken");
|
||||
const IMUserID = uni.getStorageSync("IMUserID");
|
||||
const IMUserID = uni.getStorageSync("IMUserID")+'';
|
||||
if (IMToken && IMUserID) {
|
||||
IMSDK.asyncApi(IMSDK.IMMethods.Login, IMSDK.uuid(), {
|
||||
userID: IMUserID,
|
||||
@@ -494,6 +403,20 @@
|
||||
this.storeCurrentConversation.conversationID
|
||||
);
|
||||
},
|
||||
// 验证是否升级
|
||||
checkUpdate() {
|
||||
let system = uni.getSystemInfoSync()
|
||||
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
|
||||
checkUpgrade({version:system.appVersion,platform:system.platform,version_wgt:inf.versionCode}).then(res=>{
|
||||
let skip_version = uni.getStorageSync('skip_version')
|
||||
if(res && res.version!=skip_version){
|
||||
uni.$emit('closeWebview')
|
||||
this.setShow(this.current, false)
|
||||
router('/pages/common/upgrade?model=' + JSON.stringify(res), '', 'fade-in')
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user