Skip to content

Commit

Permalink
feat: set isOnline status with user presence data
Browse files Browse the repository at this point in the history
  • Loading branch information
domw30 committed Oct 16, 2023
1 parent d61983e commit cb025dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib/chat/matrix-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export class MatrixClient implements IChatClient {
firstName: user?.displayName,
lastName: '',
profileId: '',
isOnline: user?.presence === 'online',
isOnline: false,
profileImage: user?.avatarUrl,
lastSeenAt: '',
};
Expand Down
19 changes: 13 additions & 6 deletions src/store/channels-list/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,26 @@ export function* mapToZeroUsers(channels: any[]) {
return;
}

export function* updateOtherMembersLastSeenAt(conversations) {
export function* updateUserPresence(conversations) {
if (!featureFlags.enableMatrix) {
return;
}

const chatClient = yield call(chat.get);
for (let conversation of conversations) {
const matrixId = conversation?.otherMembers?.[0]?.matrixId;
const { isOneOnOne, otherMembers } = conversation;
const matrixId = otherMembers?.[0]?.matrixId;

if (conversation.isOneOnOne && matrixId) {
if (isOneOnOne && matrixId) {
const presenceData = yield call([chatClient, chatClient.getUserPresence], matrixId);
if (presenceData && presenceData.lastSeenAt) {
conversation.otherMembers[0].lastSeenAt = presenceData.lastSeenAt;

if (presenceData) {
if (presenceData.lastSeenAt) {
conversation.otherMembers[0].lastSeenAt = presenceData.lastSeenAt;
}
if (presenceData.isOnline) {
conversation.otherMembers[0].isOnline = presenceData.isOnline;
}
}
}
}
Expand Down Expand Up @@ -113,7 +120,7 @@ export function* fetchConversations() {
chatClient.getConversations,
]);
yield call(mapToZeroUsers, conversations);
yield call(updateOtherMembersLastSeenAt, conversations);
yield call(updateUserPresence, conversations);

const existingConversationList = yield select(denormalizeConversations);
const optimisticConversationIds = existingConversationList
Expand Down

0 comments on commit cb025dd

Please sign in to comment.