Compare commits

...

11 commits

Author SHA1 Message Date
Bruno Windels
1572934195 remove accidental space 2022-01-14 19:12:05 +01:00
RMidhunSuresh
c3784d406b Move getter to this PR 2022-01-14 19:27:14 +05:30
RMidhunSuresh
22356bee51 No need to git add . whole expression 2022-01-14 19:27:14 +05:30
RMidhunSuresh
72691eeb9d Delete ghost .js file 2022-01-14 19:27:14 +05:30
RMidhunSuresh
6a556d73ad Always include reply content 2022-01-14 19:27:14 +05:30
RMidhunSuresh
f44fa775de Move threading relation type const to relations.js 2022-01-14 19:27:14 +05:30
RMidhunSuresh
38781db858 Implement quote replies to thread 2022-01-14 19:27:14 +05:30
RMidhunSuresh
825bec80b0 Prefer reply over thread when both are available 2022-01-14 19:27:14 +05:30
RMidhunSuresh
78c79b148a Refactor code 2022-01-14 19:27:14 +05:30
RMidhunSuresh
9eeeea47d9 Treat replies to thread as threaded message 2022-01-14 19:27:14 +05:30
RMidhunSuresh
337d0726ce WIP 2022-01-14 19:27:14 +05:30
4 changed files with 28 additions and 8 deletions

View file

@ -16,9 +16,9 @@ limitations under the License.
import {BaseEntry} from "./BaseEntry"; import {BaseEntry} from "./BaseEntry";
import {REDACTION_TYPE} from "../../common.js"; import {REDACTION_TYPE} from "../../common.js";
import {createAnnotation, ANNOTATION_RELATION_TYPE, getRelationFromContent} from "../relations.js"; import {createAnnotation, ANNOTATION_RELATION_TYPE, THREADING_RELATION_TYPE, getRelationFromContent} from "../relations.js";
import {PendingAnnotation} from "../PendingAnnotation.js"; import {PendingAnnotation} from "../PendingAnnotation.js";
import {createReplyContent} from "./reply.js" import {createReplyContent} from "./reply.js";
/** Deals mainly with local echo for relations and redactions, /** Deals mainly with local echo for relations and redactions,
* so it is shared between PendingEventEntry and EventEntry */ * so it is shared between PendingEventEntry and EventEntry */
@ -32,7 +32,11 @@ export class BaseEventEntry extends BaseEntry {
} }
get isReply() { get isReply() {
return !!this.relation?.["m.in_reply_to"]; return !!this.relation?.["m.in_reply_to"] || this.isThread;
}
get isThread() {
return this.relation?.["rel_type"] === THREADING_RELATION_TYPE;
} }
get isRedacting() { get isRedacting() {

View file

@ -124,6 +124,13 @@ export class EventEntry extends BaseEventEntry {
return getRelatedEventId(this.event); return getRelatedEventId(this.event);
} }
get threadEventId() {
if (this.isThread) {
return this.relation?.event_id;
}
return null;
}
get isRedacted() { get isRedacted() {
return super.isRedacted || isRedacted(this._eventEntry.event); return super.isRedacted || isRedacted(this._eventEntry.event);
} }

View file

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {THREADING_RELATION_TYPE} from "../relations.js";
function htmlEscape(string) { function htmlEscape(string) {
return string.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); return string.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
} }
@ -36,8 +38,8 @@ function fallbackPrefix(msgtype) {
return msgtype === "m.emote" ? "* " : ""; return msgtype === "m.emote" ? "* " : "";
} }
function _createReplyContent(targetId, msgtype, body, formattedBody) { function _createReplyContent(targetId, msgtype, body, formattedBody, threadId) {
return { const reply = {
msgtype, msgtype,
body, body,
"format": "org.matrix.custom.html", "format": "org.matrix.custom.html",
@ -48,10 +50,16 @@ function _createReplyContent(targetId, msgtype, body, formattedBody) {
} }
} }
}; };
if (threadId) {
Object.assign(reply["m.relates_to"], {
rel_type: THREADING_RELATION_TYPE,
event_id: threadId,
});
}
return reply;
} }
export function createReplyContent(entry, msgtype, body) { export function createReplyContent(entry, msgtype, body) {
// TODO check for absense of sender / body / msgtype / etc?
const nonTextual = fallbackForNonTextualMessage(entry.content.msgtype); const nonTextual = fallbackForNonTextualMessage(entry.content.msgtype);
const prefix = fallbackPrefix(entry.content.msgtype); const prefix = fallbackPrefix(entry.content.msgtype);
const sender = entry.sender; const sender = entry.sender;
@ -70,5 +78,5 @@ export function createReplyContent(entry, msgtype, body) {
const newBody = plainFallback + '\n\n' + body; const newBody = plainFallback + '\n\n' + body;
const newFormattedBody = formattedFallback + htmlEscape(body); const newFormattedBody = formattedFallback + htmlEscape(body);
return _createReplyContent(entry.id, msgtype, newBody, newFormattedBody); return _createReplyContent(entry.id, msgtype, newBody, newFormattedBody, entry.threadEventId);
} }

View file

@ -18,6 +18,7 @@ import {REDACTION_TYPE} from "../common.js";
export const REACTION_TYPE = "m.reaction"; export const REACTION_TYPE = "m.reaction";
export const ANNOTATION_RELATION_TYPE = "m.annotation"; export const ANNOTATION_RELATION_TYPE = "m.annotation";
export const THREADING_RELATION_TYPE = "io.element.thread";
export function createAnnotation(targetId, key) { export function createAnnotation(targetId, key) {
return { return {
@ -30,7 +31,7 @@ export function createAnnotation(targetId, key) {
} }
export function getRelationTarget(relation) { export function getRelationTarget(relation) {
return relation.event_id || relation["m.in_reply_to"]?.event_id return relation["m.in_reply_to"]?.event_id || relation.event_id;
} }
export function setRelationTarget(relation, target) { export function setRelationTarget(relation, target) {