55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
|
package model
|
||
|
|
||
|
import "encoding/json"
|
||
|
|
||
|
// AccessControl is a type determining client assigned authorization to a peer
|
||
|
type AccessControl struct {
|
||
|
Blocked bool // Any attempts from this handle to connect are blocked
|
||
|
Read bool // Allows a handle to access the conversation
|
||
|
Append bool // Allows a handle to append new messages to the conversation
|
||
|
}
|
||
|
|
||
|
// DefaultP2PAccessControl - because in the year 2021, go does not support constant structs...
|
||
|
func DefaultP2PAccessControl() AccessControl {
|
||
|
return AccessControl{Read: true, Append: true, Blocked: false}
|
||
|
}
|
||
|
|
||
|
// AccessControlList represents an access control list for a conversation. Mapping handles to conversation
|
||
|
// functions
|
||
|
type AccessControlList map[string]AccessControl
|
||
|
|
||
|
func (acl *AccessControlList) Serialize() []byte {
|
||
|
data, _ := json.Marshal(acl)
|
||
|
return data
|
||
|
}
|
||
|
|
||
|
func DeserializeAccessControlList(data []byte) AccessControlList {
|
||
|
var acl AccessControlList
|
||
|
json.Unmarshal(data, &acl)
|
||
|
return acl
|
||
|
}
|
||
|
|
||
|
type Attributes map[string]string
|
||
|
|
||
|
func (a *Attributes) Serialize() []byte {
|
||
|
data, _ := json.Marshal(a)
|
||
|
return data
|
||
|
}
|
||
|
|
||
|
func DeserializeAttributes(data []byte) Attributes {
|
||
|
var attributes Attributes
|
||
|
json.Unmarshal(data, &attributes)
|
||
|
return attributes
|
||
|
}
|
||
|
|
||
|
// Conversation encapsulates high-level information about a conversation, including the
|
||
|
// handle, any set attributes, the access control list associated with the message tree and the
|
||
|
// accepted status of the conversation (whether the user has consented into the conversation).
|
||
|
type Conversation struct {
|
||
|
ID int
|
||
|
Handle string
|
||
|
Attributes Attributes
|
||
|
ACL AccessControlList
|
||
|
Accepted bool
|
||
|
}
|