[core] GOWS - add "merge" flag
This commit is contained in:
1 parent
f8e52959a4
commit
81083e7f82
3 files changed
+173
-9
No files matched your search
@@ -9221,6 +9221,7 @@ export namespace messages {
|
||||
filters?: MessageFilters;
|
||||
pagination?: Pagination;
|
||||
sortBy?: SortBy;
|
||||
merge?: OptionalBool;
|
||||
}) {
|
||||
super();
|
||||
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls);
|
||||
@@ -9237,6 +9238,9 @@ export namespace messages {
|
||||
if ("sortBy" in data && data.sortBy != undefined) {
|
||||
this.sortBy = data.sortBy;
|
||||
}
|
||||
if ("merge" in data && data.merge != undefined) {
|
||||
this.merge = data.merge;
|
||||
}
|
||||
}
|
||||
}
|
||||
get session() {
|
||||
@@ -9275,11 +9279,21 @@ export namespace messages {
|
||||
get has_sortBy() {
|
||||
return pb_1.Message.getField(this, 4) != null;
|
||||
}
|
||||
get merge() {
|
||||
return pb_1.Message.getWrapperField(this, OptionalBool, 5) as OptionalBool;
|
||||
}
|
||||
set merge(value: OptionalBool) {
|
||||
pb_1.Message.setWrapperField(this, 5, value);
|
||||
}
|
||||
get has_merge() {
|
||||
return pb_1.Message.getField(this, 5) != null;
|
||||
}
|
||||
static fromObject(data: {
|
||||
session?: ReturnType<typeof Session.prototype.toObject>;
|
||||
filters?: ReturnType<typeof MessageFilters.prototype.toObject>;
|
||||
pagination?: ReturnType<typeof Pagination.prototype.toObject>;
|
||||
sortBy?: ReturnType<typeof SortBy.prototype.toObject>;
|
||||
merge?: ReturnType<typeof OptionalBool.prototype.toObject>;
|
||||
}): GetMessagesRequest {
|
||||
const message = new GetMessagesRequest({});
|
||||
if (data.session != null) {
|
||||
@@ -9294,6 +9308,9 @@ export namespace messages {
|
||||
if (data.sortBy != null) {
|
||||
message.sortBy = SortBy.fromObject(data.sortBy);
|
||||
}
|
||||
if (data.merge != null) {
|
||||
message.merge = OptionalBool.fromObject(data.merge);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
toObject() {
|
||||
@@ -9302,6 +9319,7 @@ export namespace messages {
|
||||
filters?: ReturnType<typeof MessageFilters.prototype.toObject>;
|
||||
pagination?: ReturnType<typeof Pagination.prototype.toObject>;
|
||||
sortBy?: ReturnType<typeof SortBy.prototype.toObject>;
|
||||
merge?: ReturnType<typeof OptionalBool.prototype.toObject>;
|
||||
} = {};
|
||||
if (this.session != null) {
|
||||
data.session = this.session.toObject();
|
||||
@@ -9315,6 +9333,9 @@ export namespace messages {
|
||||
if (this.sortBy != null) {
|
||||
data.sortBy = this.sortBy.toObject();
|
||||
}
|
||||
if (this.merge != null) {
|
||||
data.merge = this.merge.toObject();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
serialize(): Uint8Array;
|
||||
@@ -9329,6 +9350,8 @@ export namespace messages {
|
||||
writer.writeMessage(3, this.pagination, () => this.pagination.serialize(writer));
|
||||
if (this.has_sortBy)
|
||||
writer.writeMessage(4, this.sortBy, () => this.sortBy.serialize(writer));
|
||||
if (this.has_merge)
|
||||
writer.writeMessage(5, this.merge, () => this.merge.serialize(writer));
|
||||
if (!w)
|
||||
return writer.getResultBuffer();
|
||||
}
|
||||
@@ -9350,6 +9373,9 @@ export namespace messages {
|
||||
case 4:
|
||||
reader.readMessage(message.sortBy, () => message.sortBy = SortBy.deserialize(reader));
|
||||
break;
|
||||
case 5:
|
||||
reader.readMessage(message.merge, () => message.merge = OptionalBool.deserialize(reader));
|
||||
break;
|
||||
default: reader.skipField();
|
||||
}
|
||||
}
|
||||
@@ -9697,6 +9723,7 @@ export namespace messages {
|
||||
sortBy?: SortBy;
|
||||
pagination?: Pagination;
|
||||
filter?: ChatFilter;
|
||||
merge?: OptionalBool;
|
||||
}) {
|
||||
super();
|
||||
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls);
|
||||
@@ -9713,6 +9740,9 @@ export namespace messages {
|
||||
if ("filter" in data && data.filter != undefined) {
|
||||
this.filter = data.filter;
|
||||
}
|
||||
if ("merge" in data && data.merge != undefined) {
|
||||
this.merge = data.merge;
|
||||
}
|
||||
}
|
||||
}
|
||||
get session() {
|
||||
@@ -9751,11 +9781,21 @@ export namespace messages {
|
||||
get has_filter() {
|
||||
return pb_1.Message.getField(this, 4) != null;
|
||||
}
|
||||
get merge() {
|
||||
return pb_1.Message.getWrapperField(this, OptionalBool, 5) as OptionalBool;
|
||||
}
|
||||
set merge(value: OptionalBool) {
|
||||
pb_1.Message.setWrapperField(this, 5, value);
|
||||
}
|
||||
get has_merge() {
|
||||
return pb_1.Message.getField(this, 5) != null;
|
||||
}
|
||||
static fromObject(data: {
|
||||
session?: ReturnType<typeof Session.prototype.toObject>;
|
||||
sortBy?: ReturnType<typeof SortBy.prototype.toObject>;
|
||||
pagination?: ReturnType<typeof Pagination.prototype.toObject>;
|
||||
filter?: ReturnType<typeof ChatFilter.prototype.toObject>;
|
||||
merge?: ReturnType<typeof OptionalBool.prototype.toObject>;
|
||||
}): GetChatsRequest {
|
||||
const message = new GetChatsRequest({});
|
||||
if (data.session != null) {
|
||||
@@ -9770,6 +9810,9 @@ export namespace messages {
|
||||
if (data.filter != null) {
|
||||
message.filter = ChatFilter.fromObject(data.filter);
|
||||
}
|
||||
if (data.merge != null) {
|
||||
message.merge = OptionalBool.fromObject(data.merge);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
toObject() {
|
||||
@@ -9778,6 +9821,7 @@ export namespace messages {
|
||||
sortBy?: ReturnType<typeof SortBy.prototype.toObject>;
|
||||
pagination?: ReturnType<typeof Pagination.prototype.toObject>;
|
||||
filter?: ReturnType<typeof ChatFilter.prototype.toObject>;
|
||||
merge?: ReturnType<typeof OptionalBool.prototype.toObject>;
|
||||
} = {};
|
||||
if (this.session != null) {
|
||||
data.session = this.session.toObject();
|
||||
@@ -9791,6 +9835,9 @@ export namespace messages {
|
||||
if (this.filter != null) {
|
||||
data.filter = this.filter.toObject();
|
||||
}
|
||||
if (this.merge != null) {
|
||||
data.merge = this.merge.toObject();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
serialize(): Uint8Array;
|
||||
@@ -9805,6 +9852,8 @@ export namespace messages {
|
||||
writer.writeMessage(3, this.pagination, () => this.pagination.serialize(writer));
|
||||
if (this.has_filter)
|
||||
writer.writeMessage(4, this.filter, () => this.filter.serialize(writer));
|
||||
if (this.has_merge)
|
||||
writer.writeMessage(5, this.merge, () => this.merge.serialize(writer));
|
||||
if (!w)
|
||||
return writer.getResultBuffer();
|
||||
}
|
||||
@@ -9826,6 +9875,9 @@ export namespace messages {
|
||||
case 4:
|
||||
reader.readMessage(message.filter, () => message.filter = ChatFilter.deserialize(reader));
|
||||
break;
|
||||
case 5:
|
||||
reader.readMessage(message.merge, () => message.merge = OptionalBool.deserialize(reader));
|
||||
break;
|
||||
default: reader.skipField();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19131,7 +19131,8 @@ proto.messages.GetMessagesRequest.toObject = function(includeInstance, msg) {
|
||||
session: (f = msg.getSession()) && proto.messages.Session.toObject(includeInstance, f),
|
||||
filters: (f = msg.getFilters()) && proto.messages.MessageFilters.toObject(includeInstance, f),
|
||||
pagination: (f = msg.getPagination()) && proto.messages.Pagination.toObject(includeInstance, f),
|
||||
sortby: (f = msg.getSortby()) && proto.messages.SortBy.toObject(includeInstance, f)
|
||||
sortby: (f = msg.getSortby()) && proto.messages.SortBy.toObject(includeInstance, f),
|
||||
merge: (f = msg.getMerge()) && proto.messages.OptionalBool.toObject(includeInstance, f)
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
@@ -19188,6 +19189,11 @@ proto.messages.GetMessagesRequest.deserializeBinaryFromReader = function(msg, re
|
||||
reader.readMessage(value,proto.messages.SortBy.deserializeBinaryFromReader);
|
||||
msg.setSortby(value);
|
||||
break;
|
||||
case 5:
|
||||
var value = new proto.messages.OptionalBool;
|
||||
reader.readMessage(value,proto.messages.OptionalBool.deserializeBinaryFromReader);
|
||||
msg.setMerge(value);
|
||||
break;
|
||||
default:
|
||||
reader.skipField();
|
||||
break;
|
||||
@@ -19249,6 +19255,14 @@ proto.messages.GetMessagesRequest.serializeBinaryToWriter = function(message, wr
|
||||
proto.messages.SortBy.serializeBinaryToWriter
|
||||
);
|
||||
}
|
||||
f = message.getMerge();
|
||||
if (f != null) {
|
||||
writer.writeMessage(
|
||||
5,
|
||||
f,
|
||||
proto.messages.OptionalBool.serializeBinaryToWriter
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19400,6 +19414,43 @@ proto.messages.GetMessagesRequest.prototype.hasSortby = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional OptionalBool merge = 5;
|
||||
* @return {?proto.messages.OptionalBool}
|
||||
*/
|
||||
proto.messages.GetMessagesRequest.prototype.getMerge = function() {
|
||||
return /** @type{?proto.messages.OptionalBool} */ (
|
||||
jspb.Message.getWrapperField(this, proto.messages.OptionalBool, 5));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {?proto.messages.OptionalBool|undefined} value
|
||||
* @return {!proto.messages.GetMessagesRequest} returns this
|
||||
*/
|
||||
proto.messages.GetMessagesRequest.prototype.setMerge = function(value) {
|
||||
return jspb.Message.setWrapperField(this, 5, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Clears the message field making it undefined.
|
||||
* @return {!proto.messages.GetMessagesRequest} returns this
|
||||
*/
|
||||
proto.messages.GetMessagesRequest.prototype.clearMerge = function() {
|
||||
return this.setMerge(undefined);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether this field is set.
|
||||
* @return {boolean}
|
||||
*/
|
||||
proto.messages.GetMessagesRequest.prototype.hasMerge = function() {
|
||||
return jspb.Message.getField(this, 5) != null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20085,7 +20136,8 @@ proto.messages.GetChatsRequest.toObject = function(includeInstance, msg) {
|
||||
session: (f = msg.getSession()) && proto.messages.Session.toObject(includeInstance, f),
|
||||
sortby: (f = msg.getSortby()) && proto.messages.SortBy.toObject(includeInstance, f),
|
||||
pagination: (f = msg.getPagination()) && proto.messages.Pagination.toObject(includeInstance, f),
|
||||
filter: (f = msg.getFilter()) && proto.messages.ChatFilter.toObject(includeInstance, f)
|
||||
filter: (f = msg.getFilter()) && proto.messages.ChatFilter.toObject(includeInstance, f),
|
||||
merge: (f = msg.getMerge()) && proto.messages.OptionalBool.toObject(includeInstance, f)
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
@@ -20142,6 +20194,11 @@ proto.messages.GetChatsRequest.deserializeBinaryFromReader = function(msg, reade
|
||||
reader.readMessage(value,proto.messages.ChatFilter.deserializeBinaryFromReader);
|
||||
msg.setFilter(value);
|
||||
break;
|
||||
case 5:
|
||||
var value = new proto.messages.OptionalBool;
|
||||
reader.readMessage(value,proto.messages.OptionalBool.deserializeBinaryFromReader);
|
||||
msg.setMerge(value);
|
||||
break;
|
||||
default:
|
||||
reader.skipField();
|
||||
break;
|
||||
@@ -20203,6 +20260,14 @@ proto.messages.GetChatsRequest.serializeBinaryToWriter = function(message, write
|
||||
proto.messages.ChatFilter.serializeBinaryToWriter
|
||||
);
|
||||
}
|
||||
f = message.getMerge();
|
||||
if (f != null) {
|
||||
writer.writeMessage(
|
||||
5,
|
||||
f,
|
||||
proto.messages.OptionalBool.serializeBinaryToWriter
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -20354,6 +20419,43 @@ proto.messages.GetChatsRequest.prototype.hasFilter = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional OptionalBool merge = 5;
|
||||
* @return {?proto.messages.OptionalBool}
|
||||
*/
|
||||
proto.messages.GetChatsRequest.prototype.getMerge = function() {
|
||||
return /** @type{?proto.messages.OptionalBool} */ (
|
||||
jspb.Message.getWrapperField(this, proto.messages.OptionalBool, 5));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {?proto.messages.OptionalBool|undefined} value
|
||||
* @return {!proto.messages.GetChatsRequest} returns this
|
||||
*/
|
||||
proto.messages.GetChatsRequest.prototype.setMerge = function(value) {
|
||||
return jspb.Message.setWrapperField(this, 5, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Clears the message field making it undefined.
|
||||
* @return {!proto.messages.GetChatsRequest} returns this
|
||||
*/
|
||||
proto.messages.GetChatsRequest.prototype.clearMerge = function() {
|
||||
return this.setMerge(undefined);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether this field is set.
|
||||
* @return {boolean}
|
||||
*/
|
||||
proto.messages.GetChatsRequest.prototype.hasMerge = function() {
|
||||
return jspb.Message.getField(this, 5) != null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ import {
|
||||
GetChatMessageQuery,
|
||||
GetChatMessagesFilter,
|
||||
GetChatMessagesQuery,
|
||||
GetChatsOverviewParams,
|
||||
GetChatsParams,
|
||||
MessageSortField,
|
||||
OverviewFilter,
|
||||
ReadChatMessagesQuery,
|
||||
@@ -1855,24 +1857,27 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
|
||||
pagination.sortOrder = SortOrder.DESC;
|
||||
}
|
||||
const chats = await this.getChats(pagination, filter);
|
||||
const merge = (pagination as GetChatsOverviewParams).merge ?? true;
|
||||
|
||||
const promises = [];
|
||||
for (const chat of chats) {
|
||||
promises.push(this.fetchChatSummary(chat));
|
||||
promises.push(this.fetchChatSummary(chat, merge));
|
||||
}
|
||||
const result = await Promise.all(promises);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected async fetchChatSummary(chat): Promise<ChatSummary> {
|
||||
protected async fetchChatSummary(chat, merge: boolean): Promise<ChatSummary> {
|
||||
const id = toCusFormat(chat.id);
|
||||
const name = chat.name;
|
||||
const picture = await this.getContactProfilePicture(chat.id, false);
|
||||
const messages = await this.getChatMessages(
|
||||
chat.id,
|
||||
{ limit: 1, offset: 0, downloadMedia: false },
|
||||
{},
|
||||
);
|
||||
const lastMessageQuery: GetChatMessagesQuery = {
|
||||
limit: 1,
|
||||
offset: 0,
|
||||
downloadMedia: false,
|
||||
merge,
|
||||
};
|
||||
const messages = await this.getChatMessages(chat.id, lastMessageQuery, {});
|
||||
const message = messages.length > 0 ? messages[0] : null;
|
||||
return {
|
||||
id: id,
|
||||
@@ -1897,6 +1902,8 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
|
||||
pagination: PaginationParams,
|
||||
filter: OverviewFilter | null = null,
|
||||
) {
|
||||
const merge =
|
||||
(pagination as GetChatsParams | GetChatsOverviewParams).merge ?? true;
|
||||
if (pagination.sortBy === ChatSortField.CONVERSATION_TIMESTAMP) {
|
||||
pagination.sortBy = 'timestamp';
|
||||
}
|
||||
@@ -1920,6 +1927,7 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
|
||||
filter: new messages.ChatFilter({
|
||||
jids: jids,
|
||||
}),
|
||||
merge: optional(merge, messages.OptionalBool),
|
||||
});
|
||||
const response = await promisify(this.client.GetChats)(request);
|
||||
const data = parseJsonList(response);
|
||||
@@ -1932,6 +1940,7 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
|
||||
filter: GetChatMessagesFilter,
|
||||
) {
|
||||
const downloadMedia = query.downloadMedia;
|
||||
const merge = query.merge ?? true;
|
||||
let jid: messages.OptionalString;
|
||||
if (chatId === 'all') {
|
||||
jid = null;
|
||||
@@ -1969,6 +1978,7 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
|
||||
limit: query.limit,
|
||||
offset: query.offset,
|
||||
}),
|
||||
merge: optional(merge, messages.OptionalBool),
|
||||
});
|
||||
const response = await promisify(this.client.GetMessages)(request);
|
||||
const msgs = parseJsonList(response);
|
||||
|
||||
Reference in new issue
Block a user