-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Update modifyClass calls to native class syntax
- Loading branch information
1 parent
e603f06
commit 1ffafb5
Showing
2 changed files
with
160 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,73 @@ | ||
import { Assignment } from "./assignment"; | ||
|
||
export function extendTopicModel(api, pluginId) { | ||
api.modifyClass("model:topic", { | ||
pluginId, | ||
export function extendTopicModel(api) { | ||
api.modifyClass( | ||
"model:topic", | ||
(Superclass) => | ||
class extends Superclass { | ||
assignees() { | ||
const result = []; | ||
|
||
assignees() { | ||
const result = []; | ||
if (this.assigned_to_user) { | ||
result.push(this.assigned_to_user); | ||
} | ||
|
||
if (this.assigned_to_user) { | ||
result.push(this.assigned_to_user); | ||
} | ||
const postAssignees = this.assignedPosts().map((p) => p.assigned_to); | ||
result.push(...postAssignees); | ||
return result; | ||
} | ||
|
||
const postAssignees = this.assignedPosts().map((p) => p.assigned_to); | ||
result.push(...postAssignees); | ||
return result; | ||
}, | ||
uniqueAssignees() { | ||
const map = new Map(); | ||
this.assignees().forEach((user) => map.set(user.username, user)); | ||
return [...map.values()]; | ||
} | ||
|
||
uniqueAssignees() { | ||
const map = new Map(); | ||
this.assignees().forEach((user) => map.set(user.username, user)); | ||
return [...map.values()]; | ||
}, | ||
assignedPosts() { | ||
if (!this.indirectly_assigned_to) { | ||
return []; | ||
} | ||
|
||
assignedPosts() { | ||
if (!this.indirectly_assigned_to) { | ||
return []; | ||
} | ||
return Object.entries(this.indirectly_assigned_to).map( | ||
([key, value]) => { | ||
value.postId = key; | ||
return value; | ||
} | ||
); | ||
} | ||
|
||
return Object.entries(this.indirectly_assigned_to).map(([key, value]) => { | ||
value.postId = key; | ||
return value; | ||
}); | ||
}, | ||
assignments() { | ||
return [this.topicAssignment(), ...this.postAssignments()].compact(); | ||
} | ||
|
||
assignments() { | ||
return [this.topicAssignment(), ...this.postAssignments()].compact(); | ||
}, | ||
postAssignments() { | ||
if (!this.indirectly_assigned_to) { | ||
return []; | ||
} | ||
|
||
postAssignments() { | ||
if (!this.indirectly_assigned_to) { | ||
return []; | ||
} | ||
return Object.entries(this.indirectly_assigned_to).map( | ||
([key, value]) => { | ||
value.postId = key; | ||
return Assignment.fromPost(value); | ||
} | ||
); | ||
} | ||
|
||
return Object.entries(this.indirectly_assigned_to).map(([key, value]) => { | ||
value.postId = key; | ||
return Assignment.fromPost(value); | ||
}); | ||
}, | ||
topicAssignment() { | ||
return Assignment.fromTopic(this); | ||
} | ||
|
||
topicAssignment() { | ||
return Assignment.fromTopic(this); | ||
}, | ||
isAssigned() { | ||
return this.assigned_to_user || this.assigned_to_group; | ||
} | ||
|
||
isAssigned() { | ||
return this.assigned_to_user || this.assigned_to_group; | ||
}, | ||
isAssignedTo(user) { | ||
return this.assigned_to_user?.username === user.username; | ||
} | ||
|
||
isAssignedTo(user) { | ||
return this.assigned_to_user?.username === user.username; | ||
}, | ||
|
||
hasAssignedPosts() { | ||
return !!this.postAssignments().length; | ||
}, | ||
}); | ||
hasAssignedPosts() { | ||
return !!this.postAssignments().length; | ||
} | ||
} | ||
); | ||
} |