syncing profile

This commit is contained in:
Roland Osborne 2022-04-04 14:56:57 -07:00
parent 6b9139009f
commit 00d0f6b8cd
8 changed files with 42 additions and 13 deletions

View File

@ -3343,6 +3343,8 @@ components:
type: string
node:
type: string
revision:
type: int64
CardDetail:
type: object

View File

@ -46,8 +46,6 @@ func GetCards(w http.ResponseWriter, r *http.Request) {
}
}
PrintMsg(response);
w.Header().Set("Card-Revision", strconv.FormatInt(account.CardRevision, 10))
WriteResponse(w, response)
}

View File

@ -10,7 +10,7 @@ import (
func SetCardProfile(w http.ResponseWriter, r *http.Request) {
account, code, err := BearerAppToken(r, false);
account, code, err := ParamAgentToken(r, false);
if err != nil {
ErrResponse(w, code, err)
return

View File

@ -148,6 +148,7 @@ type Card struct {
Location string
Image string
Version string `gorm:"not null"`
Revision string `gorm:"not null"`
Node string `gorm:"not null"`
ProfileRevision int64 `gorm:"not null"`
DetailRevision int64 `gorm:"not null;default:1"`

View File

@ -113,8 +113,13 @@ export async function getCards(token, revision) {
}
export async function getCardProfile(token, cardId) {
let param = "?agent=" + token
let profile = await fetchWithTimeout(`/contact/cards/${cardId}/profile${param}`, { method: 'GET', timeout: FETCH_TIMEOUT });
let profile = await fetchWithTimeout(`/contact/cards/${cardId}/profile?agent=${token}`, { 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);
return await profile.json()
}
@ -126,3 +131,9 @@ export async function getCardDetail(token, cardId) {
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()
}

View File

@ -1,5 +1,5 @@
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) {
let status = await getAccountStatus(token);
@ -25,6 +25,7 @@ async function updateGroups(token, revision, groupMap, updateData) {
}
async function updateCards(token, revision, cardMap, updateData) {
let cards = await getCards(token, revision);
for (let card of cards) {
if (card.data) {
@ -42,7 +43,7 @@ async function updateCards(token, revision, cardMap, updateData) {
cur.data.detailRevision = card.data.detailRevision;
}
if (cur.data.profileRevision != card.data.profileRevision) {
if (cur.data.cardProfile != null) {
if (card.data.cardProfile != null) {
cur.data.cardProfile = card.data.cardProfile;
}
else {
@ -50,7 +51,12 @@ async function updateCards(token, revision, cardMap, updateData) {
}
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
cur.data.notifiedProfile = card.data.notifiedProfile;
}

View File

@ -66,8 +66,17 @@ export const ContactWrapper = styled.div`
width: 192px;
min-width: 192px;
font-size: 8em;
border-radius: 8px;
overflow: hidden;
border: 1px solid #888888;
}
.logo {
width: 192px;
height 192px;
display: flex;
justify-content: flex-end;
align-items: center;
justify-content: center;
}
.unset {
@ -117,7 +126,6 @@ export const ContactWrapper = styled.div`
align-items: center;
justify-content: flex-end;
width: 50%;
cursor: pointer;
}
`;

View File

@ -2,6 +2,8 @@ import { useContext, useState, useEffect } from 'react';
import { AppContext } from '../../AppContext/AppContext';
import { useNavigate } from "react-router-dom";
const IMAGE_DIM = 256;
export function useProfile() {
const [state, setState] = useState({
@ -79,10 +81,11 @@ export function useProfile() {
img.onload = () => {
var canvas = document.createElement("canvas");
var context = canvas.getContext('2d');
canvas.width = 128;
canvas.height = 128;
canvas.width = IMAGE_DIM;
canvas.height = IMAGE_DIM;
context.imageSmoothingQuality = "medium";
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());
}
img.onerror = reject;