also update room list when encrypted events come in
This commit is contained in:
parent
5b04587722
commit
fb69688d47
2 changed files with 17 additions and 14 deletions
|
@ -168,6 +168,7 @@ export class Room extends EventEmitter {
|
||||||
}
|
}
|
||||||
const summaryChanges = this._summary.writeSync(
|
const summaryChanges = this._summary.writeSync(
|
||||||
roomResponse,
|
roomResponse,
|
||||||
|
entries,
|
||||||
membership,
|
membership,
|
||||||
isInitialSync, this._isTimelineOpen,
|
isInitialSync, this._isTimelineOpen,
|
||||||
txn);
|
txn);
|
||||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import {MEGOLM_ALGORITHM} from "../e2ee/common.js";
|
import {MEGOLM_ALGORITHM} from "../e2ee/common.js";
|
||||||
|
|
||||||
function applySyncResponse(data, roomResponse, membership, isInitialSync, isTimelineOpen, ownUserId) {
|
function applySyncResponse(data, roomResponse, timelineEntries, membership, isInitialSync, isTimelineOpen, ownUserId) {
|
||||||
if (roomResponse.summary) {
|
if (roomResponse.summary) {
|
||||||
data = updateSummary(data, roomResponse.summary);
|
data = updateSummary(data, roomResponse.summary);
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,12 @@ function applySyncResponse(data, roomResponse, membership, isInitialSync, isTime
|
||||||
if (roomResponse.state) {
|
if (roomResponse.state) {
|
||||||
data = roomResponse.state.events.reduce(processStateEvent, data);
|
data = roomResponse.state.events.reduce(processStateEvent, data);
|
||||||
}
|
}
|
||||||
const {timeline} = roomResponse;
|
if (timelineEntries.length) {
|
||||||
if (timeline && Array.isArray(timeline.events)) {
|
data = timelineEntries.reduce((data, entry) => {
|
||||||
data = timeline.events.reduce((data, event) => {
|
if (typeof entry.stateKey === "string") {
|
||||||
if (typeof event.state_key === "string") {
|
return processStateEvent(data, entry.event);
|
||||||
return processStateEvent(data, event);
|
|
||||||
} else {
|
} else {
|
||||||
return processTimelineEvent(data, event,
|
return processTimelineEvent(data, entry,
|
||||||
isInitialSync, isTimelineOpen, ownUserId);
|
isInitialSync, isTimelineOpen, ownUserId);
|
||||||
}
|
}
|
||||||
}, data);
|
}, data);
|
||||||
|
@ -91,17 +90,19 @@ function processStateEvent(data, event) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function processTimelineEvent(data, event, isInitialSync, isTimelineOpen, ownUserId) {
|
function processTimelineEvent(data, eventEntry, isInitialSync, isTimelineOpen, ownUserId) {
|
||||||
if (event.type === "m.room.message") {
|
if (eventEntry.eventType === "m.room.message") {
|
||||||
|
console.log("new message", eventEntry.timestamp, eventEntry.content?.body);
|
||||||
data = data.cloneIfNeeded();
|
data = data.cloneIfNeeded();
|
||||||
data.lastMessageTimestamp = event.origin_server_ts;
|
data.lastMessageTimestamp = eventEntry.timestamp;
|
||||||
if (!isInitialSync && event.sender !== ownUserId && !isTimelineOpen) {
|
if (!isInitialSync && eventEntry.sender !== ownUserId && !isTimelineOpen) {
|
||||||
|
console.log("also marking unread");
|
||||||
data.isUnread = true;
|
data.isUnread = true;
|
||||||
}
|
}
|
||||||
const {content} = event;
|
const {content} = eventEntry;
|
||||||
const body = content?.body;
|
const body = content?.body;
|
||||||
const msgtype = content?.msgtype;
|
const msgtype = content?.msgtype;
|
||||||
if (msgtype === "m.text") {
|
if (msgtype === "m.text" && !eventEntry.isEncrypted) {
|
||||||
data.lastMessageBody = body;
|
data.lastMessageBody = body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,12 +268,13 @@ export class RoomSummary {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeSync(roomResponse, membership, isInitialSync, isTimelineOpen, txn) {
|
writeSync(roomResponse, timelineEntries, membership, isInitialSync, isTimelineOpen, txn) {
|
||||||
// clear cloned flag, so cloneIfNeeded makes a copy and
|
// clear cloned flag, so cloneIfNeeded makes a copy and
|
||||||
// this._data is not modified if any field is changed.
|
// this._data is not modified if any field is changed.
|
||||||
this._data.cloned = false;
|
this._data.cloned = false;
|
||||||
const data = applySyncResponse(
|
const data = applySyncResponse(
|
||||||
this._data, roomResponse,
|
this._data, roomResponse,
|
||||||
|
timelineEntries,
|
||||||
membership,
|
membership,
|
||||||
isInitialSync, isTimelineOpen,
|
isInitialSync, isTimelineOpen,
|
||||||
this._ownUserId);
|
this._ownUserId);
|
||||||
|
|
Reference in a new issue