mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
added remaining profile actions
This commit is contained in:
parent
9d7220486f
commit
5866d2fd99
48
net/server/internal/api_getAccountListingMessage.go
Normal file
48
net/server/internal/api_getAccountListingMessage.go
Normal file
@ -0,0 +1,48 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"gorm.io/gorm"
|
||||
"databag/internal/store"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func GetAccountListingMessage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// get referenced account guid
|
||||
params := mux.Vars(r)
|
||||
guid := params["guid"]
|
||||
|
||||
var account store.Account
|
||||
if err := store.DB.Preload("AccountDetail").Where("guid = ? AND searchable = ? AND disabled = ?", guid, true, false).First(&account).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
ErrResponse(w, http.StatusNotFound, err)
|
||||
} else {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
detail := account.AccountDetail;
|
||||
|
||||
// generate identity DataMessage
|
||||
identity := Identity{
|
||||
Revision: account.ProfileRevision,
|
||||
Handle: account.Username,
|
||||
Name: detail.Name,
|
||||
Description: detail.Description,
|
||||
Location: detail.Location,
|
||||
Image: detail.Image,
|
||||
Version: APP_VERSION,
|
||||
Node: getStrConfigValue(CONFIG_DOMAIN, ""),
|
||||
}
|
||||
msg, res := WriteDataMessage(detail.PrivateKey, detail.PublicKey, detail.KeyType,
|
||||
APP_SIGNPKCS1V15, account.Guid, APP_MSGIDENTITY, &identity)
|
||||
if res != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, res)
|
||||
return
|
||||
}
|
||||
|
||||
WriteResponse(w, msg)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func GetCloseMessage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
account, code, res := BearerAppToken(r, true);
|
||||
account, code, res := ParamAgentToken(r, true);
|
||||
if res != nil {
|
||||
ErrResponse(w, code, res)
|
||||
return
|
||||
|
@ -51,14 +51,7 @@ func SetCloseMessage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
slot := card.CardSlot
|
||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
if card.Status == APP_CARDPENDING {
|
||||
if res := tx.Model(&slot).Update("card_id", 0).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Delete(&card).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
} else {
|
||||
if card.Status != APP_CARDPENDING {
|
||||
if res := tx.Model(&card).Update("status", APP_CARDCONFIRMED).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
|
@ -128,6 +128,7 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) {
|
||||
card.Status = APP_CARDCONNECTED
|
||||
}
|
||||
card.OutToken = connect.Token
|
||||
card.DetailRevision = account.CardRevision + 1
|
||||
|
||||
// save contact card
|
||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
|
8
net/web/src/Api/getCardCloseMessage.js
Normal file
8
net/web/src/Api/getCardCloseMessage.js
Normal file
@ -0,0 +1,8 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function getCardCloseMessage(token, cardId) {
|
||||
let message = await fetchWithTimeout(`/contact/cards/${cardId}/closeMessage?agent=${token}`, { method: 'GET' });
|
||||
checkResponse(message);
|
||||
return await message.json();
|
||||
}
|
||||
|
8
net/web/src/Api/setCardCloseMessage.js
Normal file
8
net/web/src/Api/setCardCloseMessage.js
Normal file
@ -0,0 +1,8 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setCardCloseMessage(server, message) {
|
||||
let status = await fetchWithTimeout(`https://${server}/contact/closeMessage`, { method: 'PUT', body: JSON.stringify(message) });
|
||||
checkResponse(status);
|
||||
return await status.json();
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ export function Contact() {
|
||||
|
||||
const Disconnect = () => {
|
||||
if (state.showButtons.disconnect) {
|
||||
return <ProfileButton ghost>Disconnect</ProfileButton>
|
||||
return <ProfileButton ghost onClick={() => actions.disconnect()}>Disconnect</ProfileButton>
|
||||
}
|
||||
return <></>
|
||||
}
|
||||
@ -55,14 +55,21 @@ export function Contact() {
|
||||
|
||||
const Cancel = () => {
|
||||
if (state.showButtons.cancel) {
|
||||
return <ProfileButton ghost>Cancel Request</ProfileButton>
|
||||
return <ProfileButton ghost onClick={() => actions.disconnect()}>Cancel Request</ProfileButton>
|
||||
}
|
||||
return <></>
|
||||
}
|
||||
|
||||
const Ignore = () => {
|
||||
if (state.showButtons.ignore) {
|
||||
return <ProfileButton ghost>Ignore Request</ProfileButton>
|
||||
return <ProfileButton ghost onClick={() => actions.remove()}>Ignore Request</ProfileButton>
|
||||
}
|
||||
return <></>
|
||||
}
|
||||
|
||||
const Deny = () => {
|
||||
if (state.showButtons.deny) {
|
||||
return <ProfileButton ghost onClick={() => actions.disconnect()}>Ignore Request</ProfileButton>
|
||||
}
|
||||
return <></>
|
||||
}
|
||||
@ -83,7 +90,7 @@ export function Contact() {
|
||||
|
||||
const SaveRequest = () => {
|
||||
if (state.showButtons.saveRequest) {
|
||||
return <ProfileButton ghost>Save & Request</ProfileButton>
|
||||
return <ProfileButton ghost onClick={() => actions.saveConnect()}>Save & Connect</ProfileButton>
|
||||
}
|
||||
return <></>
|
||||
}
|
||||
@ -95,16 +102,9 @@ export function Contact() {
|
||||
return <></>
|
||||
}
|
||||
|
||||
const SaveAccept = () => {
|
||||
if (state.showButtons.saveAccept) {
|
||||
return <ProfileButton ghost>Save & Accept</ProfileButton>
|
||||
}
|
||||
return <></>
|
||||
}
|
||||
|
||||
const Accept = () => {
|
||||
if (state.showButtons.accept) {
|
||||
return <ProfileButton ghost>Accept Connection</ProfileButton>
|
||||
return <ProfileButton ghost onClick={() => actions.connect()}>Accept Connection</ProfileButton>
|
||||
}
|
||||
return <></>
|
||||
}
|
||||
@ -115,15 +115,15 @@ export function Contact() {
|
||||
<div class="title">{ state.handle }</div>
|
||||
<div class="buttons">
|
||||
<ContactSpin size="large" spinning={state.busy} />
|
||||
<Disconnect />
|
||||
<Remove />
|
||||
<Disconnect />
|
||||
<Confirm />
|
||||
<Cancel />
|
||||
<Ignore />
|
||||
<Deny />
|
||||
<Save />
|
||||
<SaveRequest />
|
||||
<Connect />
|
||||
<SaveAccept />
|
||||
<Accept />
|
||||
</div>
|
||||
<CloseButton type="text" class="close" size={'large'} onClick={() => actions.close()} icon={<CloseOutlined />} />
|
||||
|
@ -7,6 +7,8 @@ import { removeCard } from '../../Api/removeCard';
|
||||
import { setCardConnecting, setCardConnected, setCardConfirmed } from '../../Api/setCardStatus';
|
||||
import { getCardOpenMessage } from '../../Api/getCardOpenMessage';
|
||||
import { setCardOpenMessage } from '../../Api/setCardOpenMessage';
|
||||
import { getCardCloseMessage } from '../../Api/getCardCloseMessage';
|
||||
import { setCardCloseMessage } from '../../Api/setCardCloseMessage';
|
||||
|
||||
export function useContact() {
|
||||
|
||||
@ -60,7 +62,7 @@ export function useContact() {
|
||||
}
|
||||
updateState({ busy: false });
|
||||
}
|
||||
},
|
||||
},
|
||||
connect: async () => {
|
||||
if (!state.busy) {
|
||||
updateState({ busy: true });
|
||||
@ -78,11 +80,24 @@ export function useContact() {
|
||||
updateState({ busy: false });
|
||||
}
|
||||
},
|
||||
disconnect: () => {
|
||||
},
|
||||
ignore: () => {
|
||||
},
|
||||
cancel: () => {
|
||||
disconnect: async () => {
|
||||
if (!state.busy) {
|
||||
updateState({ busy: true });
|
||||
try {
|
||||
await setCardConfirmed(app.state.token, state.cardId);
|
||||
try {
|
||||
let message = await getCardCloseMessage(app.state.token, state.cardId);
|
||||
await setCardCloseMessage(state.node, message);
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
window.alert(err);
|
||||
}
|
||||
updateState({ busy: false });
|
||||
}
|
||||
},
|
||||
remove: async () => {
|
||||
if (!state.busy) {
|
||||
@ -97,9 +112,24 @@ export function useContact() {
|
||||
updateState({ busy: false });
|
||||
}
|
||||
},
|
||||
saveRequest: () => {
|
||||
},
|
||||
saveAccept: () => {
|
||||
saveConnect: async () => {
|
||||
if (!state.busy) {
|
||||
updateState({ busy: true });
|
||||
try {
|
||||
let profile = await getListingMessage(state.node, guid);
|
||||
let card = await addCard(app.state.token, profile);
|
||||
await setCardConnecting(app.state.token, card.id);
|
||||
let open = await getCardOpenMessage(app.state.token, card.id);
|
||||
let contact = await setCardOpenMessage(state.node, open);
|
||||
if (contact.status === 'connected') {
|
||||
await setCardConnected(app.state.token, card.id, contact.token, contact.viewRevision, contact.articleRevision, contact.channelRevision, contact.profileRevision);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
window.alert(err);
|
||||
}
|
||||
updateState({ busy: false });
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@ -131,7 +161,7 @@ export function useContact() {
|
||||
}
|
||||
if (status === 'pending') {
|
||||
updateState({ status: 'pending' });
|
||||
updateState({ showButtons: { ignore: true, confirm: true, saveAccept: true }});
|
||||
updateState({ showButtons: { ignore: true, confirm: true, saveRequest: true }});
|
||||
}
|
||||
if (status === 'confirmed') {
|
||||
updateState({ status: 'confirmed' });
|
||||
@ -139,7 +169,7 @@ export function useContact() {
|
||||
}
|
||||
if (status === 'requested') {
|
||||
updateState({ status: 'requested' });
|
||||
updateState({ showButtons: { ignore: true, accept: true }});
|
||||
updateState({ showButtons: { deny: true, accept: true }});
|
||||
}
|
||||
}
|
||||
else if (data.state) {
|
||||
|
Loading…
Reference in New Issue
Block a user