diff --git a/src/core/engines/gows/grpc/gows.ts b/src/core/engines/gows/grpc/gows.ts index 06b06927..aeaa5d0a 100644 --- a/src/core/engines/gows/grpc/gows.ts +++ b/src/core/engines/gows/grpc/gows.ts @@ -5656,6 +5656,122 @@ export namespace messages { return CheckPhonesRequest.deserialize(bytes); } } + export class ChatUnreadRequest extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + session?: Session; + jid?: string; + read?: boolean; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("session" in data && data.session != undefined) { + this.session = data.session; + } + if ("jid" in data && data.jid != undefined) { + this.jid = data.jid; + } + if ("read" in data && data.read != undefined) { + this.read = data.read; + } + } + } + get session() { + return pb_1.Message.getWrapperField(this, Session, 1) as Session; + } + set session(value: Session) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_session() { + return pb_1.Message.getField(this, 1) != null; + } + get jid() { + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; + } + set jid(value: string) { + pb_1.Message.setField(this, 2, value); + } + get read() { + return pb_1.Message.getFieldWithDefault(this, 3, false) as boolean; + } + set read(value: boolean) { + pb_1.Message.setField(this, 3, value); + } + static fromObject(data: { + session?: ReturnType; + jid?: string; + read?: boolean; + }): ChatUnreadRequest { + const message = new ChatUnreadRequest({}); + if (data.session != null) { + message.session = Session.fromObject(data.session); + } + if (data.jid != null) { + message.jid = data.jid; + } + if (data.read != null) { + message.read = data.read; + } + return message; + } + toObject() { + const data: { + session?: ReturnType; + jid?: string; + read?: boolean; + } = {}; + if (this.session != null) { + data.session = this.session.toObject(); + } + if (this.jid != null) { + data.jid = this.jid; + } + if (this.read != null) { + data.read = this.read; + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_session) + writer.writeMessage(1, this.session, () => this.session.serialize(writer)); + if (this.jid.length) + writer.writeString(2, this.jid); + if (this.read != false) + writer.writeBool(3, this.read); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ChatUnreadRequest { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ChatUnreadRequest(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.session, () => message.session = Session.deserialize(reader)); + break; + case 2: + message.jid = reader.readString(); + break; + case 3: + message.read = reader.readBool(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): ChatUnreadRequest { + return ChatUnreadRequest.deserialize(bytes); + } + } export class PhoneInfo extends pb_1.Message { #one_of_decls: number[][] = []; constructor(data?: any[] | { @@ -10424,6 +10540,15 @@ export namespace messages { responseSerialize: (message: CheckPhonesResponse) => Buffer.from(message.serialize()), responseDeserialize: (bytes: Buffer) => CheckPhonesResponse.deserialize(new Uint8Array(bytes)) }, + MarkChatUnread: { + path: "/messages.MessageService/MarkChatUnread", + requestStream: false, + responseStream: false, + requestSerialize: (message: ChatUnreadRequest) => Buffer.from(message.serialize()), + requestDeserialize: (bytes: Buffer) => ChatUnreadRequest.deserialize(new Uint8Array(bytes)), + responseSerialize: (message: Empty) => Buffer.from(message.serialize()), + responseDeserialize: (bytes: Buffer) => Empty.deserialize(new Uint8Array(bytes)) + }, GenerateNewMessageID: { path: "/messages.MessageService/GenerateNewMessageID", requestStream: false, @@ -10728,6 +10853,7 @@ export namespace messages { abstract SendChatPresence(call: grpc_1.ServerUnaryCall, callback: grpc_1.sendUnaryData): void; abstract SubscribePresence(call: grpc_1.ServerUnaryCall, callback: grpc_1.sendUnaryData): void; abstract CheckPhones(call: grpc_1.ServerUnaryCall, callback: grpc_1.sendUnaryData): void; + abstract MarkChatUnread(call: grpc_1.ServerUnaryCall, callback: grpc_1.sendUnaryData): void; abstract GenerateNewMessageID(call: grpc_1.ServerUnaryCall, callback: grpc_1.sendUnaryData): void; abstract SendMessage(call: grpc_1.ServerUnaryCall, callback: grpc_1.sendUnaryData): void; abstract SendReaction(call: grpc_1.ServerUnaryCall, callback: grpc_1.sendUnaryData): void; @@ -10859,6 +10985,9 @@ export namespace messages { CheckPhones: GrpcUnaryServiceInterface = (message: CheckPhonesRequest, metadata: grpc_1.Metadata | grpc_1.CallOptions | grpc_1.requestCallback, options?: grpc_1.CallOptions | grpc_1.requestCallback, callback?: grpc_1.requestCallback): grpc_1.ClientUnaryCall => { return super.CheckPhones(message, metadata, options, callback); }; + MarkChatUnread: GrpcUnaryServiceInterface = (message: ChatUnreadRequest, metadata: grpc_1.Metadata | grpc_1.CallOptions | grpc_1.requestCallback, options?: grpc_1.CallOptions | grpc_1.requestCallback, callback?: grpc_1.requestCallback): grpc_1.ClientUnaryCall => { + return super.MarkChatUnread(message, metadata, options, callback); + }; GenerateNewMessageID: GrpcUnaryServiceInterface = (message: Session, metadata: grpc_1.Metadata | grpc_1.CallOptions | grpc_1.requestCallback, options?: grpc_1.CallOptions | grpc_1.requestCallback, callback?: grpc_1.requestCallback): grpc_1.ClientUnaryCall => { return super.GenerateNewMessageID(message, metadata, options, callback); }; diff --git a/src/core/engines/gows/grpc/gows_grpc_pb.js b/src/core/engines/gows/grpc/gows_grpc_pb.js index c2df03ba..d91448f6 100644 --- a/src/core/engines/gows/grpc/gows_grpc_pb.js +++ b/src/core/engines/gows/grpc/gows_grpc_pb.js @@ -48,6 +48,17 @@ function deserialize_messages_ChatPresenceRequest(buffer_arg) { return gows_pb.ChatPresenceRequest.deserializeBinary(new Uint8Array(buffer_arg)); } +function serialize_messages_ChatUnreadRequest(arg) { + if (!(arg instanceof gows_pb.ChatUnreadRequest)) { + throw new Error('Expected argument of type messages.ChatUnreadRequest'); + } + return Buffer.from(arg.serializeBinary()); +} + +function deserialize_messages_ChatUnreadRequest(buffer_arg) { + return gows_pb.ChatUnreadRequest.deserializeBinary(new Uint8Array(buffer_arg)); +} + function serialize_messages_CheckPhonesRequest(arg) { if (!(arg instanceof gows_pb.CheckPhonesRequest)) { throw new Error('Expected argument of type messages.CheckPhonesRequest'); @@ -1053,6 +1064,17 @@ getProfilePicture: { responseSerialize: serialize_messages_CheckPhonesResponse, responseDeserialize: deserialize_messages_CheckPhonesResponse, }, + markChatUnread: { + path: '/messages.MessageService/MarkChatUnread', + requestStream: false, + responseStream: false, + requestType: gows_pb.ChatUnreadRequest, + responseType: gows_pb.Empty, + requestSerialize: serialize_messages_ChatUnreadRequest, + requestDeserialize: deserialize_messages_ChatUnreadRequest, + responseSerialize: serialize_messages_Empty, + responseDeserialize: deserialize_messages_Empty, + }, // // Message // diff --git a/src/core/engines/gows/grpc/gows_pb.js b/src/core/engines/gows/grpc/gows_pb.js index dd3d5332..1c89f7e3 100644 --- a/src/core/engines/gows/grpc/gows_pb.js +++ b/src/core/engines/gows/grpc/gows_pb.js @@ -28,6 +28,7 @@ goog.exportSymbol('proto.messages.ChatFilter', null, global); goog.exportSymbol('proto.messages.ChatLabelRequest', null, global); goog.exportSymbol('proto.messages.ChatPresence', null, global); goog.exportSymbol('proto.messages.ChatPresenceRequest', null, global); +goog.exportSymbol('proto.messages.ChatUnreadRequest', null, global); goog.exportSymbol('proto.messages.CheckPhonesRequest', null, global); goog.exportSymbol('proto.messages.CheckPhonesResponse', null, global); goog.exportSymbol('proto.messages.CreateGroupRequest', null, global); @@ -1167,6 +1168,27 @@ if (goog.DEBUG && !COMPILED) { */ proto.messages.CheckPhonesRequest.displayName = 'proto.messages.CheckPhonesRequest'; } +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.messages.ChatUnreadRequest = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.messages.ChatUnreadRequest, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.messages.ChatUnreadRequest.displayName = 'proto.messages.ChatUnreadRequest'; +} /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a @@ -12414,6 +12436,217 @@ proto.messages.CheckPhonesRequest.prototype.clearPhonesList = function() { +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.messages.ChatUnreadRequest.prototype.toObject = function(opt_includeInstance) { + return proto.messages.ChatUnreadRequest.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.messages.ChatUnreadRequest} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.messages.ChatUnreadRequest.toObject = function(includeInstance, msg) { + var f, obj = { + session: (f = msg.getSession()) && proto.messages.Session.toObject(includeInstance, f), + jid: jspb.Message.getFieldWithDefault(msg, 2, ""), + read: jspb.Message.getBooleanFieldWithDefault(msg, 3, false) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.messages.ChatUnreadRequest} + */ +proto.messages.ChatUnreadRequest.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.messages.ChatUnreadRequest; + return proto.messages.ChatUnreadRequest.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.messages.ChatUnreadRequest} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.messages.ChatUnreadRequest} + */ +proto.messages.ChatUnreadRequest.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = new proto.messages.Session; + reader.readMessage(value,proto.messages.Session.deserializeBinaryFromReader); + msg.setSession(value); + break; + case 2: + var value = /** @type {string} */ (reader.readString()); + msg.setJid(value); + break; + case 3: + var value = /** @type {boolean} */ (reader.readBool()); + msg.setRead(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.messages.ChatUnreadRequest.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.messages.ChatUnreadRequest.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.messages.ChatUnreadRequest} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.messages.ChatUnreadRequest.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getSession(); + if (f != null) { + writer.writeMessage( + 1, + f, + proto.messages.Session.serializeBinaryToWriter + ); + } + f = message.getJid(); + if (f.length > 0) { + writer.writeString( + 2, + f + ); + } + f = message.getRead(); + if (f) { + writer.writeBool( + 3, + f + ); + } +}; + + +/** + * optional Session session = 1; + * @return {?proto.messages.Session} + */ +proto.messages.ChatUnreadRequest.prototype.getSession = function() { + return /** @type{?proto.messages.Session} */ ( + jspb.Message.getWrapperField(this, proto.messages.Session, 1)); +}; + + +/** + * @param {?proto.messages.Session|undefined} value + * @return {!proto.messages.ChatUnreadRequest} returns this +*/ +proto.messages.ChatUnreadRequest.prototype.setSession = function(value) { + return jspb.Message.setWrapperField(this, 1, value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.messages.ChatUnreadRequest} returns this + */ +proto.messages.ChatUnreadRequest.prototype.clearSession = function() { + return this.setSession(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.messages.ChatUnreadRequest.prototype.hasSession = function() { + return jspb.Message.getField(this, 1) != null; +}; + + +/** + * optional string jid = 2; + * @return {string} + */ +proto.messages.ChatUnreadRequest.prototype.getJid = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); +}; + + +/** + * @param {string} value + * @return {!proto.messages.ChatUnreadRequest} returns this + */ +proto.messages.ChatUnreadRequest.prototype.setJid = function(value) { + return jspb.Message.setProto3StringField(this, 2, value); +}; + + +/** + * optional bool read = 3; + * @return {boolean} + */ +proto.messages.ChatUnreadRequest.prototype.getRead = function() { + return /** @type {boolean} */ (jspb.Message.getBooleanFieldWithDefault(this, 3, false)); +}; + + +/** + * @param {boolean} value + * @return {!proto.messages.ChatUnreadRequest} returns this + */ +proto.messages.ChatUnreadRequest.prototype.setRead = function(value) { + return jspb.Message.setProto3BooleanField(this, 3, value); +}; + + + + + if (jspb.Message.GENERATE_TO_OBJECT) { /** * Creates an object representation of this proto. diff --git a/src/core/engines/gows/session.gows.core.ts b/src/core/engines/gows/session.gows.core.ts index 3fbe7aac..f4a873d2 100644 --- a/src/core/engines/gows/session.gows.core.ts +++ b/src/core/engines/gows/session.gows.core.ts @@ -1859,6 +1859,17 @@ export class WhatsappSessionGoWSCore extends WhatsappSession { return labels.map(this.toLabel); } + public async chatsUnreadChat(chatId: string): Promise { + const jid = toJID(this.ensureSuffix(chatId)); + const request = new messages.ChatUnreadRequest({ + session: this.session, + jid: jid, + read: false, + }); + await promisify(this.client.MarkChatUnread)(request); + return { success: true }; + } + public async putLabelsToChat(chatId: string, labels: LabelID[]) { const jid = toJID(chatId); const labelsIds = labels.map((label) => label.id);