Kinda fix networks
This commit is contained in:
@@ -1 +1 @@
|
||||
{"config.json": 1756118682.0519147, "dataManager.py": 1757749170.2625794, "networks.py": 1757800810.4118917, "networksApiBlueprint.py": 1757750515.750099, "p2private.py": 1757803028.377009, "p2privateApiBlueprint.py": 1757825501.4272363, "vue\\router.js": 1755335641.4535544, "vue\\api\\p2privateApi.js": 1757756279.5687172, "vue\\api\\socketEvents.js": 1757748445.9564493, "vue\\views\\HomeView.vue": 1757756292.8398924}
|
||||
{"config.json": 1756118682.0519147, "dataManager.py": 1769761674.1419418, "networks.py": 1757800810.4118917, "networksApiBlueprint.py": 1757750515.750099, "p2private.py": 1757803028.377009, "p2privateApiBlueprint.py": 1769761706.0132868, "vue\\router.js": 1755335641.4535544, "vue\\api\\p2privateApi.js": 1769764270.9727585, "vue\\api\\socketEvents.js": 1757748445.9564493, "vue\\views\\HomeView.vue": 1769764331.9364705}
|
||||
@@ -44,4 +44,7 @@ class DataManager():
|
||||
|
||||
def update_message(self, hash: str, updates: Dict[str, Any]) -> bool:
|
||||
return self.store.update_item("messages", "hash", hash, updates)
|
||||
|
||||
def get_chat(self, from_user, to_user):
|
||||
return [m for m in self.list_messages() if from_user == m.get("from") and to_user == m.get("to")]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "p2private",
|
||||
"version": 0.043,
|
||||
"version": 0.046,
|
||||
"modules": [
|
||||
{
|
||||
"id": "p2private",
|
||||
|
||||
Binary file not shown.
@@ -30,12 +30,13 @@ class Blueprint(ApiBlueprint):
|
||||
pass
|
||||
|
||||
@self.blueprint.route('/messages/<path:user_id>/<path:friend_id>', methods=["GET", "POST"])
|
||||
def messages():
|
||||
def messages(user_id, friend_id):
|
||||
if request.method == "GET":
|
||||
return jsonify()
|
||||
messages = self.module.data.get_chat(user_id, friend_id)
|
||||
return jsonify(messages)
|
||||
elif request.method == "POST":
|
||||
content:dict = request.json
|
||||
message = self.module.create_message(content["from"], content["to"], content["content"], content["medias"])
|
||||
message = self.module.create_message(user_id, friend_id, content["content"], content["medias"])
|
||||
return jsonify(message)
|
||||
|
||||
# @self.blueprint.route('/posts', methods=["GET", "POST"])
|
||||
|
||||
@@ -37,14 +37,14 @@ export const p2privateApi = {
|
||||
},
|
||||
|
||||
async createMessage(from, to, content, medias){
|
||||
const data = {"from":from, "to":to, "content":content, "medias":medias}
|
||||
const data = {"content":content, "medias":medias}
|
||||
const requestOptions = {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json',},
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
try {
|
||||
const response = await fetch(p2privateApiUrl+"/messages", requestOptions);
|
||||
const response = await fetch(p2privateApiUrl+"/messages/"+from+"/"+to, requestOptions);
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Error fetching posts: ${response.status} - ${errorText}`);
|
||||
@@ -59,6 +59,21 @@ export const p2privateApi = {
|
||||
}
|
||||
},
|
||||
|
||||
async getChat(from, to){
|
||||
try {
|
||||
const response = await fetch(p2privateApiUrl+"/messages/"+from+"/"+to)
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Error fetching networks: ${response.status} - ${errorText}`);
|
||||
}
|
||||
const result = await response.json()
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("Error fetching networks:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// async createPosts(user, content, medias, networks){
|
||||
// const data = {"user": user, "content": content, "medias": medias, "networks": networks};
|
||||
// const requestOptions = {
|
||||
|
||||
@@ -13,6 +13,7 @@ import { p2postApi } from '@/modules/p2post/api/p2postApi';
|
||||
const friends = ref([])
|
||||
const activeFriend = ref(null)
|
||||
const myUsers = ref([])
|
||||
const currentUser = ref({"pubkey":null})
|
||||
|
||||
const relays = ref([])
|
||||
|
||||
@@ -20,31 +21,39 @@ async function getRelays(){
|
||||
relays.value = await p2privateApi.getNetworks()
|
||||
}
|
||||
|
||||
async function getFriends(){
|
||||
async function getFriends(user){
|
||||
const result = await p2privateApi.getFriends()
|
||||
for (const f of result){
|
||||
const m1 = {id:1, senderId:'me', content:"test Meeeeeeeeeeeeeeeeeeeeee", timestamp:new Date(), status:"SENT"}
|
||||
const m2 = {id:2, senderId:'peer', content:"test Peer", status:"RECEIVED", timestamp:new Date(), files:[{name:'file1', type:'image/jpeg', size:123}]}
|
||||
const mes = [m1,m2]
|
||||
const fr = {nickname:'Nickname', unreadCount:5, publicKey:f.pubkey, isOnline:true, messages:mes}
|
||||
const chat = await p2privateApi.getChat(user.pubkey, f.pubkey)
|
||||
const messages = []
|
||||
for (const m of chat){
|
||||
if (m.from === user.pubkey){
|
||||
var senderId = "me"
|
||||
}else{
|
||||
var senderId = "peer"
|
||||
}
|
||||
var message = {id:m.hash, senderId:senderId, content:m.content, timestamp:m.timestamp, status:"SENT"}
|
||||
messages.push(message)
|
||||
}
|
||||
const fr = {nickname:'Nickname', unreadCount:5, publicKey:f.pubkey, isOnline:true, messages:messages}
|
||||
friends.value.push(fr)
|
||||
}
|
||||
}
|
||||
|
||||
async function getMyUsers(){
|
||||
myUsers.value = await p2postApi.getMyUsers()
|
||||
const randomIndex = Math.floor(Math.random() * myUsers.value.length);
|
||||
currentUser.value = myUsers.value[randomIndex]
|
||||
getFriends(currentUser.value)
|
||||
}
|
||||
|
||||
const inputMessageText = ref("")
|
||||
async function createMessage(){
|
||||
const randomIndex = Math.floor(Math.random() * myUsers.value.length);
|
||||
const randomUser = myUsers.value[randomIndex]
|
||||
await p2privateApi.createMessage(randomUser.pubkey, activeFriend.value.publicKey, inputMessageText.value, [])
|
||||
await p2privateApi.createMessage(currentUser.value.pubkey, activeFriend.value.publicKey, inputMessageText.value, [])
|
||||
}
|
||||
|
||||
onMounted(()=>{
|
||||
getRelays()
|
||||
getFriends()
|
||||
getMyUsers()
|
||||
})
|
||||
|
||||
@@ -109,6 +118,7 @@ onMounted(()=>{
|
||||
<UsersIcon class="w-5 h-5 mr-2" />
|
||||
Friends ({{friends.length}})
|
||||
</h3>
|
||||
<span class="text-sm">{{ currentUser.pubkey }}</span>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto p-4 space-y-2">
|
||||
|
||||
Reference in New Issue
Block a user