This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 823
Support prioritized room list filters #4737
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -45,3 +45,63 @@ export function arrayDiff<T>(a: T[], b: T[]): { added: T[], removed: T[] } { | |
removed: a.filter(i => !b.includes(i)), | ||
}; | ||
} | ||
|
||
/** | ||
* Helper functions to perform LINQ-like queries on arrays. | ||
*/ | ||
export class ArrayUtil<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly LINQArray or Array2 to fully embrace .net bad practices. Or dump these on the Array prototype and forget that they're custom to the project There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yikes. 😨 Let's just leave it as-is for now, can change if we're inspired later. |
||
/** | ||
* Create a new array helper. | ||
* @param a The array to help. Can be modified in-place. | ||
*/ | ||
constructor(private a: T[]) { | ||
} | ||
|
||
/** | ||
* The value of this array, after all appropriate alterations. | ||
*/ | ||
public get value(): T[] { | ||
return this.a; | ||
} | ||
|
||
/** | ||
* Groups an array by keys. | ||
* @param fn The key-finding function. | ||
* @returns This. | ||
*/ | ||
public groupBy<K>(fn: (a: T) => K): GroupedArray<K, T> { | ||
const obj = this.a.reduce((rv: Map<K, T[]>, val: T) => { | ||
const k = fn(val); | ||
if (!rv.has(k)) rv.set(k, []); | ||
rv.get(k).push(val); | ||
return rv; | ||
}, new Map<K, T[]>()); | ||
return new GroupedArray(obj); | ||
} | ||
} | ||
|
||
/** | ||
* Helper functions to perform LINQ-like queries on groups (maps). | ||
*/ | ||
export class GroupedArray<K, T> { | ||
/** | ||
* Creates a new group helper. | ||
* @param val The group to help. Can be modified in-place. | ||
*/ | ||
constructor(private val: Map<K, T[]>) { | ||
} | ||
|
||
/** | ||
* Orders the grouping into an array using the provided key order. | ||
* @param keyOrder The key order. | ||
* @returns An array helper of the result. | ||
*/ | ||
public orderBy(keyOrder: K[]): ArrayUtil<T> { | ||
const a: T[] = []; | ||
for (const k of keyOrder) { | ||
if (!this.val.has(k)) continue; | ||
a.push(...this.val.get(k)); | ||
} | ||
return new ArrayUtil(a); | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright 2020 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Get the values for an enum. | ||
* @param e The enum. | ||
* @returns The enum values. | ||
*/ | ||
export function getEnumValues<T>(e: any): T[] { | ||
const keys = Object.keys(e); | ||
return keys | ||
.filter(k => ['string', 'number'].includes(typeof(e[k]))) | ||
.map(k => e[k]); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you're slowly implementing every C# / .NET Framework feature... 😜
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really wanted
groupBy