[polari] app: Use bool instead of time in join-room/message-user
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] app: Use bool instead of time in join-room/message-user
- Date: Sat, 14 Aug 2021 20:58:53 +0000 (UTC)
commit 0ad18e4508b6641409f084d7890448608f5db3d0
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Aug 14 22:04:38 2021 +0200
app: Use bool instead of time in join-room/message-user
The time parameter in the 'join-room' and 'message-user' actions
is really about whether we should switch to the room or not.
Make this explicit by changing the parameter to a 'present' boolean.
This is not just easier, it also removes the bulk of calls to
`gtk_get_current_event()`, which is gone in GTK4.
https://gitlab.gnome.org/GNOME/polari/-/merge_requests/212
src/application.js | 23 ++++++++++-------------
src/initialSetup.js | 5 +----
src/ircParser.js | 12 ++++++------
src/joinDialog.js | 5 ++---
src/roomManager.js | 17 ++++++++---------
src/telepathyClient.js | 12 ++++++------
src/userList.js | 5 ++---
src/userTracker.js | 5 ++---
src/utils.js | 11 -----------
9 files changed, 37 insertions(+), 58 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 296b6439..817a051e 100644
--- a/src/application.js
+++ b/src/application.js
@@ -209,11 +209,11 @@ export default GObject.registerClass({
}, {
name: 'join-room',
activate: this._onJoinRoom.bind(this),
- parameter_type: GLib.VariantType.new('(ssu)'),
+ parameter_type: GLib.VariantType.new('(ssb)'),
}, {
name: 'message-user',
activate: this._onMessageUser.bind(this),
- parameter_type: GLib.VariantType.new('(sssu)'),
+ parameter_type: GLib.VariantType.new('(sssb)'),
}, {
name: 'leave-room',
parameter_type: GLib.VariantType.new('(ss)'),
@@ -440,15 +440,14 @@ export default GObject.registerClass({
vfunc_open(files) {
this.activate();
- let time = Utils.getTpEventTime();
let uris = files.map(f => f.get_uri());
this._accountsMonitor.prepare(() => {
- this._openURIs(uris, time);
+ this._openURIs(uris);
});
}
- _openURIs(uris, time) {
+ _openURIs(uris) {
let map = {};
this._accountsMonitor.visibleAccounts.forEach(a => {
@@ -480,7 +479,7 @@ export default GObject.registerClass({
accountPath = account.get_object_path();
}
- joinAction.activate(new GLib.Variant('(ssu)', [accountPath, `#${room}`, time]));
+ joinAction.activate(new GLib.Variant('(ssb)', [accountPath, `#${room}`, true]));
});
}
@@ -573,21 +572,19 @@ export default GObject.registerClass({
this.active_window.showJoinRoomDialog();
}
- _maybePresent(time) {
- let [present] = Tp.user_action_time_should_present(time);
-
+ _maybePresent(present) {
if (!this.active_window || present)
this.activate();
}
_onJoinRoom(action, parameter) {
- let [accountPath_, channelName_, time] = parameter.deep_unpack();
- this._maybePresent(time);
+ let [accountPath_, channelName_, present] = parameter.deep_unpack();
+ this._maybePresent(present);
}
_onMessageUser(action, parameter) {
- let [accountPath_, contactName_, msg_, time] = parameter.deep_unpack();
- this._maybePresent(time);
+ let [accountPath_, contactName_, msg_, present] = parameter.deep_unpack();
+ this._maybePresent(present);
}
_trackNominalNick(account) {
diff --git a/src/initialSetup.js b/src/initialSetup.js
index 0b68a049..a1eda74c 100644
--- a/src/initialSetup.js
+++ b/src/initialSetup.js
@@ -4,8 +4,6 @@ import GObject from 'gi://GObject';
import Gtk from 'gi://Gtk';
import Tp from 'gi://TelepathyGLib';
-import * as Utils from './utils.js';
-
Gio._promisify(Tp.Account.prototype, 'remove_async', 'remove_finish');
const SetupPage = {
@@ -130,14 +128,13 @@ export default GObject.registerClass({
let toJoinRooms = this._serverRoomList.selectedRooms;
let accountPath = this._currentAccount.get_object_path();
- let time = Utils.getTpEventTime();
toJoinRooms.forEach(room => {
if (room[0] !== '#')
room = `#${room}`;
let app = Gio.Application.get_default();
let action = app.lookup_action('join-room');
- action.activate(GLib.Variant.new('(ssu)', [accountPath, room, time]));
+ action.activate(GLib.Variant.new('(ssb)', [accountPath, room, true]));
});
}
});
diff --git a/src/ircParser.js b/src/ircParser.js
index d2e60860..f5f368a5 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -133,10 +133,10 @@ export default class IrcParser {
let { account } = this._room;
let app = Gio.Application.get_default();
let action = app.lookup_action('join-room');
- action.activate(GLib.Variant.new('(ssu)', [
+ action.activate(GLib.Variant.new('(ssb)', [
account.get_object_path(),
room,
- Utils.getTpEventTime(),
+ true,
]));
break;
}
@@ -182,11 +182,11 @@ export default class IrcParser {
let app = Gio.Application.get_default();
let action = app.lookup_action('message-user');
- action.activate(GLib.Variant.new('(sssu)', [
+ action.activate(GLib.Variant.new('(sssb)', [
account.get_object_path(),
nick,
message,
- Tp.USER_ACTION_TIME_NOT_USER_ACTION,
+ false,
]));
break;
}
@@ -239,11 +239,11 @@ export default class IrcParser {
let app = Gio.Application.get_default();
let action = app.lookup_action('message-user');
- action.activate(GLib.Variant.new('(sssu)', [
+ action.activate(GLib.Variant.new('(sssb)', [
account.get_object_path(),
nick,
'',
- Utils.getTpEventTime(),
+ true,
]));
break;
}
diff --git a/src/joinDialog.js b/src/joinDialog.js
index 303020f4..40e97873 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -5,7 +5,6 @@ import GObject from 'gi://GObject';
import Gtk from 'gi://Gtk';
import AccountsMonitor from './accountsMonitor.js';
-import * as Utils from './utils.js';
const DialogPage = {
MAIN: 0,
@@ -173,10 +172,10 @@ export default GObject.registerClass({
let app = Gio.Application.get_default();
let action = app.lookup_action('join-room');
- action.activate(GLib.Variant.new('(ssu)', [
+ action.activate(GLib.Variant.new('(ssb)', [
account.get_object_path(),
room,
- Utils.getTpEventTime(),
+ true,
]));
});
}
diff --git a/src/roomManager.js b/src/roomManager.js
index 15608a84..fa8bf5dd 100644
--- a/src/roomManager.js
+++ b/src/roomManager.js
@@ -79,19 +79,19 @@ export default class RoomManager {
}
_onJoinActivated(action, parameter) {
- let [accountPath, channelName, time] = parameter.deep_unpack();
+ let [accountPath, channelName, present] = parameter.deep_unpack();
this._addSavedChannel(accountPath, channelName);
this._accountsMonitor.prepare(() => {
- this._ensureRoom(accountPath, channelName, Tp.HandleType.ROOM, time);
+ this._ensureRoom(accountPath, channelName, Tp.HandleType.ROOM, present);
});
}
_onQueryActivated(action, parameter) {
- let [accountPath, channelName, , time] = parameter.deep_unpack();
+ let [accountPath, channelName, , present] = parameter.deep_unpack();
this._accountsMonitor.prepare(() => {
- this._ensureRoom(accountPath, channelName, Tp.HandleType.CONTACT, time);
+ this._ensureRoom(accountPath, channelName, Tp.HandleType.CONTACT, present);
});
}
@@ -108,7 +108,7 @@ export default class RoomManager {
for (let prop in c)
c[prop] = c[prop].deep_unpack();
if (!accountPath || c.account === accountPath)
- this._ensureRoom(c.account, c.channel, Tp.HandleType.ROOM, 0);
+ this._ensureRoom(c.account, c.channel, Tp.HandleType.ROOM, false);
});
this.emit('rooms-loaded');
}
@@ -159,7 +159,7 @@ export default class RoomManager {
new GLib.Variant('aa{sv}', channels));
}
- _ensureRoom(accountPath, channelName, type, time) {
+ _ensureRoom(accountPath, channelName, type, present) {
let account = this._accountsMonitor.lookupAccount(accountPath);
if (!account) {
@@ -182,20 +182,19 @@ export default class RoomManager {
this.emit('room-added', room);
}
- let [present] = Tp.user_action_time_should_present(time);
if (present && this._app.active_window)
this._app.active_window.active_room = room;
return room;
}
- ensureRoomForChannel(channel, time) {
+ ensureRoomForChannel(channel, present) {
let accountPath = channel.connection.get_account().object_path;
let targetContact = channel.target_contact;
let channelName = targetContact
? targetContact.alias : channel.identifier;
let [, handleType] = channel.get_handle();
- let room = this._ensureRoom(accountPath, channelName, handleType, time);
+ let room = this._ensureRoom(accountPath, channelName, handleType, present);
room.channel = channel;
}
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index 333f93d1..aca5ec7f 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -448,7 +448,7 @@ class TelepathyClient extends Tp.BaseClient {
}
async _onQueryActivated(action, parameter) {
- let [accountPath, channelName, message, time_] = parameter.deep_unpack();
+ let [accountPath, channelName, message, present_] = parameter.deep_unpack();
let account = this._accountsMonitor.lookupAccount(accountPath);
if (!account || !account.enabled)
@@ -606,7 +606,7 @@ class TelepathyClient extends Tp.BaseClient {
channel.connect('pending-message-removed',
this._onPendingMessageRemoved.bind(this));
- this._roomManager.ensureRoomForChannel(channel, 0);
+ this._roomManager.ensureRoomForChannel(channel, false);
});
}
@@ -623,7 +623,7 @@ class TelepathyClient extends Tp.BaseClient {
if (present)
this._app.activate();
- this._roomManager.ensureRoomForChannel(channel, time);
+ this._roomManager.ensureRoomForChannel(channel, present);
// channel.join_async('', null);
});
}
@@ -644,16 +644,16 @@ class TelepathyClient extends Tp.BaseClient {
let params = [
room.account.object_path,
room.channel_name,
- Utils.getTpEventTime(),
+ true,
];
let actionName, paramFormat;
if (room.type === Tp.HandleType.ROOM) {
actionName = 'app.join-room';
- paramFormat = '(ssu)';
+ paramFormat = '(ssb)';
} else {
actionName = 'app.message-user';
- paramFormat = '(sssu)';
+ paramFormat = '(sssb)';
params.splice(2, 0, '');
}
diff --git a/src/userList.js b/src/userList.js
index 56dab649..fefc31ee 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -289,12 +289,11 @@ export const UserDetails = GObject.registerClass({
let app = Gio.Application.get_default();
let action = app.lookup_action('message-user');
- let time = Gtk.get_current_event().get_time();
- action.activate(GLib.Variant.new('(sssu)', [
+ action.activate(GLib.Variant.new('(sssb)', [
account.get_object_path(),
this._user.alias,
'',
- time,
+ true,
]));
}
diff --git a/src/userTracker.js b/src/userTracker.js
index ec4a25fa..6b572ceb 100644
--- a/src/userTracker.js
+++ b/src/userTracker.js
@@ -6,7 +6,6 @@ import Tp from 'gi://TelepathyGLib';
import AccountsMonitor from './accountsMonitor.js';
import RoomManager from './roomManager.js';
-import * as Utils from './utils.js';
export default class UserStatusMonitor {
static getDefault() {
@@ -371,10 +370,10 @@ const UserTracker = GObject.registerClass({
notification.set_title(_('User is online'));
vprintf(notification.set_body(_('User %s is now online.'), member.alias));
- let param = GLib.Variant.new('(ssu)', [
+ let param = GLib.Variant.new('(ssb)', [
this._account.get_object_path(),
room.channel_name,
- Utils.getTpEventTime(),
+ true,
]);
notification.set_default_action_and_target('app.join-room', param);
diff --git a/src/utils.js b/src/utils.js
index d81c51e8..32fad48f 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -26,7 +26,6 @@ import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import Gtk from 'gi://Gtk';
import Secret from 'gi://Secret';
-import Tp from 'gi://TelepathyGLib';
import * as AppNotifications from './appNotifications.js';
@@ -173,16 +172,6 @@ export function needsOnetimeAction(name) {
return true;
}
-/**
- * @returns {number}
- */
-export function getTpEventTime() {
- let time = Gtk.get_current_event_time();
- if (time === 0)
- return GLib.MAXUINT32;
- return Tp.user_action_time_from_x11(time);
-}
-
/**
* @param {Tp.Account} account - the account
* @param {string} password - the password
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]