mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
syncing profile
This commit is contained in:
parent
6b9139009f
commit
00d0f6b8cd
@ -3343,6 +3343,8 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
node:
|
node:
|
||||||
type: string
|
type: string
|
||||||
|
revision:
|
||||||
|
type: int64
|
||||||
|
|
||||||
CardDetail:
|
CardDetail:
|
||||||
type: object
|
type: object
|
||||||
|
@ -46,8 +46,6 @@ func GetCards(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintMsg(response);
|
|
||||||
|
|
||||||
w.Header().Set("Card-Revision", strconv.FormatInt(account.CardRevision, 10))
|
w.Header().Set("Card-Revision", strconv.FormatInt(account.CardRevision, 10))
|
||||||
WriteResponse(w, response)
|
WriteResponse(w, response)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func SetCardProfile(w http.ResponseWriter, r *http.Request) {
|
func SetCardProfile(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
account, code, err := BearerAppToken(r, false);
|
account, code, err := ParamAgentToken(r, false);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrResponse(w, code, err)
|
ErrResponse(w, code, err)
|
||||||
return
|
return
|
||||||
|
@ -148,6 +148,7 @@ type Card struct {
|
|||||||
Location string
|
Location string
|
||||||
Image string
|
Image string
|
||||||
Version string `gorm:"not null"`
|
Version string `gorm:"not null"`
|
||||||
|
Revision string `gorm:"not null"`
|
||||||
Node string `gorm:"not null"`
|
Node string `gorm:"not null"`
|
||||||
ProfileRevision int64 `gorm:"not null"`
|
ProfileRevision int64 `gorm:"not null"`
|
||||||
DetailRevision int64 `gorm:"not null;default:1"`
|
DetailRevision int64 `gorm:"not null;default:1"`
|
||||||
|
@ -113,8 +113,13 @@ export async function getCards(token, revision) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getCardProfile(token, cardId) {
|
export async function getCardProfile(token, cardId) {
|
||||||
let param = "?agent=" + token
|
let profile = await fetchWithTimeout(`/contact/cards/${cardId}/profile?agent=${token}`, { method: 'GET', timeout: FETCH_TIMEOUT });
|
||||||
let profile = await fetchWithTimeout(`/contact/cards/${cardId}/profile${param}`, { method: 'GET', timeout: FETCH_TIMEOUT });
|
checkResponse(profile);
|
||||||
|
return await profile.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setCardProfile(token, cardId, message) {
|
||||||
|
let profile = await fetchWithTimeout(`/contact/cards/${cardId}/profile?agent=${token}`, { method: 'PUT', body: JSON.stringify(message), timeout: FETCH_TIMEOUT });
|
||||||
checkResponse(profile);
|
checkResponse(profile);
|
||||||
return await profile.json()
|
return await profile.json()
|
||||||
}
|
}
|
||||||
@ -126,3 +131,9 @@ export async function getCardDetail(token, cardId) {
|
|||||||
return await detail.json()
|
return await detail.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getContactProfile(server, guid, token) {
|
||||||
|
let profile = await fetchWithTimeout(`https://${server}/profile/message?contact=${guid}.${token}`, { method: 'GET', timeout: FETCH_TIMEOUT });
|
||||||
|
checkResponse(profile);
|
||||||
|
return await profile.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState, useRef } from 'react';
|
import { useEffect, useState, useRef } from 'react';
|
||||||
import { getCards, getCardImageUrl, getCardProfile, getCardDetail, getListingImageUrl, getListing, setProfileImage, setProfileData, getProfileImageUrl, getAccountStatus, setAccountSearchable, getProfile, getGroups, getAvailable, getUsername, setLogin, createAccount } from './fetchUtil';
|
import { getContactProfile, setCardProfile, getCards, getCardImageUrl, getCardProfile, getCardDetail, getListingImageUrl, getListing, setProfileImage, setProfileData, getProfileImageUrl, getAccountStatus, setAccountSearchable, getProfile, getGroups, getAvailable, getUsername, setLogin, createAccount } from './fetchUtil';
|
||||||
|
|
||||||
async function updateAccount(token, updateData) {
|
async function updateAccount(token, updateData) {
|
||||||
let status = await getAccountStatus(token);
|
let status = await getAccountStatus(token);
|
||||||
@ -25,6 +25,7 @@ async function updateGroups(token, revision, groupMap, updateData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updateCards(token, revision, cardMap, updateData) {
|
async function updateCards(token, revision, cardMap, updateData) {
|
||||||
|
|
||||||
let cards = await getCards(token, revision);
|
let cards = await getCards(token, revision);
|
||||||
for (let card of cards) {
|
for (let card of cards) {
|
||||||
if (card.data) {
|
if (card.data) {
|
||||||
@ -42,7 +43,7 @@ async function updateCards(token, revision, cardMap, updateData) {
|
|||||||
cur.data.detailRevision = card.data.detailRevision;
|
cur.data.detailRevision = card.data.detailRevision;
|
||||||
}
|
}
|
||||||
if (cur.data.profileRevision != card.data.profileRevision) {
|
if (cur.data.profileRevision != card.data.profileRevision) {
|
||||||
if (cur.data.cardProfile != null) {
|
if (card.data.cardProfile != null) {
|
||||||
cur.data.cardProfile = card.data.cardProfile;
|
cur.data.cardProfile = card.data.cardProfile;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -50,7 +51,12 @@ async function updateCards(token, revision, cardMap, updateData) {
|
|||||||
}
|
}
|
||||||
cur.data.profileRevision = card.data.profileRevision;
|
cur.data.profileRevision = card.data.profileRevision;
|
||||||
}
|
}
|
||||||
if (cur.data.notifiedProfile != card.data.notifiedProfile) {
|
if (cur.data.profileRevision != card.data.notifiedProfile) {
|
||||||
|
const { cardDetail, cardProfile } = cur.data;
|
||||||
|
if (cardDetail.status === 'connected') {
|
||||||
|
let message = await getContactProfile(cardProfile.node, cardProfile.guid, cardDetail.token);
|
||||||
|
await setCardProfile(token, card.id, message);
|
||||||
|
}
|
||||||
// update remote profile
|
// update remote profile
|
||||||
cur.data.notifiedProfile = card.data.notifiedProfile;
|
cur.data.notifiedProfile = card.data.notifiedProfile;
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,17 @@ export const ContactWrapper = styled.div`
|
|||||||
width: 192px;
|
width: 192px;
|
||||||
min-width: 192px;
|
min-width: 192px;
|
||||||
font-size: 8em;
|
font-size: 8em;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid #888888;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
width: 192px;
|
||||||
|
height 192px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.unset {
|
.unset {
|
||||||
@ -117,7 +126,6 @@ export const ContactWrapper = styled.div`
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ import { useContext, useState, useEffect } from 'react';
|
|||||||
import { AppContext } from '../../AppContext/AppContext';
|
import { AppContext } from '../../AppContext/AppContext';
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
|
const IMAGE_DIM = 256;
|
||||||
|
|
||||||
export function useProfile() {
|
export function useProfile() {
|
||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
@ -79,10 +81,11 @@ export function useProfile() {
|
|||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
var canvas = document.createElement("canvas");
|
var canvas = document.createElement("canvas");
|
||||||
var context = canvas.getContext('2d');
|
var context = canvas.getContext('2d');
|
||||||
canvas.width = 128;
|
canvas.width = IMAGE_DIM;
|
||||||
canvas.height = 128;
|
canvas.height = IMAGE_DIM;
|
||||||
|
context.imageSmoothingQuality = "medium";
|
||||||
context.drawImage(img, state.crop.x, state.crop.y, state.crop.w, state.crop.h,
|
context.drawImage(img, state.crop.x, state.crop.y, state.crop.w, state.crop.h,
|
||||||
0, 0, 128, 128);
|
0, 0, IMAGE_DIM, IMAGE_DIM);
|
||||||
resolve(canvas.toDataURL());
|
resolve(canvas.toDataURL());
|
||||||
}
|
}
|
||||||
img.onerror = reject;
|
img.onerror = reject;
|
||||||
|
Loading…
Reference in New Issue
Block a user