Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hacky custom status feature #2350

Merged
merged 1 commit into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5063,26 +5063,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
return getHttpUriForMxc(this.baseUrl, mxcUrl, width, height, resizeMethod, allowDirectLinks);
}

/**
* Sets a new status message for the user. The message may be null/falsey
* to clear the message.
* @param {string} newMessage The new message to set.
* @return {Promise} Resolves: to nothing
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
public _unstable_setStatusMessage(newMessage: string): Promise<void> { // eslint-disable-line
const type = "im.vector.user_status";
return Promise.all(this.getRooms().map(async (room) => {
const isJoined = room.getMyMembership() === "join";
const looksLikeDm = room.getInvitedAndJoinedMemberCount() === 2;
if (!isJoined || !looksLikeDm) return;
// Check power level separately as it's a bit more expensive.
const maySend = room.currentState.mayClientSendStateEvent(type, this);
if (!maySend) return;
await this.sendStateEvent(room.roomId, type, { status: newMessage }, this.getUserId());
})).then(); // .then to fix return type
}

/**
* @param {Object} opts Options to apply
* @param {string} opts.presence One of "online", "offline" or "unavailable"
Expand Down
21 changes: 0 additions & 21 deletions src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export enum UserEvent {
Presence = "User.presence",
CurrentlyActive = "User.currentlyActive",
LastPresenceTs = "User.lastPresenceTs",
/* @deprecated */
_UnstableStatusMessage = "User.unstable_statusMessage",
}

export type UserEventHandlerMap = {
Expand All @@ -37,7 +35,6 @@ export type UserEventHandlerMap = {
[UserEvent.Presence]: (event: MatrixEvent | undefined, user: User) => void;
[UserEvent.CurrentlyActive]: (event: MatrixEvent | undefined, user: User) => void;
[UserEvent.LastPresenceTs]: (event: MatrixEvent | undefined, user: User) => void;
[UserEvent._UnstableStatusMessage]: (user: User) => void;
};

export class User extends TypedEventEmitter<UserEvent, UserEventHandlerMap> {
Expand All @@ -59,8 +56,6 @@ export class User extends TypedEventEmitter<UserEvent, UserEventHandlerMap> {
presence: null,
profile: null,
};
// eslint-disable-next-line camelcase
public unstable_statusMessage = "";

/**
* Construct a new User. A User must have an ID and can optionally have extra
Expand All @@ -81,9 +76,6 @@ export class User extends TypedEventEmitter<UserEvent, UserEventHandlerMap> {
* when a user was last active.
* @prop {Boolean} currentlyActive Whether we should consider lastActiveAgo to be
* an approximation and that the user should be seen as active 'now'
* @prop {string} unstable_statusMessage The status message for the user, if known. This is
* different from the presenceStatusMsg in that this is not tied to
* the user's presence, and should be represented differently.
* @prop {Object} events The events describing this user.
* @prop {MatrixEvent} events.presence The m.presence event for this user.
*/
Expand Down Expand Up @@ -219,19 +211,6 @@ export class User extends TypedEventEmitter<UserEvent, UserEventHandlerMap> {
public getLastActiveTs(): number {
return this.lastPresenceTs - this.lastActiveAgo;
}

/**
* Manually set the user's status message.
* @param {MatrixEvent} event The <code>im.vector.user_status</code> event.
* @fires module:client~MatrixClient#event:"User.unstable_statusMessage"
*/
// eslint-disable-next-line
public unstable_updateStatusMessage(event: MatrixEvent): void {
if (!event.getContent()) this.unstable_statusMessage = "";
else this.unstable_statusMessage = event.getContent()["status"];
this.updateModifiedTime();
this.emit(UserEvent._UnstableStatusMessage, this);
}
}

/**
Expand Down
10 changes: 0 additions & 10 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1295,16 +1295,6 @@ export class SyncApi {
if (e.isState() && e.getType() == "m.room.encryption" && this.opts.crypto) {
await this.opts.crypto.onCryptoEvent(e);
}
if (e.isState() && e.getType() === "im.vector.user_status") {
let user = client.store.getUser(e.getStateKey());
if (user) {
user.unstable_updateStatusMessage(e);
} else {
user = createNewUser(client, e.getStateKey());
user.unstable_updateStatusMessage(e);
client.store.storeUser(user);
}
}
};

await utils.promiseMapSeries(stateEvents, processRoomEvent);
Expand Down