mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-04 04:41:35 +00:00
Added option clearattachments <String> to gam [<UserTypeMessage>] update chatmessage
This commit is contained in:
@@ -2057,7 +2057,7 @@ gam create chatmessage <ChatSpace>
|
|||||||
[(thread <ChatThread>)|(threadkey <String>) [replyoption fail|fallbacktonew]]
|
[(thread <ChatThread>)|(threadkey <String>) [replyoption fail|fallbacktonew]]
|
||||||
[returnidonly]
|
[returnidonly]
|
||||||
gam update chatmessage name <ChatMessage>
|
gam update chatmessage name <ChatMessage>
|
||||||
<ChatContent>
|
[<ChatContent>] [clearattachments <String>]
|
||||||
gam delete chatmessage name <ChatMessage>
|
gam delete chatmessage name <ChatMessage>
|
||||||
|
|
||||||
<ChatMessageFieldName> ::=
|
<ChatMessageFieldName> ::=
|
||||||
@@ -6586,7 +6586,7 @@ gam <UserTypeEntity> create chatmessage <ChatSpace>
|
|||||||
[replyoption fail|fallback]
|
[replyoption fail|fallback]
|
||||||
[returnidonly]
|
[returnidonly]
|
||||||
gam <UserTypeEntity> update chatmessage name <ChatMessage>
|
gam <UserTypeEntity> update chatmessage name <ChatMessage>
|
||||||
<ChatContent>
|
[<ChatContent>] [clearattachments <String>]
|
||||||
gam <UserTypeEntity> delete chatmessage name <ChatMessage>
|
gam <UserTypeEntity> delete chatmessage name <ChatMessage>
|
||||||
|
|
||||||
<ChatMessageFieldName> ::=
|
<ChatMessageFieldName> ::=
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
7.27.02
|
||||||
|
|
||||||
|
Added option `clearattachments <String>` to `gam [<UserTypeMessage>] update chatmessage`
|
||||||
|
that clears all attachments from a Chat message. If `<ChatContent>` is not specified,
|
||||||
|
the current message text is retained and `<String>` is appended; `<String>` must be specified
|
||||||
|
but can be empty in which case the current message test is preserved as-is.
|
||||||
|
|
||||||
7.27.01
|
7.27.01
|
||||||
|
|
||||||
Fixed bug in `gam <UserTypeEntity> claim ownership <DriveFileEntity> ... onlyUsers|skipusers <UserTypeEntity>`
|
Fixed bug in `gam <UserTypeEntity> claim ownership <DriveFileEntity> ... onlyUsers|skipusers <UserTypeEntity>`
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
|
__author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
|
||||||
__version__ = '7.27.01'
|
__version__ = '7.27.02'
|
||||||
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
|
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
|
||||||
|
|
||||||
#pylint: disable=wrong-import-position
|
#pylint: disable=wrong-import-position
|
||||||
@@ -9182,7 +9182,7 @@ def showJSON(showName, showValue, skipObjects=None, timeObjects=None,
|
|||||||
return
|
return
|
||||||
if objectName is not None:
|
if objectName is not None:
|
||||||
printJSONKey(objectName)
|
printJSONKey(objectName)
|
||||||
subObjectKey = dictObjectsKey.get(objectName)
|
subObjectKey = dictObjectsKey.get(objectName)
|
||||||
if isinstance(objectValue, list):
|
if isinstance(objectValue, list):
|
||||||
if objectName in simpleLists:
|
if objectName in simpleLists:
|
||||||
printJSONValue(' '.join(objectValue))
|
printJSONValue(' '.join(objectValue))
|
||||||
@@ -26506,14 +26506,18 @@ CHAT_TIME_OBJECTS = {'createTime', 'deleteTime', 'eventTime', 'lastActiveTime',
|
|||||||
def _showChatItem(citem, entityType, FJQC, i=0, count=0):
|
def _showChatItem(citem, entityType, FJQC, i=0, count=0):
|
||||||
if entityType == Ent.CHAT_SPACE:
|
if entityType == Ent.CHAT_SPACE:
|
||||||
_cleanChatSpace(citem)
|
_cleanChatSpace(citem)
|
||||||
|
dictObjectsKey = {None: 'displayName'}
|
||||||
elif entityType == Ent.CHAT_MESSAGE:
|
elif entityType == Ent.CHAT_MESSAGE:
|
||||||
_cleanChatMessage(citem)
|
_cleanChatMessage(citem)
|
||||||
|
dictObjectsKey = {None: 'text'}
|
||||||
|
else:
|
||||||
|
dictObjectsKey={}
|
||||||
if FJQC.formatJSON:
|
if FJQC.formatJSON:
|
||||||
printLine(json.dumps(cleanJSON(citem, timeObjects=CHAT_TIME_OBJECTS), ensure_ascii=False, sort_keys=True))
|
printLine(json.dumps(cleanJSON(citem, timeObjects=CHAT_TIME_OBJECTS), ensure_ascii=False, sort_keys=True))
|
||||||
return
|
return
|
||||||
printEntity([entityType, citem['name']], i, count)
|
printEntity([entityType, citem['name']], i, count)
|
||||||
Ind.Increment()
|
Ind.Increment()
|
||||||
showJSON(None, citem, timeObjects=CHAT_TIME_OBJECTS)
|
showJSON(None, citem, timeObjects=CHAT_TIME_OBJECTS, dictObjectsKey=dictObjectsKey)
|
||||||
Ind.Decrement()
|
Ind.Decrement()
|
||||||
|
|
||||||
def _printChatItem(user, citem, parent, entityType, csvPF, FJQC, addCSVData=None):
|
def _printChatItem(user, citem, parent, entityType, csvPF, FJQC, addCSVData=None):
|
||||||
@@ -27986,10 +27990,11 @@ def _getChatSenderEmail(cd, sender):
|
|||||||
sender['email'], _ = convertUIDtoEmailAddressWithType(f'uid:{senderUid}', cd, None, emailTypes=['user'])
|
sender['email'], _ = convertUIDtoEmailAddressWithType(f'uid:{senderUid}', cd, None, emailTypes=['user'])
|
||||||
|
|
||||||
def trimChatMessageIfRequired(body):
|
def trimChatMessageIfRequired(body):
|
||||||
msgLen = len(body['text'])
|
if 'text' in body:
|
||||||
if msgLen > 4096:
|
msgLen = len(body['text'])
|
||||||
stderrWarningMsg(Msg.TRIMMED_MESSAGE_FROM_LENGTH_TO_MAXIMUM.format(msgLen, 4096))
|
if msgLen > 4096:
|
||||||
body['text'] = body['text'][:4095]
|
stderrWarningMsg(Msg.TRIMMED_MESSAGE_FROM_LENGTH_TO_MAXIMUM.format(msgLen, 4096))
|
||||||
|
body['text'] = body['text'][:4095]
|
||||||
|
|
||||||
CHAT_MESSAGE_REPLY_OPTION_MAP = {
|
CHAT_MESSAGE_REPLY_OPTION_MAP = {
|
||||||
'fail': 'REPLY_MESSAGE_OR_FAIL',
|
'fail': 'REPLY_MESSAGE_OR_FAIL',
|
||||||
@@ -28066,22 +28071,29 @@ def doCreateChatMessage():
|
|||||||
createChatMessage([None])
|
createChatMessage([None])
|
||||||
|
|
||||||
# gam [<UserTypeMessage>] update chatmessage name <ChatMessage>
|
# gam [<UserTypeMessage>] update chatmessage name <ChatMessage>
|
||||||
# <ChatContent>
|
# [<ChatContent>] [clearattachments <String>]
|
||||||
def updateChatMessage(users):
|
def updateChatMessage(users):
|
||||||
name = None
|
name = None
|
||||||
body = {}
|
body = {}
|
||||||
|
updateMask = []
|
||||||
|
clearMsg = ''
|
||||||
while Cmd.ArgumentsRemaining():
|
while Cmd.ArgumentsRemaining():
|
||||||
myarg = getArgument()
|
myarg = getArgument()
|
||||||
if myarg == 'name':
|
if myarg == 'name':
|
||||||
name = getString(Cmd.OB_CHAT_MESSAGE)
|
name = getString(Cmd.OB_CHAT_MESSAGE)
|
||||||
elif myarg in SORF_TEXT_ARGUMENTS:
|
elif myarg in SORF_TEXT_ARGUMENTS:
|
||||||
body['text'] = getStringOrFile(myarg, minLen=0, unescapeCRLF=True)[0]
|
body['text'] = getStringOrFile(myarg, minLen=0, unescapeCRLF=True)[0]
|
||||||
|
updateMask.append('text')
|
||||||
|
elif myarg == 'clearattachments':
|
||||||
|
clearMsg = getString(Cmd.OB_STRING, minLen=0)
|
||||||
|
body['attachment'] = []
|
||||||
|
updateMask.append('attachment')
|
||||||
else:
|
else:
|
||||||
unknownArgumentExit()
|
unknownArgumentExit()
|
||||||
if not name:
|
if not name:
|
||||||
missingArgumentExit('name')
|
missingArgumentExit('name')
|
||||||
if 'text' not in body:
|
if not updateMask:
|
||||||
missingArgumentExit('text or textfile')
|
missingArgumentExit('text|textfile|clearattachments')
|
||||||
trimChatMessageIfRequired(body)
|
trimChatMessageIfRequired(body)
|
||||||
i, count, users = getEntityArgument(users)
|
i, count, users = getEntityArgument(users)
|
||||||
for user in users:
|
for user in users:
|
||||||
@@ -28090,9 +28102,19 @@ def updateChatMessage(users):
|
|||||||
if not chat:
|
if not chat:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
|
if 'attachment' in updateMask and 'text' not in updateMask:
|
||||||
|
resp = callGAPI(chat.spaces().messages(), 'get',
|
||||||
|
throwReasons=[GAPI.NOT_FOUND, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED, GAPI.FAILED_PRECONDITION],
|
||||||
|
name=name, fields='text')
|
||||||
|
body['text'] = resp.get('text', '')
|
||||||
|
if clearMsg:
|
||||||
|
body['text'] += clearMsg
|
||||||
|
elif not body['text']:
|
||||||
|
body['text'] = 'Attachments cleared'
|
||||||
|
updateMask.append('text')
|
||||||
resp = callGAPI(chat.spaces().messages(), 'patch',
|
resp = callGAPI(chat.spaces().messages(), 'patch',
|
||||||
throwReasons=[GAPI.NOT_FOUND, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED, GAPI.FAILED_PRECONDITION],
|
throwReasons=[GAPI.NOT_FOUND, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED, GAPI.FAILED_PRECONDITION],
|
||||||
name=name, updateMask='text', body=body)
|
name=name, updateMask=','.join(updateMask), body=body)
|
||||||
kvList.extend([Ent.CHAT_THREAD, resp['thread']['name']])
|
kvList.extend([Ent.CHAT_THREAD, resp['thread']['name']])
|
||||||
entityActionPerformed(kvList, i, count)
|
entityActionPerformed(kvList, i, count)
|
||||||
except (GAPI.notFound, GAPI.invalidArgument, GAPI.permissionDenied) as e:
|
except (GAPI.notFound, GAPI.invalidArgument, GAPI.permissionDenied) as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user