Skip to content

Commit

Permalink
Remove groups (#2234)
Browse files Browse the repository at this point in the history
This API is due for removal in Synapse and has been deprecated for a very long time. People should move away from it soon, but just in case we'll declare this as a breaking change.

There is no impact on sync storage here: we happen to store the data in a way that is backwards-compatible for group-supporting clients, and the code guards against missing data from the stores. So, if someone were to revert, they'd be "safe" (probably lose all their group info, but the app wouldn't crash).
  • Loading branch information
turt2live authored Mar 22, 2022
1 parent 65316ff commit d0b9648
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 718 deletions.
406 changes: 1 addition & 405 deletions src/client.ts

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export * from "./errors";
export * from "./models/beacon";
export * from "./models/event";
export * from "./models/room";
export * from "./models/group";
export * from "./models/event-timeline";
export * from "./models/event-timeline-set";
export * from "./models/room-member";
Expand Down
100 changes: 0 additions & 100 deletions src/models/group.js

This file was deleted.

26 changes: 1 addition & 25 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ limitations under the License.
*/

import { EventType } from "../@types/event";
import { Group } from "../models/group";
import { Room } from "../models/room";
import { User } from "../models/user";
import { IEvent, MatrixEvent } from "../models/event";
import { Filter } from "../filter";
import { RoomSummary } from "../models/room-summary";
import { IMinimalEvent, IGroups, IRooms, ISyncResponse } from "../sync-accumulator";
import { IMinimalEvent, IRooms, ISyncResponse } from "../sync-accumulator";
import { IStartClientOpts } from "../client";

export interface ISavedSync {
nextBatch: string;
roomsData: IRooms;
groupsData: IGroups;
accountData: IMinimalEvent[];
}

Expand All @@ -53,28 +51,6 @@ export interface IStore {
*/
setSyncToken(token: string): void;

/**
* No-op.
* @param {Group} group
* @deprecated groups/communities never made it to the spec and support for them is being discontinued.
*/
storeGroup(group: Group): void;

/**
* No-op.
* @param {string} groupId
* @return {null}
* @deprecated groups/communities never made it to the spec and support for them is being discontinued.
*/
getGroup(groupId: string): Group | null;

/**
* No-op.
* @return {Array} An empty array.
* @deprecated groups/communities never made it to the spec and support for them is being discontinued.
*/
getGroups(): Group[];

/**
* No-op.
* @param {Room} room
Expand Down
6 changes: 1 addition & 5 deletions src/store/indexeddb-local-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ export class LocalIndexedDBStoreBackend implements IIndexedDBBackend {
this.syncAccumulator.accumulate({
next_batch: syncData.nextBatch,
rooms: syncData.roomsData,
groups: syncData.groupsData,
account_data: {
events: accountData,
},
Expand Down Expand Up @@ -405,21 +404,19 @@ export class LocalIndexedDBStoreBackend implements IIndexedDBBackend {
await Promise.all([
this.persistUserPresenceEvents(userTuples),
this.persistAccountData(syncData.accountData),
this.persistSyncData(syncData.nextBatch, syncData.roomsData, syncData.groupsData),
this.persistSyncData(syncData.nextBatch, syncData.roomsData),
]);
}

/**
* Persist rooms /sync data along with the next batch token.
* @param {string} nextBatch The next_batch /sync value.
* @param {Object} roomsData The 'rooms' /sync data from a SyncAccumulator
* @param {Object} groupsData The 'groups' /sync data from a SyncAccumulator
* @return {Promise} Resolves if the data was persisted.
*/
private persistSyncData(
nextBatch: string,
roomsData: ISyncResponse["rooms"],
groupsData: ISyncResponse["groups"],
): Promise<void> {
logger.log("Persisting sync data up to", nextBatch);
return utils.promiseTry<void>(() => {
Expand All @@ -429,7 +426,6 @@ export class LocalIndexedDBStoreBackend implements IIndexedDBBackend {
clobber: "-", // constant key so will always clobber
nextBatch,
roomsData,
groupsData,
}); // put == UPSERT
return txnAsPromise(txn).then();
});
Expand Down
30 changes: 0 additions & 30 deletions src/store/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ limitations under the License.
*/

import { EventType } from "../@types/event";
import { Group } from "../models/group";
import { Room } from "../models/room";
import { User } from "../models/user";
import { IEvent, MatrixEvent } from "../models/event";
Expand Down Expand Up @@ -53,7 +52,6 @@ export interface IOpts {
*/
export class MemoryStore implements IStore {
private rooms: Record<string, Room> = {}; // roomId: Room
private groups: Record<string, Group> = {}; // groupId: Group
private users: Record<string, User> = {}; // userId: User
private syncToken: string = null;
// userId: {
Expand Down Expand Up @@ -90,34 +88,6 @@ export class MemoryStore implements IStore {
this.syncToken = token;
}

/**
* Store the given room.
* @param {Group} group The group to be stored
* @deprecated groups/communities never made it to the spec and support for them is being discontinued.
*/
public storeGroup(group: Group) {
this.groups[group.groupId] = group;
}

/**
* Retrieve a group by its group ID.
* @param {string} groupId The group ID.
* @return {Group} The group or null.
* @deprecated groups/communities never made it to the spec and support for them is being discontinued.
*/
public getGroup(groupId: string): Group | null {
return this.groups[groupId] || null;
}

/**
* Retrieve all known groups.
* @return {Group[]} A list of groups, which may be empty.
* @deprecated groups/communities never made it to the spec and support for them is being discontinued.
*/
public getGroups(): Group[] {
return Object.values(this.groups);
}

/**
* Store the given room.
* @param {Room} room The room to be stored. All properties must be stored.
Expand Down
27 changes: 0 additions & 27 deletions src/store/stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ limitations under the License.
*/

import { EventType } from "../@types/event";
import { Group } from "../models/group";
import { Room } from "../models/room";
import { User } from "../models/user";
import { IEvent, MatrixEvent } from "../models/event";
Expand Down Expand Up @@ -58,32 +57,6 @@ export class StubStore implements IStore {
this.fromToken = token;
}

/**
* No-op.
* @param {Group} group
* @deprecated groups/communities never made it to the spec and support for them is being discontinued.
*/
public storeGroup(group: Group) {}

/**
* No-op.
* @param {string} groupId
* @return {null}
* @deprecated groups/communities never made it to the spec and support for them is being discontinued.
*/
public getGroup(groupId: string): Group | null {
return null;
}

/**
* No-op.
* @return {Array} An empty array.
* @deprecated groups/communities never made it to the spec and support for them is being discontinued.
*/
public getGroups(): Group[] {
return [];
}

/**
* No-op.
* @param {Room} room
Expand Down
50 changes: 0 additions & 50 deletions src/sync-accumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ interface IDeviceLists {
left: string[];
}

export interface IGroups {
[Category.Join]: object;
[Category.Invite]: object;
[Category.Leave]: object;
}

export interface ISyncResponse {
next_batch: string;
rooms: IRooms;
Expand All @@ -142,8 +136,6 @@ export interface ISyncResponse {
to_device?: IToDevice;
device_lists?: IDeviceLists;
device_one_time_keys_count?: Record<string, number>;

groups: IGroups; // unspecced
}
/* eslint-enable camelcase */

Expand Down Expand Up @@ -174,7 +166,6 @@ export interface ISyncData {
nextBatch: string;
accountData: IMinimalEvent[];
roomsData: IRooms;
groupsData: IGroups;
}

/**
Expand All @@ -197,13 +188,6 @@ export class SyncAccumulator {
// streaming from without losing events.
private nextBatch: string = null;

// { ('invite'|'join'|'leave'): $groupId: { ... sync 'group' data } }
private groups: Record<Category, object> = {
invite: {},
join: {},
leave: {},
};

/**
* @param {Object} opts
* @param {Number=} opts.maxTimelineEntries The ideal maximum number of
Expand All @@ -219,7 +203,6 @@ export class SyncAccumulator {

public accumulate(syncResponse: ISyncResponse, fromDatabase = false): void {
this.accumulateRooms(syncResponse, fromDatabase);
this.accumulateGroups(syncResponse);
this.accumulateAccountData(syncResponse);
this.nextBatch = syncResponse.next_batch;
}
Expand Down Expand Up @@ -505,38 +488,6 @@ export class SyncAccumulator {
}
}

/**
* Accumulate incremental /sync group data.
* @param {Object} syncResponse the complete /sync JSON
*/
private accumulateGroups(syncResponse: ISyncResponse): void {
if (!syncResponse.groups) {
return;
}
if (syncResponse.groups.invite) {
Object.keys(syncResponse.groups.invite).forEach((groupId) => {
this.accumulateGroup(groupId, Category.Invite, syncResponse.groups.invite[groupId]);
});
}
if (syncResponse.groups.join) {
Object.keys(syncResponse.groups.join).forEach((groupId) => {
this.accumulateGroup(groupId, Category.Join, syncResponse.groups.join[groupId]);
});
}
if (syncResponse.groups.leave) {
Object.keys(syncResponse.groups.leave).forEach((groupId) => {
this.accumulateGroup(groupId, Category.Leave, syncResponse.groups.leave[groupId]);
});
}
}

private accumulateGroup(groupId: string, category: Category, data: object): void {
for (const cat of [Category.Invite, Category.Leave, Category.Join]) {
delete this.groups[cat][groupId];
}
this.groups[category][groupId] = data;
}

/**
* Return everything under the 'rooms' key from a /sync response which
* represents all room data that should be stored. This should be paired
Expand Down Expand Up @@ -694,7 +645,6 @@ export class SyncAccumulator {
return {
nextBatch: this.nextBatch,
roomsData: data,
groupsData: this.groups,
accountData: accData,
};
}
Expand Down
Loading

0 comments on commit d0b9648

Please sign in to comment.