[polari/wip/carlosg/tracker: 406/445] chatView: Use new message type
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/carlosg/tracker: 406/445] chatView: Use new message type
- Date: Mon, 21 Jun 2021 22:04:10 +0000 (UTC)
commit b8b12390d4411d1bce53553a168fa56416df1139
Author: Florian Müllner <fmuellner gnome org>
Date: Mon Jul 24 21:44:04 2017 +0200
chatView: Use new message type
src/chatView.js | 74 +++++++++++++++++++++++++--------------------------------
1 file changed, 33 insertions(+), 41 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 9ef5851d..ffb4b425 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -573,23 +573,14 @@ const ChatView = GObject.registerClass({
_createMessage(source) {
if (source instanceof Tp.Message) {
- let [text] = source.to_text();
let [id, valid] = source.get_pending_message_id();
- return {
- nick: source.sender.alias,
- text,
- timestamp: source.get_sent_timestamp() ||
- source.get_received_timestamp(),
- messageType: source.get_message_type(),
- pendingId: valid ? id : undefined,
- };
+ let msg = Polari.Message.new_from_tp_message(source);
+ msg.pendingId = valid ? id : undefined;
+ return msg;
} else if (source instanceof Tpl.Event) {
- return {
- nick: source.sender.alias,
- text: source.message,
- timestamp: source.timestamp,
- messageType: source.get_message_type(),
- };
+ let msg = Polari.Message.new_from_tpl_event(source);
+ msg.pendingId = undefined;
+ return msg;
}
throw new Error(`Cannot create message from source ${source}`);
@@ -599,11 +590,12 @@ const ChatView = GObject.registerClass({
if (this._logWalker.is_end())
return this._pendingLogs.splice(0);
- let { nick, messageType: type } = this._pendingLogs[0];
+ let nick = this._pendingLogs[0].get_sender();
+ let isAction = this._pendingLogs[0].is_action();
let maxNum = this._pendingLogs.length - this._initialPending.length;
for (let i = 0; i < maxNum; i++) {
- if (this._pendingLogs[i].nick !== nick ||
- this._pendingLogs[i].messageType !== type)
+ if (this._pendingLogs[i].get_sender() !== nick ||
+ this._pendingLogs[i].is_action() !== isAction)
return this._pendingLogs.splice(i);
}
return [];
@@ -616,10 +608,10 @@ const ChatView = GObject.registerClass({
let numLogs = logs.length;
let pos;
for (pos = numLogs - pending.length; pos < numLogs; pos++) {
- if (logs[pos].nick === firstPending.nick &&
- logs[pos].text === firstPending.text &&
- logs[pos].timestamp === firstPending.timestamp &&
- logs[pos].messageType === firstPending.messageType)
+ if (logs[pos].get_sender() === firstPending.get_sender() &&
+ logs[pos].get_text() === firstPending.get_text() &&
+ logs[pos].is_action() === firstPending.is_action() &&
+ logs[pos].get_time().equal(firstPending.get_time()))
break;
}
// Remove entries that are also in pending (if any), then
@@ -1263,42 +1255,44 @@ const ChatView = GObject.registerClass({
let iter = this._view.buffer.get_end_iter();
this._insertMessage(iter, message, this._state);
- if (message.pendingId === undefined /* outgoing */ ||
- this._app.isRoomFocused(this._room) && this._pending.size === 0)
+ if (message.is_self() /* outgoing */ ||
+ (this._app.isRoomFocused(this._room) && this._pending.size === 0))
this._channel.ack_message_async(tpMessage, null);
else if (this._needsIndicator)
this._setIndicatorMark(this._view.buffer.get_end_iter());
}
_insertMessage(iter, message, state) {
- let isAction = message.messageType === Tp.ChannelTextMessageType.ACTION;
- let needsGap = message.nick !== state.lastNick || isAction;
- let highlight = this._room.should_highlight_message(
- message.nick, message.text);
-
- if (message.timestamp - TIMESTAMP_INTERVAL > state.lastTimestamp) {
+ let nick = message.get_sender();
+ let text = message.get_text();
+ let isAction = message.is_action();
+ let needsGap = nick !== state.lastNick || isAction;
+ let highlight = this._room.should_highlight_message(nick, text);
+ let timestamp = message.get_time().to_unix();
+
+ if (timestamp - TIMESTAMP_INTERVAL > state.lastTimestamp) {
let tags = [this._lookupTag('timestamp')];
if (needsGap)
tags.push(this._lookupTag('gap'));
needsGap = false;
this._insertWithTags(iter,
- `${this._formatTimestamp(message.timestamp)}\n`, tags);
+ `${this._formatTimestamp(timestamp)}\n`, tags);
}
- state.lastTimestamp = message.timestamp;
+ state.lastTimestamp = timestamp;
- this._updateMaxNickChars(message.nick.length);
+ this._updateMaxNickChars(nick.length);
let tags = [];
if (isAction) {
- message.text = `${message.nick} ${message.text}`;
+ text = `${nick} ${text}`;
state.lastNick = null;
tags.push(this._lookupTag('action'));
if (needsGap)
tags.push(this._lookupTag('gap'));
} else {
- if (state.lastNick !== message.nick) {
+ if (state.lastNick !== nick) {
let nickTags = [this._lookupTag('nick')];
- let nickTagName = this._getNickTagName(message.nick);
+ let nickTagName = this._getNickTagName(nick);
let nickTag = this._lookupTag(nickTagName);
let buffer = this._view.get_buffer();
@@ -1306,7 +1300,7 @@ const ChatView = GObject.registerClass({
nickTag = new ButtonTag({ name: nickTagName });
nickTag.connect('clicked', this._onNickTagClicked.bind(this));
- let status = this._userTracker.getNickRoomStatus(message.nick, this._room);
+ let status = this._userTracker.getNickRoomStatus(nick, this._room);
this._updateNickTag(nickTag, status);
buffer.get_tag_table().add(nickTag);
@@ -1323,10 +1317,10 @@ const ChatView = GObject.registerClass({
if (needsGap)
nickTags.push(this._lookupTag('gap'));
- this._insertWithTags(iter, message.nick, nickTags);
+ this._insertWithTags(iter, nick, nickTags);
buffer.insert(iter, '\t', -1);
}
- state.lastNick = message.nick;
+ state.lastNick = nick;
tags.push(this._lookupTag('message'));
}
@@ -1336,8 +1330,6 @@ const ChatView = GObject.registerClass({
let params = this._room.account.dup_parameters_vardict().deep_unpack();
let server = params.server.deep_unpack();
- let { text } = message;
-
// mask identify passwords in private chats
if (this._room.type === Tp.HandleType.CONTACT) {
let [isIdentify, command_, username_, password] =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]