@shaxpir/duiduidui-models 1.6.4 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models/Content.d.ts +2 -1
- package/dist/models/ContentKind.d.ts +1 -0
- package/dist/models/ContentKind.js +1 -0
- package/dist/models/Model.js +3 -2
- package/dist/models/Social.d.ts +64 -0
- package/dist/models/Social.js +148 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +1 -0
- package/package.json +1 -1
package/dist/models/Content.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { Model } from './Model';
|
|
|
10
10
|
import { ProfilePayload } from "./Profile";
|
|
11
11
|
import { ProgressPayload } from './Progress';
|
|
12
12
|
import { SessionPayload } from './Session';
|
|
13
|
+
import { SocialPayload } from './Social';
|
|
13
14
|
import { TermPayload } from './Term';
|
|
14
15
|
import { UserPayload } from './User';
|
|
15
16
|
import { WorkspacePayload } from './Workspace';
|
|
@@ -36,7 +37,7 @@ export interface ContentMeta {
|
|
|
36
37
|
created_at: MultiTime;
|
|
37
38
|
updated_at: MultiTime;
|
|
38
39
|
}
|
|
39
|
-
export type ContentPayload = BillingPayload | DevicePayload | ImagePayload | MetricPayload | ProfilePayload | ProgressPayload | SessionPayload | TermPayload | UserPayload | WorkspacePayload;
|
|
40
|
+
export type ContentPayload = BillingPayload | DevicePayload | ImagePayload | MetricPayload | ProfilePayload | ProgressPayload | SessionPayload | SocialPayload | TermPayload | UserPayload | WorkspacePayload;
|
|
40
41
|
export declare abstract class Content extends Model {
|
|
41
42
|
static ID_LENGTH: number;
|
|
42
43
|
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
@@ -11,6 +11,7 @@ var ContentKind;
|
|
|
11
11
|
ContentKind["PROFILE"] = "profile";
|
|
12
12
|
ContentKind["PROGRESS"] = "progress";
|
|
13
13
|
ContentKind["SESSION"] = "session";
|
|
14
|
+
ContentKind["SOCIAL"] = "social";
|
|
14
15
|
ContentKind["TERM"] = "term";
|
|
15
16
|
ContentKind["USER"] = "user";
|
|
16
17
|
ContentKind["IMAGE"] = "image";
|
package/dist/models/Model.js
CHANGED
|
@@ -19,6 +19,7 @@ class Model {
|
|
|
19
19
|
model._isDisposed = false;
|
|
20
20
|
model._isForbidden = false;
|
|
21
21
|
model._hasEventListeners = false;
|
|
22
|
+
model._shouldPerformModelChangeAnalysis = true;
|
|
22
23
|
const onBeforeOpBatch = function (op, source) {
|
|
23
24
|
if (model._shouldPerformModelChangeAnalysis) {
|
|
24
25
|
model._dataBeforeOpBatch = shaxpir_common_1.Struct.clone(model.doc.data);
|
|
@@ -277,13 +278,13 @@ class Model {
|
|
|
277
278
|
return data.meta.owner === userId;
|
|
278
279
|
}
|
|
279
280
|
static doesUserHaveContentPermission(kind, meta, userId, type) {
|
|
280
|
-
// Users are allowed to read any of their own content, but they are not allowed to write their User or
|
|
281
|
+
// Users are allowed to read any of their own content, but they are not allowed to write their User, Billing, or Social objects.
|
|
281
282
|
if (meta.owner === userId) {
|
|
282
283
|
if (type === Permissions_1.PermissionType.READ) {
|
|
283
284
|
return true;
|
|
284
285
|
}
|
|
285
286
|
else if (type === Permissions_1.PermissionType.WRITE) {
|
|
286
|
-
return kind !== ContentKind_1.ContentKind.USER && kind !== ContentKind_1.ContentKind.BILLING;
|
|
287
|
+
return kind !== ContentKind_1.ContentKind.USER && kind !== ContentKind_1.ContentKind.BILLING && kind !== ContentKind_1.ContentKind.SOCIAL;
|
|
287
288
|
}
|
|
288
289
|
}
|
|
289
290
|
// If all else fails, deny permission.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
2
|
+
import { CompactDateTime } from '@shaxpir/shaxpir-common';
|
|
3
|
+
import { ShareSync } from '../repo';
|
|
4
|
+
import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
5
|
+
export declare enum FriendRequestStatus {
|
|
6
|
+
PENDING = "pending",
|
|
7
|
+
ACCEPTED = "accepted",
|
|
8
|
+
REJECTED = "rejected"
|
|
9
|
+
}
|
|
10
|
+
export interface FriendRequest {
|
|
11
|
+
request_id: string;
|
|
12
|
+
from_user_id: ContentId;
|
|
13
|
+
to_user_id: ContentId;
|
|
14
|
+
from_username: string;
|
|
15
|
+
from_full_name: string;
|
|
16
|
+
to_username: string;
|
|
17
|
+
to_full_name: string;
|
|
18
|
+
status: FriendRequestStatus;
|
|
19
|
+
created_at: CompactDateTime;
|
|
20
|
+
updated_at: CompactDateTime;
|
|
21
|
+
}
|
|
22
|
+
export interface Friend {
|
|
23
|
+
user_id: ContentId;
|
|
24
|
+
username: string;
|
|
25
|
+
full_name: string;
|
|
26
|
+
since: CompactDateTime;
|
|
27
|
+
}
|
|
28
|
+
export interface BlockedUser {
|
|
29
|
+
user_id: ContentId;
|
|
30
|
+
username: string;
|
|
31
|
+
full_name: string;
|
|
32
|
+
blocked_at: CompactDateTime;
|
|
33
|
+
}
|
|
34
|
+
export interface SocialPayload {
|
|
35
|
+
outgoing_requests: FriendRequest[];
|
|
36
|
+
incoming_requests: FriendRequest[];
|
|
37
|
+
friends: Friend[];
|
|
38
|
+
blocked_users: BlockedUser[];
|
|
39
|
+
}
|
|
40
|
+
export interface SocialBody extends ContentBody {
|
|
41
|
+
meta: ContentMeta;
|
|
42
|
+
payload: SocialPayload;
|
|
43
|
+
}
|
|
44
|
+
export declare class Social extends Content {
|
|
45
|
+
static makeSocialId(userId: ContentId): ContentId;
|
|
46
|
+
static create(userId: ContentId): Social;
|
|
47
|
+
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
48
|
+
get payload(): SocialPayload;
|
|
49
|
+
getOutgoingRequests(): FriendRequest[];
|
|
50
|
+
addOutgoingRequest(request: FriendRequest): void;
|
|
51
|
+
removeOutgoingRequest(requestId: string): void;
|
|
52
|
+
getIncomingRequests(): FriendRequest[];
|
|
53
|
+
addIncomingRequest(request: FriendRequest): void;
|
|
54
|
+
removeIncomingRequest(requestId: string): void;
|
|
55
|
+
updateIncomingRequestStatus(requestId: string, status: FriendRequestStatus): void;
|
|
56
|
+
getFriends(): Friend[];
|
|
57
|
+
addFriend(friend: Friend): void;
|
|
58
|
+
removeFriend(userId: ContentId): void;
|
|
59
|
+
isFriend(userId: ContentId): boolean;
|
|
60
|
+
getBlockedUsers(): BlockedUser[];
|
|
61
|
+
addBlockedUser(blockedUser: BlockedUser): void;
|
|
62
|
+
removeBlockedUser(userId: ContentId): void;
|
|
63
|
+
isBlocked(userId: ContentId): boolean;
|
|
64
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Social = exports.FriendRequestStatus = void 0;
|
|
4
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
5
|
+
const repo_1 = require("../repo");
|
|
6
|
+
const Content_1 = require("./Content");
|
|
7
|
+
const ContentKind_1 = require("./ContentKind");
|
|
8
|
+
const Operation_1 = require("./Operation");
|
|
9
|
+
var FriendRequestStatus;
|
|
10
|
+
(function (FriendRequestStatus) {
|
|
11
|
+
FriendRequestStatus["PENDING"] = "pending";
|
|
12
|
+
FriendRequestStatus["ACCEPTED"] = "accepted";
|
|
13
|
+
FriendRequestStatus["REJECTED"] = "rejected";
|
|
14
|
+
})(FriendRequestStatus || (exports.FriendRequestStatus = FriendRequestStatus = {}));
|
|
15
|
+
class Social extends Content_1.Content {
|
|
16
|
+
static makeSocialId(userId) {
|
|
17
|
+
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.SOCIAL);
|
|
18
|
+
}
|
|
19
|
+
static create(userId) {
|
|
20
|
+
const now = shaxpir_common_1.ClockService.getClock().now();
|
|
21
|
+
const socialId = Social.makeSocialId(userId);
|
|
22
|
+
return repo_1.ShareSyncFactory.get().createContent({
|
|
23
|
+
meta: {
|
|
24
|
+
ref: socialId,
|
|
25
|
+
kind: ContentKind_1.ContentKind.SOCIAL,
|
|
26
|
+
id: socialId,
|
|
27
|
+
owner: userId,
|
|
28
|
+
created_at: now,
|
|
29
|
+
updated_at: now
|
|
30
|
+
},
|
|
31
|
+
payload: {
|
|
32
|
+
outgoing_requests: [],
|
|
33
|
+
incoming_requests: [],
|
|
34
|
+
friends: [],
|
|
35
|
+
blocked_users: []
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
constructor(doc, shouldAcquire, shareSync) {
|
|
40
|
+
super(doc, shouldAcquire, shareSync);
|
|
41
|
+
}
|
|
42
|
+
get payload() {
|
|
43
|
+
this.checkDisposed("Social.payload");
|
|
44
|
+
return this.doc.data.payload;
|
|
45
|
+
}
|
|
46
|
+
// ========== Outgoing Requests ==========
|
|
47
|
+
getOutgoingRequests() {
|
|
48
|
+
this.checkDisposed("Social.getOutgoingRequests");
|
|
49
|
+
return [...this.payload.outgoing_requests];
|
|
50
|
+
}
|
|
51
|
+
addOutgoingRequest(request) {
|
|
52
|
+
this.checkDisposed("Social.addOutgoingRequest");
|
|
53
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
54
|
+
batch.pushIntoArray(['payload', 'outgoing_requests'], request);
|
|
55
|
+
batch.commit();
|
|
56
|
+
}
|
|
57
|
+
removeOutgoingRequest(requestId) {
|
|
58
|
+
this.checkDisposed("Social.removeOutgoingRequest");
|
|
59
|
+
const index = this.payload.outgoing_requests.findIndex(r => r.request_id === requestId);
|
|
60
|
+
if (index !== -1) {
|
|
61
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
62
|
+
batch.removeValueAtPath(['payload', 'outgoing_requests', index]);
|
|
63
|
+
batch.commit();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// ========== Incoming Requests ==========
|
|
67
|
+
getIncomingRequests() {
|
|
68
|
+
this.checkDisposed("Social.getIncomingRequests");
|
|
69
|
+
return [...this.payload.incoming_requests];
|
|
70
|
+
}
|
|
71
|
+
addIncomingRequest(request) {
|
|
72
|
+
this.checkDisposed("Social.addIncomingRequest");
|
|
73
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
74
|
+
batch.pushIntoArray(['payload', 'incoming_requests'], request);
|
|
75
|
+
batch.commit();
|
|
76
|
+
}
|
|
77
|
+
removeIncomingRequest(requestId) {
|
|
78
|
+
this.checkDisposed("Social.removeIncomingRequest");
|
|
79
|
+
const index = this.payload.incoming_requests.findIndex(r => r.request_id === requestId);
|
|
80
|
+
if (index !== -1) {
|
|
81
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
82
|
+
batch.removeValueAtPath(['payload', 'incoming_requests', index]);
|
|
83
|
+
batch.commit();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
updateIncomingRequestStatus(requestId, status) {
|
|
87
|
+
this.checkDisposed("Social.updateIncomingRequestStatus");
|
|
88
|
+
const index = this.payload.incoming_requests.findIndex(r => r.request_id === requestId);
|
|
89
|
+
if (index !== -1) {
|
|
90
|
+
const now = shaxpir_common_1.ClockService.getClock().utc();
|
|
91
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
92
|
+
batch.setPathValue(['payload', 'incoming_requests', index, 'status'], status);
|
|
93
|
+
batch.setPathValue(['payload', 'incoming_requests', index, 'updated_at'], now);
|
|
94
|
+
batch.commit();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// ========== Friends ==========
|
|
98
|
+
getFriends() {
|
|
99
|
+
this.checkDisposed("Social.getFriends");
|
|
100
|
+
return [...this.payload.friends];
|
|
101
|
+
}
|
|
102
|
+
addFriend(friend) {
|
|
103
|
+
this.checkDisposed("Social.addFriend");
|
|
104
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
105
|
+
batch.pushIntoArray(['payload', 'friends'], friend);
|
|
106
|
+
batch.commit();
|
|
107
|
+
}
|
|
108
|
+
removeFriend(userId) {
|
|
109
|
+
this.checkDisposed("Social.removeFriend");
|
|
110
|
+
const index = this.payload.friends.findIndex(f => f.user_id === userId);
|
|
111
|
+
if (index !== -1) {
|
|
112
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
113
|
+
batch.removeValueAtPath(['payload', 'friends', index]);
|
|
114
|
+
batch.commit();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
isFriend(userId) {
|
|
118
|
+
this.checkDisposed("Social.isFriend");
|
|
119
|
+
return this.payload.friends.some(f => f.user_id === userId);
|
|
120
|
+
}
|
|
121
|
+
// ========== Blocked Users ==========
|
|
122
|
+
getBlockedUsers() {
|
|
123
|
+
this.checkDisposed("Social.getBlockedUsers");
|
|
124
|
+
return [...this.payload.blocked_users];
|
|
125
|
+
}
|
|
126
|
+
addBlockedUser(blockedUser) {
|
|
127
|
+
this.checkDisposed("Social.addBlockedUser");
|
|
128
|
+
if (!this.payload.blocked_users.some(b => b.user_id === blockedUser.user_id)) {
|
|
129
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
130
|
+
batch.pushIntoArray(['payload', 'blocked_users'], blockedUser);
|
|
131
|
+
batch.commit();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
removeBlockedUser(userId) {
|
|
135
|
+
this.checkDisposed("Social.removeBlockedUser");
|
|
136
|
+
const index = this.payload.blocked_users.findIndex(b => b.user_id === userId);
|
|
137
|
+
if (index !== -1) {
|
|
138
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
139
|
+
batch.removeValueAtPath(['payload', 'blocked_users', index]);
|
|
140
|
+
batch.commit();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
isBlocked(userId) {
|
|
144
|
+
this.checkDisposed("Social.isBlocked");
|
|
145
|
+
return this.payload.blocked_users.some(b => b.user_id === userId);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.Social = Social;
|
package/dist/models/index.d.ts
CHANGED
package/dist/models/index.js
CHANGED
|
@@ -37,6 +37,7 @@ __exportStar(require("./Profile"), exports);
|
|
|
37
37
|
__exportStar(require("./Progress"), exports);
|
|
38
38
|
__exportStar(require("./Review"), exports);
|
|
39
39
|
__exportStar(require("./Session"), exports);
|
|
40
|
+
__exportStar(require("./Social"), exports);
|
|
40
41
|
__exportStar(require("./Term"), exports);
|
|
41
42
|
__exportStar(require("./User"), exports);
|
|
42
43
|
__exportStar(require("./Workspace"), exports);
|