Skip to content

Commit

Permalink
save bulletin from server cache
Browse files Browse the repository at this point in the history
  • Loading branch information
oxogenesis authored Mar 28, 2020
1 parent a011926 commit 07eb9d9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/components/section/FooterSection.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="inner-footer">
<footer>
<p>版本 0.0.8</p>
<p>版本 0.0.9</p>
<p>@copyright 2019-2020</p>
</footer>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/section/OuterFooter.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="outer-footer">
<footer>
<p>版本 0.0.8</p>
<p>版本 0.0.9</p>
<p>@copyright 2019-2020</p>
<p>
<router-link class="links" to="AboutUs">关于</router-link>
Expand Down
109 changes: 61 additions & 48 deletions src/store/modules/OXO.js
Original file line number Diff line number Diff line change
Expand Up @@ -2848,60 +2848,73 @@ function Conn() {
console.log('Received: ', event.data)
}
*/
let json = checkJsonSchema(event.data)
if (json) {
//check receiver is me
if (json.To != state.Address) {
console.log('receiver is not me...')
return
}
try {
let json = JSON.parse(event.data)

//verify signature
if (VerifyJsonSignature(json) == false) {
//save bulletin from server cache
if (json.ObjectType == state.ObjectType.Bulletin && checkBulletinSchema(json)) {
let address = oxoKeyPairs.deriveAddress(json.PublicKey)
SaveBulletin(address, json)
return
}

if (json.Action == state.ActionCode.ChatDH) {
HandleChatDH(json)
} else if (json.Action == state.ActionCode.ChatMessage) {
HandleChatMessage(json)
} else if (json.Action == state.ActionCode.ChatSync) {
HandleChatSync(json)
} else if (json.Action == state.ActionCode.BulletinRequest) {
HandleBulletinRequest(json)
} else if (json.Action == state.ActionCode.BulletinFileRequest) {
HandleBulletinFileRequest(json)
} else if (json.Action == state.ActionCode.PrivateFileRequest) {
HandlePrivateFileRequest(json)
} else if (json.Action == state.ActionCode.GroupFileRequest) {
HandleGroupFileRequest(json)
} else if (json.Action == state.ActionCode.ObjectResponse) {
let address = oxoKeyPairs.deriveAddress(json.PublicKey)
let objectJson = json.Object
if (json.Object.ObjectType == state.ObjectType.Bulletin && checkBulletinSchema(objectJson)) {
SaveBulletin(address, objectJson)
} else if (json.Object.ObjectType == state.ObjectType.BulletinFile && checkFileChunkSchema(objectJson)) {
SaveBulletinFile(address, objectJson)
} else if (json.Object.ObjectType == state.ObjectType.PrivateFile && checkFileChunkSchema(objectJson)) {
SavePrivateFile(address, objectJson)
} else if (json.Object.ObjectType == state.ObjectType.GroupFile && checkFileChunkSchema(objectJson)) {
SaveGroupFile(address, objectJson)
} else if (json.Object.ObjectType == state.ObjectType.GroupManage && checkGroupManageSchema(objectJson)) {
SaveGroupManage(address, objectJson)
} else if (json.Object.ObjectType == state.ObjectType.GroupMessage) {
SaveGroupMessage(address, objectJson)
//handle message send To me
if (checkJsonSchema(json)) {
//check receiver is me
if (json.To != state.Address) {
console.log('receiver is not me...')
return
}

//verify signature
if (VerifyJsonSignature(json) == false) {
return
}

if (json.Action == state.ActionCode.ChatDH) {
HandleChatDH(json)
} else if (json.Action == state.ActionCode.ChatMessage) {
HandleChatMessage(json)
} else if (json.Action == state.ActionCode.ChatSync) {
HandleChatSync(json)
} else if (json.Action == state.ActionCode.BulletinRequest) {
HandleBulletinRequest(json)
} else if (json.Action == state.ActionCode.BulletinFileRequest) {
HandleBulletinFileRequest(json)
} else if (json.Action == state.ActionCode.PrivateFileRequest) {
HandlePrivateFileRequest(json)
} else if (json.Action == state.ActionCode.GroupFileRequest) {
HandleGroupFileRequest(json)
} else if (json.Action == state.ActionCode.ObjectResponse) {
let address = oxoKeyPairs.deriveAddress(json.PublicKey)
let objectJson = json.Object
if (objectJson.ObjectType == state.ObjectType.Bulletin && checkBulletinSchema(objectJson)) {
SaveBulletin(address, objectJson)
} else if (objectJson.ObjectType == state.ObjectType.BulletinFile && checkFileChunkSchema(objectJson)) {
SaveBulletinFile(address, objectJson)
} else if (objectJson.ObjectType == state.ObjectType.PrivateFile && checkFileChunkSchema(objectJson)) {
SavePrivateFile(address, objectJson)
} else if (objectJson.ObjectType == state.ObjectType.GroupFile && checkFileChunkSchema(objectJson)) {
SaveGroupFile(address, objectJson)
} else if (objectJson.ObjectType == state.ObjectType.GroupManage && checkGroupManageSchema(objectJson)) {
SaveGroupManage(address, objectJson)
} else if (objectJson.ObjectType == state.ObjectType.GroupMessage) {
SaveGroupMessage(address, objectJson)
}
} else if (json.Action == state.ActionCode.GroupRequest) {
HandleGroupRequest(json)
} else if (json.Action == state.ActionCode.GroupManageSync) {
HandleGroupManageSync(json)
} else if (json.Action == state.ActionCode.GroupDH) {
HandleGroupDH(json)
} else if (json.Action == state.ActionCode.GroupMessageSync) {
HandleGroupMessageSync(json)
}
} else if (json.Action == state.ActionCode.GroupRequest) {
HandleGroupRequest(json)
} else if (json.Action == state.ActionCode.GroupManageSync) {
HandleGroupManageSync(json)
} else if (json.Action == state.ActionCode.GroupDH) {
HandleGroupDH(json)
} else if (json.Action == state.ActionCode.GroupMessageSync) {
HandleGroupMessageSync(json)
} else {
console.log("json schema invalid...")
return
}
} else {
console.log("json schema invalid...")
} catch (e) {
return
}
})
Expand Down
15 changes: 3 additions & 12 deletions src/utils/json_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,9 @@ var vGroupDHSchema = ajv.compile(GroupDHSchema)
var vGroupMessageSyncSchema = ajv.compile(GroupMessageSyncSchema)
var vGroupRequestSchema = ajv.compile(GroupRequestSchema)

function checkJsonSchema(strJson) {
if (typeof strJson == "string") {
try {
let json = JSON.parse(strJson)
if (vObjectResponseSchema(json) || vBulletinRequestSchema(json) || vFileRequestSchema(json) || vChatMessageSchema(json) || vChatSyncSchema(json) || vChatDHSchema(json) || vDeclare(json) || vGroupManageSyncSchema(json) || vGroupDHSchema(json) || vGroupMessageSyncSchema(json) || vGroupRequestSchema(json)) {
return json
} else {
return false
}
} catch (e) {
return false
}
function checkJsonSchema(json) {
if (vObjectResponseSchema(json) || vBulletinRequestSchema(json) || vFileRequestSchema(json) || vChatMessageSchema(json) || vChatSyncSchema(json) || vChatDHSchema(json) || vDeclare(json) || vGroupManageSyncSchema(json) || vGroupDHSchema(json) || vGroupMessageSyncSchema(json) || vGroupRequestSchema(json)) {
return true
} else {
return false
}
Expand Down

0 comments on commit 07eb9d9

Please sign in to comment.